コード例 #1
0
 private V put0(K key, V value, boolean replaceIfPresent) {
   if (!kClass.isInstance(key)) return null;
   DirectBytes bytes = getKeyAsBytes(key);
   long hash = longHashCode(bytes);
   int segmentNum = (int) (hash & (builder.segments() - 1));
   int hash2 = (int) (hash / builder.segments());
   //        System.out.println("[" + key + "] s: " + segmentNum + " h2: " + hash2);
   return segments[segmentNum].put(bytes, value, hash2, replaceIfPresent);
 }
コード例 #2
0
 private V removeUsing(Object key, V value) {
   if (!kClass.isInstance(key)) return null;
   DirectBytes bytes = getKeyAsBytes((K) key);
   long hash = longHashCode(bytes);
   int segmentNum = (int) (hash & (builder.segments() - 1));
   int hash2 = (int) (hash / builder.segments());
   //        System.out.println("[" + key + "] s: " + segmentNum + " h2: " + hash2);
   return segments[segmentNum].remove(bytes, value, hash2);
 }
コード例 #3
0
  public VanillaSharedHashMap(
      SharedHashMapBuilder builder, MappedStore ms, Class<K> kClass, Class<V> vClass) {
    this.builder = builder;
    lockTimeOutNS = builder.lockTimeOutMS() * 1000000;
    this.ms = ms;
    this.kClass = kClass;
    this.vClass = vClass;

    @SuppressWarnings("unchecked")
    Segment[] segments =
        (VanillaSharedHashMap<K, V>.Segment[]) new VanillaSharedHashMap.Segment[builder.segments()];
    this.segments = segments;

    long offset = SharedHashMapBuilder.HEADER_SIZE;
    long segmentSize = builder.segmentSize();
    for (int i = 0; i < this.segments.length; i++) {
      this.segments[i] = new Segment(ms.createSlice(offset, segmentSize));
      offset += segmentSize;
    }
  }