From d6dfb891593d43b5045540d4c12841b7dd52e233 Mon Sep 17 00:00:00 2001 From: Avril Date: Sun, 20 Sep 2020 13:27:02 +0100 Subject: [PATCH] documented --- .#README.md | 1 - README.md | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) delete mode 120000 .#README.md diff --git a/.#README.md b/.#README.md deleted file mode 120000 index 22fde22..0000000 --- a/.#README.md +++ /dev/null @@ -1 +0,0 @@ -avril@eientei.889:1600549970 \ No newline at end of file diff --git a/README.md b/README.md index 936f1cb..9d1eca2 100644 --- a/README.md +++ b/README.md @@ -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. `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 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.