Пример #1
0
  /**
   * Creates new HashSet
   *
   * @param name of set to create
   * @param keepCounter if counter should be kept, without counter updates are faster, but entire
   *     collection needs to be traversed to count items.
   * @param serializer used to convert keys into/from binary form. Use null for default value.
   * @param <K> item type
   * @throws IllegalArgumentException if name is already used
   */
  public synchronized <K> Set<K> createHashSet(
      String name, boolean keepCounter, Serializer<K> serializer) {
    checkNameNotExists(name);

    Set<K> ret =
        new HTreeMap<K, Object>(
                engine,
                catPut(name + ".counterRecid", !keepCounter ? 0L : engine.put(0L, Serializer.LONG)),
                catPut(name + ".hashSalt", Utils.RANDOM.nextInt()),
                catPut(name + ".segmentRecids", HTreeMap.preallocateSegments(engine)),
                catPut(name + ".serializer", serializer, getDefaultSerializer()),
                null,
                0L,
                0L,
                0L,
                0L,
                null,
                null,
                null)
            .keySet();

    catalog.put(name + ".type", "HashSet");
    collections.put(name, new WeakReference<Object>(ret));
    return ret;
  }
Пример #2
0
  /**
   * Creates new HashMap with more specific arguments
   *
   * @param <K> key type
   * @param <V> value type
   * @throws IllegalArgumentException if name is already used
   * @return newly created map
   */
  protected synchronized <K, V> HTreeMap<K, V> createHashMap(HTreeMapMaker m) {
    String name = m.name;
    checkNameNotExists(name);

    long expireTimeStart = 0, expire = 0, expireAccess = 0, expireMaxSize = 0;
    long[] expireHeads = null, expireTails = null;

    if (m.expire != 0 || m.expireAccess != 0 || m.expireMaxSize != 0) {
      expireTimeStart = catPut(name + ".expireTimeStart", System.currentTimeMillis());
      expire = catPut(name + ".expire", m.expire);
      expireAccess = catPut(name + ".expireAccess", m.expireAccess);
      expireMaxSize = catPut(name + ".expireMaxSize", m.expireMaxSize);
      expireHeads = new long[16];
      expireTails = new long[16];
      for (int i = 0; i < 16; i++) {
        expireHeads[i] = engine.put(0L, Serializer.LONG);
        expireTails[i] = engine.put(0L, Serializer.LONG);
      }
      catPut(name + ".expireHeads", expireHeads);
      catPut(name + ".expireTails", expireHeads);
    }

    HTreeMap<K, V> ret =
        new HTreeMap<K, V>(
            engine,
            catPut(name + ".counterRecid", !m.keepCounter ? 0L : engine.put(0L, Serializer.LONG)),
            catPut(name + ".hashSalt", Utils.RANDOM.nextInt()),
            catPut(name + ".segmentRecids", HTreeMap.preallocateSegments(engine)),
            catPut(name + ".keySerializer", m.keySerializer, getDefaultSerializer()),
            catPut(name + ".valueSerializer", m.valueSerializer, getDefaultSerializer()),
            expireTimeStart,
            expire,
            expireAccess,
            expireMaxSize,
            expireHeads,
            expireTails,
            m.valueCreator);

    catalog.put(name + ".type", "HashMap");
    collections.put(name, new WeakReference<Object>(ret));
    return ret;
  }