Пример #1
0
 @Override
 public Class<? extends FSTStruct> getElementType(Field arrayRef, FSTStructFactory fac) {
   if (keyTemplate != null && "keys".equals(arrayRef.getName())) {
     return keyTemplate.getClass();
   }
   if (valueTemplate != null && "vals".equals(arrayRef.getName())) {
     return valueTemplate.getClass();
   }
   return null;
 }
Пример #2
0
  protected int locateIndex(Object key) {
    if (size >= getCapacity() - 1) {
      throw new RuntimeException("Map is full");
    }
    if (pointer != null /*?? special for instantiation ?*/ || isOffHeap()) {
      long arrbase = ___offset + keysStructIndex();
      int kvlen = ___bytes.getInt(arrbase + 4);
      int kelemsiz = ___bytes.getInt(arrbase + 8);
      if (pointer == null) {
        pointer = ___fac.createStructPointer(___bytes, 0, ___bytes.getInt(arrbase + 12));
      }

      int pos = ((key.hashCode() & 0x7FFFFFFF) % kvlen);
      pointer.___offset = ___offset + ___bytes.getInt(arrbase) + pos * kelemsiz;
      while (pointer.getInt() > 0) {
        if (key.equals(pointer)) break;
        pos++;
        pointer.next(kelemsiz);
        if (pos >= kvlen) {
          pos = 0;
          pointer.___offset = ___offset + ___bytes.getInt(arrbase);
        }
      }
      return pos;
    } else {
      int kvlen = keysLen();
      int pos = ((key.hashCode() & 0x7FFFFFFF) % kvlen);
      Object o = keys(pos);
      while (o != null) {
        if (key.equals(o)) break;
        pos++;
        if (pos >= kvlen) pos = 0;
        o = keys(pos);
      }
      return pos;
    }
  }