### Question:
CharSequenceMap implements SequenceMap<CharSequence> { public void put(final CharSequence value, final long id) { if (value.length() > maxKeyLength) { throw new IllegalArgumentException("Key too long"); } if (liveEntryCount > entryCountToTriggerRehash) { rehash(true); } final int hashValue = hash.applyAsInt(value); final int entryIndex = (hashValue & entryMask); final boolean existingEntryAt = isExistingEntryAt(value, entryIndex, hashValue); if (isEmptyEntrySlot(entryIndex) || existingEntryAt) { insertEntry(value, id, entryIndex, !existingEntryAt, hashValue); } else { for (int i = 1; i < totalEntryCount; i++) { int candidateIndex = (entryIndex + (i)); if (candidateIndex >= totalEntryCount) { candidateIndex -= totalEntryCount; } final boolean innerExistingEntryAt = isExistingEntryAt(value, candidateIndex, hashValue); if (isEmptyEntrySlot(candidateIndex) || innerExistingEntryAt) { insertEntry(value, id, candidateIndex, !innerExistingEntryAt, hashValue); return; } } put(value, id); } } CharSequenceMap(final int maxKeyLength, final int initialSize, final long missingValue);  CharSequenceMap(
        final int maxKeyLength, final int initialSize,
        final long missingValue, final IntFunction<ByteBuffer> bufferFactory);   CharSequenceMap(
        final int maxKeyLength, final int initialSize,
        final ToIntFunction<CharSequence> hash, final long missingValue,
        final IntFunction<ByteBuffer> bufferFactory); void put(final CharSequence value, final long id); long get(final CharSequence value); long remove(final CharSequence value); int size(); void rehash();  }### Answer:
@Test void shouldRejectKeyThatIsTooLong() { final StringBuilder key = new StringBuilder(); for (int i = 0; i <= MAX_KEY_LENGTH; i++) { key.append('x'); } Assertions.assertThrows(IllegalArgumentException.class, () -> map.put(key, 7L)); }
@Test void shouldStoreSingleValue() { map.put(SEARCH_TERM, ID); assertSearchResult(map, SEARCH_TERM, ID); }
@Test void shouldRetrieveMultipleValuesWhenHashesCollide() { final CharSequenceMap poorIndex = new CharSequenceMap(16, 10, cs -> 7, Long.MIN_VALUE, ByteBuffer::allocateDirect); final String otherTerm = "otherTerm"; final long otherId = 99L; poorIndex.put(SEARCH_TERM, ID); poorIndex.put(otherTerm, otherId); assertSearchResult(poorIndex, SEARCH_TERM, ID); assertSearchResult(poorIndex, otherTerm, otherId); }
@Test void shouldReplaceExistingValue() { final long otherId = 42L; map.put(SEARCH_TERM, ID); map.put(SEARCH_TERM, otherId); assertSearchResult(map, SEARCH_TERM, otherId); }
@Disabled("Requires more RAM than that provided by Travis container") @Test void shouldUseFullBufferCapactity() { final int perRecordOverhead = 4 * Integer.BYTES; final int maxKeyLength = 128; final int recordLength = perRecordOverhead + maxKeyLength; long maxBufferSize = recordLength * 8; while ((maxBufferSize * 2) < (long)Integer.MAX_VALUE) { maxBufferSize = maxBufferSize << 1; } maxBufferSize /= 2; final int maxRecordableValues = (int)((((int)maxBufferSize) / (perRecordOverhead + maxKeyLength) - 1) * 0.7f); final CharSequenceMap largeMap = new CharSequenceMap( maxKeyLength, maxRecordableValues / 4, Long.MIN_VALUE); for (int i = 0; i < maxRecordableValues; i++) { largeMap.put(Integer.toString(i), i); } Assertions.assertThrows(IllegalStateException.class, () -> { for (int i = 0; i < 5; i++) { largeMap.put(Integer.toString(i + maxRecordableValues), i); } }); }