Skip to content

Commit

Permalink
Hide shards and determine_map behind the raw-api feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
xacrimon committed Jan 15, 2020
1 parent 3021d1a commit b72b841
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dashmap"
version = "3.0.2"
version = "3.0.3"
authors = ["Acrimon <[email protected]>"]
edition = "2018"
license = "MIT"
Expand All @@ -14,6 +14,7 @@ categories = ["concurrency", "algorithms", "data-structures"]

[features]
nightly = ["parking_lot/nightly"]
raw-api = []

[dev-dependencies]
criterion = "0.3.0"
Expand Down Expand Up @@ -46,4 +47,8 @@ harness = false
parking_lot = "0.10.0"
num_cpus = "1.11.1"
fxhash = "0.2.1"
serde = { version = "~1.0.24", optional = true, features = ["derive"] }
serde = { version = "1.0.104", optional = true, features = ["derive"] }
cfg-if = "0.1.10"

[package.metadata.docs.rs]
all-features = true
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ If you have any suggestions or tips do not hesitate to open an issue or a PR.

- `serde` - Enables serde support.

- `raw-api` - Enables the unstable raw-shard api.

## Contributing

DashMap is gladly accepts contributions!
Expand Down
15 changes: 11 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use std::iter::FromIterator;
use std::ops::{BitAnd, BitOr, Shl, Shr, Sub};
use t::Map;
use util::SharedValue;
use cfg_if::cfg_if;

type HashMap<K, V> = std::collections::HashMap<K, SharedValue<V>, FxBuildHasher>;

Expand Down Expand Up @@ -114,9 +115,13 @@ impl<'a, K: 'a + Eq + Hash, V: 'a> DashMap<K, V> {
/// let map = DashMap::<(), ()>::new();
/// println!("Amount of shards: {}", map.shards().len());
/// ```
#[inline]
pub fn shards(&self) -> &[RwLock<HashMap<K, V>>] {
&self.shards
cfg_if! {
if #[cfg(feature = "raw-api")] {
#[inline]
pub fn shards(&self) -> &[RwLock<HashMap<K, V>>] {
&self.shards
}
}
}

/// Finds which shard a certain key is stored in.
Expand All @@ -132,7 +137,9 @@ impl<'a, K: 'a + Eq + Hash, V: 'a> DashMap<K, V> {
/// println!("coca-cola is stored in shard: {}", map.determine_map("coca-cola"));
/// ```
#[inline]
pub fn determine_map<Q>(&self, key: &Q) -> usize
cfg_if! {
if #[cfg(feature = "raw-api")] { pub }
} fn determine_map<Q>(&self, key: &Q) -> usize
where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
Expand Down

0 comments on commit b72b841

Please sign in to comment.