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);
 }
    void directPut(final Bytes key, final Bytes value, int hash2) {
      lock();
      try {
        hash2 = hashLookup.startSearch(hash2);
        while (true) {
          final int pos = hashLookup.nextPos();
          if (pos < 0) {
            directPutEntry(key, value, hash2);

            return;

          } else {
            final long offset = entriesOffset + pos * entrySize;
            tmpBytes.storePositionAndSize(bytes, offset, entrySize);
            if (!keyEquals(key, tmpBytes)) continue;
            final long keyLength = key.remaining();
            tmpBytes.skip(keyLength);
            appendValue(value);
            return;
          }
        }
      } finally {
        unlock();
      }
    }
    void directRemove(final Bytes keyBytes, int hash2) {
      lock();
      try {
        hash2 = hashLookup.startSearch(hash2);
        while (true) {

          final int pos = hashLookup.nextPos();
          if (pos < 0) {
            return;

          } else {
            final long offset = entriesOffset + pos * entrySize;
            tmpBytes.storePositionAndSize(bytes, offset, entrySize);
            if (!keyEquals(keyBytes, tmpBytes)) continue;
            final long keyLength =
                align(keyBytes.remaining() + tmpBytes.position()); // includes the stop bit length.
            tmpBytes.position(keyLength);

            hashLookup.remove(hash2, pos);
            decrementSize();

            freeList.clear(pos);
            if (pos < nextSet) nextSet = pos;

            return;
          }
        }
      } finally {
        unlock();
      }
    }
 boolean keyEquals(Bytes keyBytes, MultiStoreBytes tmpBytes) {
   // check the length is the same.
   long keyLength = tmpBytes.readStopBit();
   return keyLength == keyBytes.remaining() && tmpBytes.startsWith(keyBytes);
 }
 private void writeKey(Bytes keyBytes, long offset) {
   tmpBytes.storePositionAndSize(bytes, offset, entrySize);
   long keyLength = keyBytes.remaining();
   tmpBytes.writeStopBit(keyLength);
   tmpBytes.write(keyBytes);
 }