Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V4 #81

Closed
wants to merge 411 commits into from
Closed

V4 #81

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
411 commits
Select commit Hold shift + click to select a range
a38e99f
Small fixes.
xacrimon Mar 9, 2020
3b8722d
insert and get on table.
xacrimon Mar 9, 2020
559756e
Aded remove functionality.
xacrimon Mar 9, 2020
cf1df0e
Branch prediction optimizations.
xacrimon Mar 10, 2020
94d89c4
Implemented extract on table.
xacrimon Mar 10, 2020
7dc5920
Added Table::len.
xacrimon Mar 10, 2020
aed940e
Capacity and better len.
xacrimon Mar 10, 2020
78494c4
Remove println.
xacrimon Mar 10, 2020
e128188
Formatted code.
xacrimon Mar 10, 2020
695148b
Added insert_get on table.
xacrimon Mar 10, 2020
d0389ec
Added update.
xacrimon Mar 10, 2020
d11d60a
Added contains_key.
xacrimon Mar 10, 2020
271dead
Added remove_if and remove_if_take.
xacrimon Mar 10, 2020
a09497b
Added retain.
xacrimon Mar 10, 2020
4fccc20
Removed useless likely hint.
xacrimon Mar 10, 2020
7966842
DashMap struct and constructor.
xacrimon Mar 11, 2020
89edc5f
Started implementing some methods.
xacrimon Mar 11, 2020
636b6bb
CachePadded counter.
xacrimon Mar 11, 2020
1759dd6
Implemented a bunch of methods.
xacrimon Mar 13, 2020
175f672
Code cleanup.
xacrimon Mar 13, 2020
9339bfc
Code cleanup.
xacrimon Mar 13, 2020
e0d19a3
Actually drop table.
xacrimon Mar 13, 2020
da7c048
Fix UAF.
xacrimon Mar 13, 2020
d634d8e
Tracked down as index issue.
xacrimon Mar 30, 2020
43e4583
nvm
xacrimon Mar 30, 2020
db35015
Started 598923th rewrite.
xacrimon Mar 30, 2020
22a98f2
Implemented find.
xacrimon Mar 30, 2020
c57d484
Small bugfix on find.
xacrimon Mar 30, 2020
0c85ba4
Resizecoordinator fix.
xacrimon Mar 30, 2020
87fbc5f
Implemented remove_if.
xacrimon Mar 30, 2020
3746421
Implemented retain.
xacrimon Mar 30, 2020
3425274
BucketArray::drop
xacrimon Mar 30, 2020
784d3b3
Added table impl.
xacrimon Mar 30, 2020
fc96c82
oh no.
xacrimon Mar 30, 2020
9b32d56
set_cache fix.
xacrimon Mar 30, 2020
d0d868a
Fixed incorrect test params.
xacrimon Mar 30, 2020
01dc60b
Fixed some code style.
xacrimon Mar 30, 2020
4c632d1
Improved pointer tagging.
xacrimon Mar 30, 2020
77e8197
impled drop.
xacrimon Mar 31, 2020
b039a2c
Fixed a couple bugs.
xacrimon Mar 31, 2020
776c650
debug on rel builds.
xacrimon Mar 31, 2020
b946d28
Fixed segfault on table drop.
xacrimon Mar 31, 2020
c3b28f7
Fixed another segfault on resize.
xacrimon Mar 31, 2020
9902e50
Read optimisation.
xacrimon Mar 31, 2020
f1a9fb6
Minor optimizations.
xacrimon Mar 31, 2020
fe7b9ed
oops.
xacrimon Mar 31, 2020
49db426
Faster hcache generation.
xacrimon Mar 31, 2020
cccade3
Done.
xacrimon Mar 31, 2020
495e016
Remove inline hints.
xacrimon Apr 3, 2020
63c61d4
MVCC stuff.
xacrimon Apr 3, 2020
8cac25d
cleanup.
xacrimon Apr 3, 2020
c7ea241
Scrapped.
xacrimon Apr 3, 2020
656e083
Relaxed atomic orderings.
xacrimon Apr 4, 2020
782b3ca
Removed rand dep.
xacrimon Apr 4, 2020
3ebc0ad
api fixes.
xacrimon Apr 4, 2020
9869b44
Updated todos.
xacrimon Apr 4, 2020
ca7bccd
Updated todos.
xacrimon Apr 4, 2020
b7d58b3
Probing optimizations.
xacrimon Apr 4, 2020
20568c2
todo update.
xacrimon Apr 4, 2020
04e5e75
Concurrent marking.
xacrimon Apr 4, 2020
9031cce
removed some todos for now.
xacrimon Apr 4, 2020
17902e7
Updated todos.
xacrimon Apr 4, 2020
72ab3e3
Updated todos.
xacrimon Apr 4, 2020
1ffa231
Save commit.
xacrimon Apr 4, 2020
1662ac7
Fixed stuff.
xacrimon Apr 4, 2020
bc6fa6e
Started working on fallback table impl.
xacrimon Apr 4, 2020
47c1209
Removed fallback for now.
xacrimon Apr 12, 2020
315e715
Fixed table trait.
xacrimon Apr 13, 2020
5d8583a
Iterator and len on Table trait.
xacrimon Apr 13, 2020
4cd34a1
Fix branch hint typo.
xacrimon Apr 13, 2020
a9e9406
ran fmt.
xacrimon Apr 13, 2020
ca9932b
Begin refactoring to impl iterators.
xacrimon Apr 17, 2020
ba9695e
Added iterator shim type.
xacrimon Apr 18, 2020
7fe7aa0
Minor fixes to iterator shim.
xacrimon Apr 18, 2020
837d839
Move x86-64 spec into its own module.
xacrimon Apr 18, 2020
ee40247
Moved recl into x86 specialized.
xacrimon Apr 18, 2020
df68eb7
Conditionally choose backend.
xacrimon Apr 18, 2020
6007962
Fixed incorrect length calculation on Table::replace.
xacrimon Apr 18, 2020
0223a82
Fix incorrect replace behaviour.
xacrimon Apr 18, 2020
a05985d
Fix doc typo.
xacrimon Apr 18, 2020
0740faf
Started implementing fallback backend.
xacrimon Apr 18, 2020
6fbcefa
Work on fallback.
xacrimon Apr 18, 2020
87c718f
Partial impl of fallback.
xacrimon Apr 18, 2020
62e0498
Finished fallback.
xacrimon Apr 18, 2020
1197f01
Removed some uneeded imports.
xacrimon Apr 18, 2020
fdf7cb9
Fix capacity miscalculation.
xacrimon Apr 18, 2020
3edc45f
Removed nightly intrinsics stuff.
xacrimon Apr 19, 2020
6dde544
Finished rebase.
xacrimon Apr 19, 2020
cc1e82f
Clean up cruft.
xacrimon Apr 19, 2020
bc90c1e
Update readme.
xacrimon Apr 19, 2020
1947ea7
Readme update.
xacrimon Apr 19, 2020
0340f77
Implemented iterators.
xacrimon Apr 19, 2020
a204d24
Added DashMap::is_empty.
xacrimon Apr 19, 2020
ab98ed8
Work on entry API.
xacrimon Apr 19, 2020
edd5158
scrap entry api.
xacrimon Apr 19, 2020
d403497
Add some basic documentation.
xacrimon Apr 19, 2020
961a62d
Removed worthless test.
xacrimon Apr 19, 2020
1dbbc91
Found an elusive segfault bug.
xacrimon Apr 19, 2020
2b0db95
Traced it to put_node returning a garbo pointer.
xacrimon Apr 19, 2020
f138a43
Fixed segfault due to returning non-stripped packed pointer.
xacrimon Apr 20, 2020
e60c606
Remove uneeded transmute.
xacrimon Apr 20, 2020
4c81248
Fix iterator segfault.
xacrimon Apr 20, 2020
351f58c
Removed method from api.
xacrimon Apr 20, 2020
864efc6
Element docs.
xacrimon Apr 20, 2020
e324059
Added iter docs.
xacrimon Apr 20, 2020
ed33c9f
Get rid of bencher.
xacrimon Apr 20, 2020
fadb64b
Code style.
xacrimon Apr 20, 2020
016a261
Added some rust api thingies for DashMap.
xacrimon Apr 20, 2020
0650c0b
Fixed wording.
xacrimon Apr 20, 2020
ca44fa6
Updated docs.
xacrimon Apr 20, 2020
25172a9
Some inlining.
xacrimon Apr 20, 2020
550b32e
More inlining.
xacrimon Apr 20, 2020
1b1cae4
Updated docs.
xacrimon Apr 20, 2020
48b4a0f
Added serde support.
xacrimon Apr 20, 2020
b04fa3d
Updated serde.
xacrimon Apr 20, 2020
91a57ef
Remove debug printlns.
xacrimon Apr 20, 2020
368f4be
Added more tests.
xacrimon Apr 20, 2020
6dfd6a2
bug fix.
xacrimon Apr 20, 2020
b66d841
Remove fix.
xacrimon Apr 20, 2020
d28ca57
Update remove.
xacrimon Apr 20, 2020
249c763
Fix segfault.
xacrimon Apr 20, 2020
c57be94
Fixed double-free.
xacrimon Apr 20, 2020
99b12b7
Added test.
xacrimon Apr 20, 2020
96b74f3
Increased test time.
xacrimon Apr 20, 2020
492e786
Made test better.
xacrimon Apr 20, 2020
7ffd748
made test reproduce bug.
xacrimon Apr 20, 2020
9e79a1b
note bugs.
xacrimon Apr 20, 2020
8fcbb61
Fixed pthread segfault in gc.
xacrimon Apr 21, 2020
c67647d
v4.0.0-rc0
xacrimon May 9, 2020
504b321
Removed scripts.
xacrimon May 9, 2020
aea5d81
Implemented IntoIterator for &DashMap.
xacrimon May 9, 2020
879cbe5
v4.0.0-rc1
xacrimon May 9, 2020
835c76b
v4.0.0-rc2.
xacrimon May 9, 2020
d6bf423
Fix #84.
xacrimon May 15, 2020
37ec964
v4.0.0-rc3
xacrimon May 15, 2020
6c6503b
Make alloc a folder module.
xacrimon May 15, 2020
b721e0f
Revert.
xacrimon May 15, 2020
b0aa973
fix: #83
xacrimon May 24, 2020
e24966d
Fix thread init deadlock on collect.
xacrimon May 24, 2020
de542f7
v4.0.0-rc4
xacrimon May 24, 2020
869f811
Added unsafe annotatations.
xacrimon Jun 1, 2020
2428ca9
4.0.0-rc5
xacrimon Jun 1, 2020
e821e1a
Updated readme.
xacrimon Jun 3, 2020
d58c07e
Drastically improved fallback.
xacrimon Jun 9, 2020
e9a16ab
Fix clippy lints.
xacrimon Jun 9, 2020
6610b38
Turned on some lints and fixed crate docs.
xacrimon Jun 9, 2020
e57e2bb
Turned off pedantic.
xacrimon Jun 9, 2020
4637864
v4.0.0-rc6
xacrimon Jun 10, 2020
035698b
Fixed comment typo.
xacrimon Jun 22, 2020
b8d2365
Save commit.
xacrimon Jun 22, 2020
876f9f0
Entry manager code.
xacrimon Jul 7, 2020
cfaceca
feat: added circular range stuff
xacrimon Jul 31, 2020
6527b3e
feat: check for entry flags in cas
xacrimon Jul 31, 2020
44fabf7
fix: remove uneeded checks in EntryManager::eq
xacrimon Jul 31, 2020
be1613b
feat: added skeleton match in the bucketarray cas
xacrimon Jul 31, 2020
f3c0035
feat: handle empty and keep cas output cases
xacrimon Aug 1, 2020
70990bb
fix: typo
xacrimon Aug 1, 2020
37a5d07
feat: handle CasOutput::New and removed redundant test
xacrimon Aug 1, 2020
50dfbfd
chore: cleanup rebase leftover
xacrimon Aug 1, 2020
9d428be
fix: force toolchain to 1.44.1
xacrimon Aug 1, 2020
e9f9e18
fix: readd people to the special thanks section
xacrimon Aug 1, 2020
75d382b
chore: remove uneeded entry from .gitignore and disable lto for concu…
xacrimon Aug 1, 2020
4df3ed7
chore: install rustfmt in ci for new toolchain
xacrimon Aug 1, 2020
6f7c745
fix: ci toolchain woes
xacrimon Aug 1, 2020
cb0f71d
chore: install fmt
xacrimon Aug 1, 2020
1edb7c8
chore: add clippy
xacrimon Aug 1, 2020
23b3542
chore: remove podman from ci
xacrimon Aug 1, 2020
305c70c
refactor: reworked allocation and bucket/element code
xacrimon Aug 1, 2020
8ea8da3
feat: added EntryManager trait
xacrimon Aug 1, 2020
545a64b
fix: remove docs.rs feature specifier
xacrimon Aug 4, 2020
fe16205
chore: format code
xacrimon Aug 4, 2020
697d526
chore: move msrv badge below downloads badge
xacrimon Aug 4, 2020
dc26612
feat: added some more methods and doc comments to the EntryManager trait
xacrimon Aug 4, 2020
c375fc8
feat: added module entry_manager::generic as a base entry manager tha…
xacrimon Aug 4, 2020
e9a2c4e
feat: added a skeleton implementation of a generic entry manager that…
xacrimon Aug 4, 2020
07205ff
feat: implemented GenericEntryManager::eq
xacrimon Aug 4, 2020
c1fe352
feat: extract bit checking into a seperate function is_on
xacrimon Aug 4, 2020
77fa5a5
docs: fixed root crate docs
xacrimon Aug 5, 2020
b1e0c6c
feat: implemented GenericEntryManager::cas
xacrimon Aug 5, 2020
638f5b7
docs: add unsafe code comments
xacrimon Aug 5, 2020
db6a854
docs: improved doc comment
xacrimon Aug 5, 2020
717aa24
test: make sure the circular iterator yields the expected set of valu…
xacrimon Aug 5, 2020
e642d09
test: ensure the resize flag is set correctly with GenericEntryManager
xacrimon Aug 5, 2020
3b6ff54
fix: correctly set resize flag on entry manager
xacrimon Aug 5, 2020
a887a1f
chore: formatted code
xacrimon Aug 5, 2020
cc5b63d
fix: strip bits correctly in GenericEntryManager
xacrimon Aug 5, 2020
e7754d7
fix: set tombstone flag correctly
xacrimon Aug 5, 2020
f6f88a5
test: ensure we can create and retrieve data from an entry using Gene…
xacrimon Aug 5, 2020
5b468fa
test: ensure the tombstone flag is set once an entry goes from occupi…
xacrimon Aug 5, 2020
73a85ff
chore: format code
xacrimon Aug 5, 2020
148c616
feat: loom shim
xacrimon Aug 5, 2020
842f75c
feat: use loom for testing
xacrimon Aug 5, 2020
7e3ec06
fix: remove loom tests but retain the loom shim
xacrimon Aug 5, 2020
f00badb
feat: add empty gc module
xacrimon Aug 5, 2020
10732e1
docs: update comment
xacrimon Aug 5, 2020
289c477
fix: I think we can use the regular Hyaline actually
xacrimon Aug 5, 2020
6f3137a
feat: garbage queue structure
xacrimon Aug 6, 2020
b14cd33
feat: added core functionality to the new gc
xacrimon Aug 6, 2020
a4aeaaf
feat: add garbage list field to gc
xacrimon Aug 6, 2020
c4d46f0
feat: added Gc::retire for retiring old nodes
xacrimon Aug 6, 2020
f2aa8ac
feat: deallocate all garbage when a gc instance is dropped
xacrimon Aug 6, 2020
b668215
refactor: switch Bucket and GenericEntryManager code to use the new gc
xacrimon Aug 6, 2020
90bac8c
fix: unsound queue
xacrimon Aug 7, 2020
d130524
feat: added Bucket::read for creating a Guard from a Bucket
xacrimon Aug 7, 2020
3537f9e
feat: return true on success of Queue::push and false if capacity hit
xacrimon Aug 7, 2020
0d197ff
chore: remove Queue::is_empty
xacrimon Aug 7, 2020
3aba833
feat: added Gc::try_advance()
xacrimon Aug 8, 2020
594a598
feat: dynamic gc collection
xacrimon Aug 9, 2020
93ff555
chore: format code
xacrimon Aug 9, 2020
d8ce244
refactor: reworked thread_local
xacrimon Aug 9, 2020
f319afb
fix: export Guard
xacrimon Aug 9, 2020
e3cd50b
docs: update and add comments
xacrimon Aug 10, 2020
dfe1e4b
fix: change initial capacity of thread priority queue from 4 to 8
xacrimon Aug 10, 2020
a7f23fe
docs: added some more comments
xacrimon Aug 10, 2020
5aaedd8
fix: don't enter a critical section in Bucket::read
xacrimon Aug 11, 2020
9ddc78b
refactor: reworked gc
xacrimon Aug 11, 2020
53eab85
chore: remove unused code
xacrimon Aug 11, 2020
7ff3822
fix: perform a full fence after pinning
xacrimon Aug 11, 2020
2339d22
docs: add a whole bunch of docs
xacrimon Aug 11, 2020
c23f4aa
fix: undefined behaviour at gc/queue.rs:45 caused by writing to a poi…
xacrimon Aug 11, 2020
b5b3f95
test: ensure GlobalObjectAllocator works correctly
xacrimon Aug 11, 2020
9748f9d
fix: rename test to tests
xacrimon Aug 11, 2020
bf0b2ba
test: ensure queue works as expected
xacrimon Aug 11, 2020
32dafc1
chore: don't run ci on wasm
xacrimon Aug 11, 2020
768f04b
docs: added som doc comments in src/gc/thread_state.rs
xacrimon Aug 11, 2020
a3aa04b
fix: write the tag to fresh buckets properly
xacrimon Aug 12, 2020
b298a31
test: add a lot of gc asserts
xacrimon Aug 12, 2020
3cc1898
docs: add doc comments for Bucket
xacrimon Aug 12, 2020
6521c00
docs: improve docs for Pcg32
xacrimon Aug 12, 2020
b790f4e
feat: use WyRng instead of Pcg32 for better aarch64 performance
xacrimon Aug 12, 2020
968440c
feat: add OptionUnchecked extension trait for unchecked unwrapping
xacrimon Aug 12, 2020
133c84d
fix: use unwrap_unchecked where possible
xacrimon Aug 12, 2020
9b838ff
fix: perfom unchecked access where possible in thread_local/table.rs
xacrimon Aug 12, 2020
8b05c2b
fix: relax atomic orderings where possible and add needed fenches to …
xacrimon Aug 13, 2020
f9f9030
fix: update orderings and remove some fences
xacrimon Aug 13, 2020
d3e5c9d
fix: we that acquire I think
xacrimon Aug 13, 2020
e43413d
fix: relax a lot of orderings in gc
xacrimon Aug 13, 2020
2c9e06c
chore: relax a bunch of memory orderings
xacrimon Aug 13, 2020
a6556ae
fix: load the global epoch with acquire ordering in Gc::retire to pre…
xacrimon Aug 13, 2020
9693646
fix: we only need to perform a relaxed decrement of the active counter
xacrimon Aug 13, 2020
02dccd1
fix: drop the old queue at the end of a collect cycle
xacrimon Aug 13, 2020
daa9193
fix: use relaxed loads where possible in thread_local and only fall b…
xacrimon Aug 13, 2020
86b695f
fix: relax atomic orderings where possible in thread_local and use re…
xacrimon Aug 13, 2020
ed8b007
docs: fix a typo
xacrimon Aug 13, 2020
6af1760
docs: add safety and atomic ordering explanation comments
xacrimon Aug 13, 2020
3cc460c
fix: use unchecked array access where possible
xacrimon Aug 13, 2020
65028fd
test: add debug asserts to enforce safety invariants for unsafe funti…
xacrimon Aug 13, 2020
6228bf9
fix: remove lock in thread local table and make needed changes
xacrimon Aug 13, 2020
8d2a370
style: remove newline
xacrimon Aug 13, 2020
ce3f10a
refactor: started porting code over to use flize
xacrimon Aug 17, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ jobs:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: setup
run: |
rustup install stable-2020-06-18-x86_64-unknown-linux-gnu
rustup component add rustfmt --toolchain stable-2020-06-18-x86_64-unknown-linux-gnu
rustup component add clippy --toolchain stable-2020-06-18-x86_64-unknown-linux-gnu
- name: style
run: cargo fmt -- --check
- name: clippy
Expand All @@ -21,8 +26,7 @@ jobs:
i686-unknown-linux-gnu,
aarch64-unknown-linux-gnu,
armv7-linux-androideabi,
powerpc-unknown-linux-gnu,
wasm32-unknown-emscripten
powerpc-unknown-linux-gnu
]
steps:
- uses: actions/checkout@v2
Expand All @@ -36,15 +40,6 @@ jobs:

