/**
     * @param keyBytes
     * @param value
     * @param hash2
     * @return
     */
    V acquireEntry(DirectBytes keyBytes, V value, int hash2) {
      value = createValueIfNull(value);

      final int pos = nextFree();
      final long offset = entriesOffset + pos * entrySize;
      tmpBytes.storePositionAndSize(bytes, offset, entrySize);
      final long keyLength = keyBytes.remaining();
      tmpBytes.writeStopBit(keyLength);
      tmpBytes.write(keyBytes);
      if (value instanceof Byteable) {
        Byteable byteable = (Byteable) value;
        int length = byteable.maxSize();
        tmpBytes.writeStopBit(length);
        tmpBytes.position(align(tmpBytes.position()));
        if (length > tmpBytes.remaining())
          throw new IllegalStateException(
              "Not enough space left in entry for value, needs "
                  + length
                  + " but only "
                  + tmpBytes.remaining()
                  + " left");
        tmpBytes.zeroOut(tmpBytes.position(), tmpBytes.position() + length);
        byteable.bytes(bytes, offset + tmpBytes.position());
      } else {
        appendInstance(keyBytes, value);
      }
      // add to index if successful.
      hashLookup.put(hash2, pos);
      incrementSize();
      return value;
    }
 void appendValue(final Bytes value) {
   if (value.remaining() + 4 > tmpBytes.remaining())
     throw new IllegalArgumentException(
         "Value too large for entry was "
             + (value.remaining() + 4)
             + ", remaining: "
             + tmpBytes.remaining());
   tmpBytes.writeStopBit(value.remaining());
   tmpBytes.position(align(tmpBytes.position()));
   tmpBytes.write(value);
 }
 private void putEntry(DirectBytes keyBytes, V value, int hash2) {
   int pos = nextFree();
   long offset = entriesOffset + pos * builder.entrySize();
   tmpBytes.storePositionAndSize(bytes, offset, builder.entrySize());
   long keyLength = keyBytes.remaining();
   tmpBytes.writeStopBit(keyLength);
   tmpBytes.write(keyBytes);
   tmpBytes.position(align(tmpBytes.position()));
   appendInstance(keyBytes, value);
   // add to index if successful.
   hashLookup.put(hash2, pos);
 }
 private V acquireEntry(DirectBytes keyBytes, V value, int hash2) {
   int pos = nextFree();
   long offset = entriesOffset + pos * builder.entrySize();
   tmpBytes.storePositionAndSize(bytes, offset, builder.entrySize());
   long keyLength = keyBytes.remaining();
   tmpBytes.writeStopBit(keyLength);
   tmpBytes.write(keyBytes);
   tmpBytes.position(align(tmpBytes.position()));
   tmpBytes.zeroOut(tmpBytes.position(), tmpBytes.limit());
   V v = readObjectUsing(value, offset + tmpBytes.position());
   // add to index if successful.
   hashLookup.put(hash2, pos);
   return v;
 }
 private void writeKey(Bytes keyBytes, long offset) {
   tmpBytes.storePositionAndSize(bytes, offset, entrySize);
   long keyLength = keyBytes.remaining();
   tmpBytes.writeStopBit(keyLength);
   tmpBytes.write(keyBytes);
 }