A port of Java's java.util.concurrent.ConcurrentHashMap
to Rust.
The port is based on the public domain source file from JSR166 as of
CVS revision 1.323, and is jointly licensed under MIT and Apache 2.0
to match the Rust API guidelines. The Java source files are included
under the jsr166/
subdirectory for easy reference.
The port was developed as part of a series of live coding streams kicked off by this tweet.
There are a number of things missing from this port that exist in the
original Java code. Some of these
are indicated by TODO
blocks in the code, but this is (maybe) a more
complete list. For all of these, PRs are warmly welcome, and I will try
to review them as promptly as I can! Feel free to open draft PRs if you
want suggestions for how to proceed.
- Add benchmarks for single-core (from
hashbrown
) and concurrent (fromdashmap
) performance measurements. - Finish the safety argument for
BinEntry::Moved
(see theFIXME
comment here (and eventually inremove
)). - Implement
with_hasher
andwith_capacity_and_hasher
. - Implement
rayon
parallel iterators. The notes and code initer/plumbing
may be helpful. - Implement
drain
andIntoIterator
(for both owned and&
). - Implement
retain
. - Implement
clear
(see the Java method) - Implement
reserve
. - Implement
get_key_value
. - Implement
Index
(to supportmap[key]
). Make sure to look at the bounds thatstd
'sHashMap
uses! - Implement
std::fmt::Debug
properly probably usingDebugMap
. - Implement
Clone
. - Use the sharded counters optimization (
LongAdder
andCounterCell
in Java) inadd_count
. - Add
computeIfAbsent
and friends. I have a suspicion thatReservationNode
could also be used to implement anEntry
-API like the one onstd::collections::HashMap
. - Implement the
TreeNode
optimization for large bins. Make sure you also read the implementation notes on that optimization in the big comment in the Java code. - Implement batch operations like
from_iter
andextend
. Note the effect on initial capacity. - Add (optional) serialization and deserialization support.
- Provide methods that wrap
get
,insert
,remove
, and friends so that the user does not need to know aboutGuard
. - Use
num_cpus
to choose resize stride more intelligently.
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.