# --

# add podman ppa

echo "adding podman ppa"
. /etc/os-release
echo "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}/ /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}/Release.key | sudo apt-key add -

# --

# add docker ppa

echo "adding docker ppa"
Expand All @@ -53,11 +48,11 @@ jobs:

# --

# install docker and podman
# install docker

echo "installing docker and podman"
echo "installing docker"
sudo apt-get update
sudo apt-get install docker-ce podman
sudo apt-get install docker-ce

# --

Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
**/*.rs.bk
Cargo.lock
/Cargo.lock
/concurrent-test/target
16 changes: 2 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dashmap"
version = "3.11.10"
version = "4.0.0-rc6"
authors = ["Acrimon <[email protected]>"]
edition = "2018"
license = "MIT"
Expand All @@ -12,17 +12,5 @@ documentation = "https://docs.rs/dashmap"
keywords = ["atomic", "concurrent", "hashmap"]
categories = ["concurrency", "algorithms", "data-structures"]

[features]
default = []
raw-api = []
no_std = ["hashbrown"]

[dependencies]
num_cpus = "1.13.0"
ahash = "0.3.8"
serde = { version = "1.0.114", optional = true, features = ["derive"] }
cfg-if = "0.1.10"
hashbrown = { version = "0.8.0", optional = true }

[package.metadata.docs.rs]
features = ["raw-api", "serde"]
flize = { version = "2.0.0", default-features = false, features = ["ebr"] }
44 changes: 18 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
# DashMap

Blazingly fast concurrent map in Rust.
DashMap is a blazing fast implementation of a concurrent key -> value map.

DashMap is an implementation of a concurrent associative array/hashmap in Rust.
DashMap tries to implement an easy to use API while also having more advanced interfaces
for squeezing out performance.

DashMap tries to implement an easy to use API similar to `std::collections::HashMap`
with some slight changes to handle concurrency.

DashMap tries to be very simple to use and to be a direct replacement for `RwLock<HashMap<K, V>>`.
To accomplish these all methods take `&self` instead modifying methods taking `&mut self`.
This allows you to put a DashMap in an `Arc<T>` and share it between threads while being able to modify it.

DashMap puts great effort into performance and aims to be as fast as possible.
We put great effort into performance and aims to be as fast as possible.
If you have any suggestions or tips do not hesitate to open an issue or a PR.

[Documentation](https://docs.rs/dashmap)
Expand All @@ -20,35 +14,33 @@ If you have any suggestions or tips do not hesitate to open an issue or a PR.

[![downloads](https://img.shields.io/crates/d/dashmap)](https://crates.io/crates/dashmap)

## Cargo features
[![minimum rustc version](https://img.shields.io/badge/rustc-1.44.1-orange.svg)](https://github.com/rust-random/rand#rust-version-requirements)

## Serde support

- `no_std` - Enable no_std + alloc support.
Turn on the `serde` feature and `DashMap` will implement `Serialize` and `Deserialize`.

## Contributing

- `serde` - Enables serde support.
DashMap is gladly accepts contributions!
Do not hesitate to open issues or PR's.

## Performance

- `raw-api` - Enables the unstable raw-shard api.
DashMap is included in a set of benchmarks found [here](https://git.acrimon.dev/Acrimon/conc-map-bench)
that use [bustle](https://docs.rs/bustle), a port of the libcuckoo benchmark harness.
Benchmarks are a best effort and we try to make them as unbiased and realistic as possible. Contributions are accepted there too!

## Support

[![Foo](https://c5.patreon.com/external/logo/[email protected])](https://patreon.com/acrimon)
[![Patreon](https://c5.patreon.com/external/logo/[email protected])](https://patreon.com/acrimon)

Creating and testing open-source software like DashMap takes up a large portion of my time
and comes with costs such as test hardware. Please consider supporting me and everything I make for the public
to enable me to continue doing this.

If you want to support me please head over and take a look at my [patreon](https://www.patreon.com/acrimon).

## Contributing

DashMap is gladly accepts contributions!
Do not hesitate to open issues or PR's.

I will take a look as soon as I have time for it.

## Performance

A comprehensive benchmark suite including DashMap can be found [here](https://git.acrimon.dev/Acrimon/conc-map-bench).

## Special thanks

- [Jon Gjengset](https://github.com/jonhoo)
Expand Down
1 change: 1 addition & 0 deletions rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
stable-2020-06-18
84 changes: 84 additions & 0 deletions src/alloc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//! The `alloc` module contains types and traits for
//! customizing the memory allocation behaviour of the map.

use std::alloc::{alloc, dealloc, Layout};
use std::ptr;

/// This trait defines the interface for the object allocator the map uses to allocate buckets.
/// Bucket allocators should be swappable to the needs of the user.
/// The `V` type parameter designates the object type.
pub trait ObjectAllocator<V>: Send + Sync {
/// The `Tag` associated type is a unique tag that can be used to identify an allocation.
type Tag: Copy + Default;

/// Allocates a new object and returns a identifying tag and a pointer.
/// The pointer must the valid for the lifetime of the allocator.
fn allocate(&self, item: V) -> (Self::Tag, *mut V);

/// Deallocates an object with a specific tag.
///
/// # Safety
/// An allocation may only be deallocated exactly once, hence this function is unsafe.
/// Calling this function multiple times for the same allocation is undefined behaviour.
///
/// Note that you may call this function multiple times with the same tag
/// if you've received the same tag multiple times from `allocate`.
/// This may happen as tag reuse is allowed.
unsafe fn deallocate(&self, tag: Self::Tag);
}

/// The default object allocator. This is merely a typed wrapper around the global allocator.
/// This shouldn't have any unexpected properties and is a balanced choice,
/// only crippled by the occasionally mediocre performance of the global allocator.
pub struct GlobalObjectAllocator;

impl<V> ObjectAllocator<V> for GlobalObjectAllocator {
type Tag = usize;

fn allocate(&self, item: V) -> (Self::Tag, *mut V) {
let layout = Layout::new::<V>();
let ptr = unsafe { alloc(layout) } as *mut V;

// # Safety
// The block of memory we are writing to is freshly allocated with the correct layout.
// Since there is nothing there we can safely perform a raw write.
unsafe { ptr::write(ptr, item) }

(ptr as usize, ptr)
}

unsafe fn deallocate(&self, tag: Self::Tag) {
let ptr = tag as *mut V;
let layout = Layout::new::<V>();

// most allocators accept null but we consider it invalid
debug_assert!(!ptr.is_null());

// # Safety
// We call `drop_in_place` here to drop the value at this memory location.
// This is safe to do since it is guaranteed to be initialized.
ptr::drop_in_place(ptr);

// # Safety
// Here we dellocate the memory which is fine to do as it is guaranteed
// to be allocated assuming the implementation of `allocate` is valid.
// `dealloc` does not perform any drop calls, that's why we did that manually earlier.
dealloc(ptr as _, layout);
}
}

#[cfg(test)]
mod tests {
use super::{GlobalObjectAllocator, ObjectAllocator};

#[test]
fn alloc_dealloc() {
let allocator = GlobalObjectAllocator;
let (tag, _ptr) =
<GlobalObjectAllocator as ObjectAllocator<usize>>::allocate(&allocator, 55);

unsafe {
<GlobalObjectAllocator as ObjectAllocator<usize>>::deallocate(&allocator, tag);
}
}
}
73 changes: 73 additions & 0 deletions src/bucket.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
use crate::alloc::{GlobalObjectAllocator, ObjectAllocator};
use std::ops::Deref;
use flize::{ebr::Ebr, function_runner::FunctionRunner, Shield};

/// Represents an occupied slot in a map.
/// Besides the key and value it contains the allocator tag
/// so it can deallocate itself when it's lifetime ends.
pub struct Bucket<K, V, A: ObjectAllocator<Self>> {
pub(crate) tag: A::Tag,
pub(crate) key: K,
pub(crate) value: V,
}

impl<K, V, A: ObjectAllocator<Self>> Bucket<K, V, A> {
/// Create a new bucket with a default tag.
/// The tag will need to be set to the correct value before being published to the map.
pub fn new(key: K, value: V) -> Self {
Self {
tag: A::Tag::default(),
key,
value,
}
}

pub fn read<'a>(&'a self, shield: Shield<'a, Ebr<FunctionRunner>>) -> Guard<'a, K, V, A> {
Guard::new(self, shield)
}
}

/// A guard is a view of a map entry.
/// It exists to automatically manage memory behind the scenes.
pub struct Guard<'a, K, V, A: ObjectAllocator<Bucket<K, V, A>> = GlobalObjectAllocator> {
bucket: &'a Bucket<K, V, A>,
shield: Shield<'a, Ebr<FunctionRunner>>,
}

impl<'a, K, V, A: ObjectAllocator<Bucket<K, V, A>>> Guard<'a, K, V, A> {
fn new(bucket: &'a Bucket<K, V, A>, shield: Shield<'a, Ebr<FunctionRunner>>) -> Self {
Self { bucket, shield }
}

/// Returns the key associated with this entry.
pub fn key(&self) -> &K {
&self.bucket.key
}

/// Returns the value associated with this entry.
pub fn value(&self) -> &V {
&self.bucket.value
}

/// Returns both the key and the value associated with this entry.
pub fn pair(&self) -> (&K, &V) {
(&self.bucket.key, &self.bucket.value)
}
}

impl<'a, K, V, A: ObjectAllocator<Bucket<K, V, A>>> Deref for Guard<'a, K, V, A> {
type Target = V;

fn deref(&self) -> &Self::Target {
self.value()
}
}

impl<'a, K, V, A: ObjectAllocator<Bucket<K, V, A>>> Clone for Guard<'a, K, V, A> {
fn clone(&self) -> Self {
Self {
bucket: self.bucket,
shield: self.shield.clone(),
}
}
}
Loading