You may want to:
- Buy my books on Amazon
- Read my blog at yegor256.com
- Subscribe to my channel in Telegram
- Follow me on Twitter
- Subscribe to my YouTube channel
- Check the project we're working on right now: EO (help needed, please contribute!)
๐ The fastest (for very small maps!) alternative of Rust HashMap, which doesn't use hashing and doesn't use heap
Home Page: https://crates.io/crates/micromap
License: MIT License
You may want to:
Let's implemented similar to this: https://doc.rust-lang.org/std/collections/struct.HashMap.html#method.entry
Currently when a Map
gets dropped it does not clean up any of it's keys or values i.e. the following tests fail:
#[test]
fn drops_keys() {
use std::rc::Rc;
let mut m: Map<Rc<()>, (), 8> = Map::new();
let k = Rc::new(());
m.insert(Rc::clone(&k), ());
drop(m);
assert_eq!(Rc::strong_count(&k), 1);
}
#[test]
fn drops_values() {
use std::rc::Rc;
let mut m: Map<(), Rc<()>, 8> = Map::new();
let v = Rc::new(());
m.insert((), Rc::clone(&v));
drop(m);
assert_eq!(Rc::strong_count(&v), 1);
}
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These problems occurred while renovating this repository. View logs.
These updates encountered an error and will be retried. Click on a checkbox below to force a retry now.
Cargo.toml
serde 1.0.200
bincode 1.3.3
hashbrown 0.14.5
heapless 0.8.0
rustc-hash 2.0.0
nohash-hasher 0.2.0
tinymap 0.4.0
linked-hash-map 0.5.6
linear-map 1.2.0
indexmap 2.2.6
litemap 0.7.0
.github/workflows/actionlint.yml
actions/checkout v4
ubuntu 22.04
.github/workflows/benchmark.yml
actions/checkout v4
peter-evans/create-pull-request v7
ubuntu 22.04
.github/workflows/cargo.yml
actions/checkout v4
actions/setup-java v4
actions-rs/toolchain v1
ubuntu 22.04
.github/workflows/copyrights.yml
actions/checkout v4
yegor256/copyrights-action 0.0.5
ubuntu 22.04
.github/workflows/markdown-lint.yml
actions/checkout v4
articulate/actions-markdownlint v1
ubuntu 22.04
.github/workflows/no_std.yml
actions/checkout v4
.github/workflows/pdd.yml
actions/checkout v4
ubuntu 22.04
.github/workflows/shellcheck.yml
actions/checkout v4
ubuntu 22.04
.github/workflows/tarpaulin.yml
actions/checkout v4
actions-rs/toolchain v1
actions-rs/tarpaulin v0.1
codecov/codecov-action v4
ubuntu 22.04
.github/workflows/up.yml
actions/checkout v4
peter-evans/create-pull-request v7
ubuntu 22.04
.github/workflows/xcop.yml
actions/checkout v4
ubuntu 22.04
.github/workflows/yamllint.yml
actions/checkout v4
ibiqlik/action-yamllint v3
ubuntu 22.04
I'd love to see a Set added as a wrapper around Map, much as rust's HashSet is a convenience wrapper around HashMap.
At the moment, we don't drop()
the keys/values. Maybe we should when we clear the map?
Let's implement it similar to this: https://doc.rust-lang.org/std/collections/struct.HashMap.html#impl-Index%3C%26Q%3E-for-HashMap%3CK%2C%20V%2C%20S%3E
As self.next <= N always holds, the construction
for i in 0..N {
if self.next <= i { break; }
can always be written as
for i in 0..self.next {
Let's add support for no_std
context
Let's add https://github.com/jonhoo/flurry to the tests
Let's get it back to 90%+
According to our benchmark, we are slower than linear_map::LinearMap
when map size is bigger than 5, but we shouldn't be, since we use the same algorithm as they do. They use Vec
, while we manage our own array. Let's investigate and fix.
Somehow Vec
and HashMap
work with keys and values that don't implement Copy
. We should do the same. I'm not sure exactly how this can be done, but it should be possible.
Let's implement them similar to this: https://doc.rust-lang.org/std/collections/struct.HashMap.html#method.values
Let's create a new GitHub Action workflow, which will (on every new tag):
src/bin
.csv
fileREADME.md
Let's implement it similar to how it's done in HashMap
Let's implement it similar to this: https://doc.rust-lang.org/std/collections/struct.HashMap.html#method.retain
Let's implement, similar to how it's done here: https://doc.rust-lang.org/std/collections/struct.HashMap.html#method.keys
Also, into_keys()
: https://doc.rust-lang.org/std/collections/struct.HashMap.html#method.into_keys
A safe API should never cause UB, implement an unsafe function like insert_unchecked instead.
Let's implement it similar to this: https://doc.rust-lang.org/std/collections/struct.HashMap.html#method.remove_entry
Cloning is not required for the core functionality of micromap
as well as for HashMap
, and this restriction can be removed from the many implementation blocks. The Clone
constraint can be added separately for functions that really need it. E.g. that's how remove_entry's declaration may look like:
pub fn remove_entry<Q: PartialEq + ?Sized>(&mut self, k: &Q) -> Option<(K, V)>
where
K: Borrow<Q> + Clone,
V: Clone,
{
...
}
It's only function in the main block that need Clone
, but I believe it's possible to remove it from there too although this is not necessary.
Impl blocks like IntoIterator for &Map
and Clone for Map
must declare its own constraint if it needed. They actually do it anyway and there is no need to change anything there.
If K or V not deriving Clone
then it will not be possible to call into_iter()
and clone()
but all other methods shoud work.
In fact, standard HashMap
are not required Clone
for into_iter()
neither it to be called by reference nor by value and it is the difference between it and the micromap
. IntoIterator
for &HashMap
returns references to its elements and IntoIterator
for HashMap
just comsumes a map so it's not accessible anymore.
As it's currently written the new in src/ctors.rs
can lead to undefined behavior in safe Rust. You can invoke it with the following test:
#[test]
fn undefined() {
let _m: Map<Vec<u8>, u8, 1> = Map::new();
}
I'm either getting a SIGILL
or SIGSEGV
depending on the actual conditions when running tests in release with
cargo test --release -- ctors::undefined
Let's implement it similar to this: https://doc.rust-lang.org/std/collections/struct.HashMap.html#impl-From%3C%5B(K%2C%20V)%3B%20N%5D%3E-for-HashMap%3CK%2C%20V%2C%20RandomState%3E
The current implementation requires to loop over empty slots. The code could be simpler - and depending on the use case faster - if the last pair would be moved to the empty slot on deletion and empty slots would never occur in the range 0..self.next
.
For instance the implementation of len(&self)
would reduce to self.next
(therefore I would suggest renaming next
to len
if this adjustment would be made).
I didn't implement and benchmark this, but it potentially could be interesting:
Let's have two arrays instead of one:
pairs0: [MaybeUninit<(K, V)>; N], // for keys whose first bit is 0
pairs1: [MaybeUninit<(K, V)>; N], // for keys whose first bit is 1
The idea under them is pretty simple -- in the first array we will store pairs, where first (or any other fixed) bit is 0, the rest -- in the other.
My intuition why it would work:
N / 2
iterations in some cases.Some thoughts about good implementation:
Sized
structs, and even for structs which have small size (not bigger than 8 bytes???)Did someone tested such approach? Maybe any analogues you benchmarking against?
This test fails:
let mut m1: Map<u8, i32, 10> = Map::new();
m1.insert(1, 42);
let mut m2: Map<u8, i32, 10> = Map::new();
m2.insert(1, 42);
assert!(m1.eq(&m2));
I believe, it must pass. Let's fix.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.