public VanillaSharedHashMap(
      SharedHashMapBuilder builder, File file, Class<K> kClass, Class<V> vClass)
      throws IOException {
    this.kClass = kClass;
    this.vClass = vClass;

    lockTimeOutNS = builder.lockTimeOutMS() * 1000000;

    this.replicas = builder.replicas();
    this.entrySize = builder.entrySize();

    this.errorListener = builder.errorListener();
    this.generatedKeyType = builder.generatedKeyType();
    this.generatedValueType = builder.generatedValueType();
    this.putReturnsNull = builder.putReturnsNull();
    this.removeReturnsNull = builder.removeReturnsNull();

    int segments = builder.actualSegments();
    this.segmentBits = Maths.intLog2(segments);
    int entriesPerSegment = builder.actualEntriesPerSegment();
    this.entriesPerSegment = entriesPerSegment;

    @SuppressWarnings("unchecked")
    Segment[] ss = (VanillaSharedHashMap.Segment[]) new VanillaSharedHashMap.Segment[segments];
    this.segments = ss;

    this.ms = new MappedStore(file, FileChannel.MapMode.READ_WRITE, sizeInBytes());

    long offset = SharedHashMapBuilder.HEADER_SIZE;
    long segmentSize = segmentSize();
    for (int i = 0; i < this.segments.length; i++) {
      this.segments[i] = new Segment(ms.createSlice(offset, segmentSize));
      offset += segmentSize;
    }
  }
 private DirectBytes getKeyAsBytes(K key) {
   DirectBytes bytes = acquireBytes();
   if (builder.generatedKeyType()) ((BytesMarshallable) key).writeMarshallable(bytes);
   else bytes.writeInstance(kClass, key);
   bytes.flip();
   return bytes;
 }