master
Avril 4 years ago
parent e4a11ee8f8
commit d6dfb89159
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -1 +0,0 @@
avril@eientei.889:1600549970

@ -3,6 +3,22 @@ A small table map using single byte key indecies. Designed for maps with tiny ke
Pages are stored as 256 entry key-value arrays which are indexed by the byte key index. The key is compared for collision check and on collision the next page is checked or inserted if needed. Pages are stored as 256 entry key-value arrays which are indexed by the byte key index. The key is compared for collision check and on collision the next page is checked or inserted if needed.
`smallmap` does not ever need to allocate more than 1 page for types which all invariants can be represented as unique bytes. `smallmap` does not ever need to allocate more than 1 page for types which all invariants can be represented as unique bytes.
## Usage
The API is a similar subset to `HashMap`, containing the same `insert`, `get`, and `entry` functions:
``` rust
fn max_char(chars: &str) -> (char, usize)
{
let mut map = Map::new();
for x in chars.chars() {
*map.entry(x).insert_or(0usize) += 1;
}
map.into_iter().max_by_key(|(k, v)| v).unwrap_or_default()
}
```
## Use cases ## Use cases
Designed for instances where you want a small map with relatively trivial keys (e.g. primitive type). Designed for instances where you want a small map with relatively trivial keys (e.g. primitive type).
Performance can greately outpace hash-based by an order of magnitude or more in these cases. Performance can greately outpace hash-based by an order of magnitude or more in these cases.

Loading…
Cancel
Save