It is an alternative implementation of a map in Rust, which works much faster under the following conditions:
- Keys are
usize - Keys used sequentially (e.g., the 5th key is inserted only when 0..4th are in the map)
- Values implement
Copy
See the benchmarking results below.
First, add this to Cargo.toml:
[]
= "0.0.0"
Then, use it like a standard hash map... well, almost:
use Map;
let mut m : = new; // allocation on stack
m.insert;
m.insert;
assert_eq!;
Pay attention, here the map is created with an extra generic argument 100. This is
the total size of the map, which is allocated on stack when ::new() is called.
If more than 100 keys will be added to the map, it will panic.
Read the API documentation.
The struct
emap::Map is designed as closely similar to
std::collections::HashMap as possible.
Benchmark
There is a summary of a simple benchmark, where we compared emap::Map with
a few other Rust maps, changing the total capacity of the map (horizontal axis).
We applied the same interactions
(benchmark.rs)
to them and measured how fast they performed. In the following table,
the numbers over 1.0 indicate performance gain,
while the numbers below 1.0 demonstrate performance loss.
How to Contribute
First, install Rust and then:
If everything goes well, fork repository, make changes,
send us a pull request.
We will review your changes and apply them to the master branch shortly,
provided they don't violate our quality standards. To avoid frustration,
before sending us your pull request please run cargo test again. Also,
run cargo fmt and cargo clippy.