Repository navigation
Conversation
ConstMap, VerifiedConstMap and PairedVerifiedConstMap are immutable maps from string or byte-array keys to 64-bit values built with the binary fuse construction, ported from github.com/lemire/constmap (Go). They share the key hash (XXH64), mixing, seed sequence, layout and file formats with constmap, rsconstmap (Rust) and fastconstmap (C/Python): - for the same input they write the same bytes as Go and Rust (CMAP0001, VMAP0001, PMAP0001), checked against the interop files of the constmap repository and against the Go package for sizes from 0 to 1,234,567 keys (tools/constmap_vectors); - they read fastconstmap's CMAP0003 and ignore its key counts, and name the legacy fastconstmap 0.9 formats (XXH3) instead of misreading them; - load validates magic, segment parameters and the FNV-1a checksum. Also adds XxHash64, a dependency-free XXH64 checked against vectors from the reference C implementation (tools/xxh64_vectors.c), with an allocation-free path for ASCII strings, plus batched getMany lookups and a JMH benchmark.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
ConstMap,VerifiedConstMapandPairedVerifiedConstMap: immutable maps from string or byte-array keys to 64-bit values, built with the binary fuse construction. They are a Java port of constmap (Go), and their files are interchangeable with rsconstmap (Rust) and fastconstmap (C/Python).Compatibility
CMAP0001,VMAP0001andPMAP0001, checked two ways:rust.*from constmap'stestdata/interop(copied tosrc/test/resources/constmap/);tools/constmap_vectors(Go) records each file's size and trailing FNV-1a checksum, which covers every byte, so no large fixtures are committed. This covers the small-size parameters, the retries with halved and doubled segments below 1M keys, and the path without retries above.CMAP0003with its key count, which is ignored, like the key count fastconstmap puts in the padding word.CMAP0002/VCMP0002, XXH3) with a message that names them. A file of the wrong map kind is also named.loadchecks the magic, the segment parameters (power-of-two segment length,(count+2)*length == array length) and the checksum, and throwsInvalidFilterExceptionon failure.Implementation notes
XxHash64: a dependency-free XXH64, checked against 740 vectors from the reference C xxhash (tools/xxh64_vectors.c).hash(String)hashes ASCII strings straight from their chars, with no allocation (11.7 vs 17.6 ns), and encodes other strings to UTF-8 first. lz4-java and zero-allocation-hashing also provide XXH64; I kept the library dependency-free.map[hash]value. Here each cell keeps the XOR of its key indices next to the XOR of the hashes, so a singleton cell names its key directly. Peeling order and output are unchanged.getManyhashes a block of 8 keys before reading the arrays: 25–40% faster at 10M keys.BinaryFuseFilter.wrap, or fastconstmap'sfrom_buffer) are left for a follow-up.Performance (Apple M4 Max, JDK 27, present keys in random order)
ConstMap.get(String)ConstMap.getManyVerifiedConstMap.get(String)PairedVerifiedConstMap.get(String)./mvnw packagepasses: 66 tests, javadoc doclint clean.