https://github.com/filmil/sequence-map
A map of unsigned 64-bit keys into strings, written in rust
https://github.com/filmil/sequence-map
Last synced: 10 months ago
JSON representation
A map of unsigned 64-bit keys into strings, written in rust
- Host: GitHub
- URL: https://github.com/filmil/sequence-map
- Owner: filmil
- License: apache-2.0
- Created: 2020-05-16T05:11:34.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-05-17T10:24:59.000Z (over 5 years ago)
- Last Synced: 2025-02-28T08:43:41.530Z (11 months ago)
- Language: Rust
- Homepage:
- Size: 26.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
This crate implements a map of unsigned 64-bit keys into strings.
The map is optimized for creating it once, and then reading many times. The struct `Builder` is
used to build the map, and the struct `Map` is used for lookups.
The special property of the implementation is that it encodes all the data needed for the
lookup in a single sequence of bytes. This makes it rather interesting for dynamic loading of
data that can then be placed in an operating system's read only memory. The internal structure
requires no decoding when it is loaded (say from a file).
The map is internally represented as a trie with each level of the trie being indexed by a
number of bits of the key, starting from the least-significant bit side. So for example, when
creating the builder with 2 bits, then 2 bits will be chopped off the provided key for each
descent into the trie by one level.
Example:
```rust
use sequence_map::{Builder, Map};
const BITS: usize = 2;
let mut builder = Builder::new(BITS);
builder.insert(42, "Hello!");
// Note: a second insert under the same key does *not* replace the
// previously inserted key.
builder.insert(42, "Wonderful!");
builder.insert(84, "World!");
// This is the resulting byte sequence.
let bytes: Vec = builder.build();
// Now, look up some keys.
let lookup = Map::new(&bytes);
assert_eq!("Hello!", lookup.get(42).unwrap());
assert_eq!("World!", lookup.get(84).unwrap());
assert!(lookup.get(100).is_none());
```
> This is not an officially supported Google product.