Wraps this DashMap into a read-only view. This view allows to obtain raw references to the stored values.
Creates a new DashMap with a capacity of 0 and the provided hasher.
\nuse dashmap::DashMap;\nuse std::collections::hash_map::RandomState;\n\nlet s = RandomState::new();\nlet reviews = DashMap::with_hasher(s);\nreviews.insert(\"Veloren\", \"What a fantastic game!\");Creates a new DashMap with a specified starting capacity and hasher.
\nuse dashmap::DashMap;\nuse std::collections::hash_map::RandomState;\n\nlet s = RandomState::new();\nlet mappings = DashMap::with_capacity_and_hasher(2, s);\nmappings.insert(2, 4);\nmappings.insert(8, 16);Creates a new DashMap with a specified hasher and shard amount
\nshard_amount should be greater than 0 and a power of two.\nIf a shard_amount which is not a power of two is provided, the function will panic.
\nuse dashmap::DashMap;\nuse std::collections::hash_map::RandomState;\n\nlet s = RandomState::new();\nlet mappings = DashMap::with_hasher_and_shard_amount(s, 32);\nmappings.insert(2, 4);\nmappings.insert(8, 16);Creates a new DashMap with a specified starting capacity, hasher and shard_amount.
\nshard_amount should greater than 0 and be a power of two.\nIf a shard_amount which is not a power of two is provided, the function will panic.
\nuse dashmap::DashMap;\nuse std::collections::hash_map::RandomState;\n\nlet s = RandomState::new();\nlet mappings = DashMap::with_capacity_and_hasher_and_shard_amount(2, s, 32);\nmappings.insert(2, 4);\nmappings.insert(8, 16);Hash a given item to produce a usize.\nUses the provided or default HashBuilder.
\nAllows you to peek at the inner shards that store your data.\nYou should probably not use this unless you know what you are doing.
\nRequires the raw-api feature to be enabled.
use dashmap::DashMap;\n\nlet map = DashMap::<(), ()>::new();\nprintln!(\"Amount of shards: {}\", map.shards().len());Provides mutable access to the inner shards that store your data.\nYou should probably not use this unless you know what you are doing.
\nRequires the raw-api feature to be enabled.
use dashmap::DashMap;\nuse dashmap::SharedValue;\nuse std::hash::{Hash, Hasher, BuildHasher};\n\nlet mut map = DashMap::<i32, &'static str>::new();\nlet shard_ind = map.determine_map(&42);\nlet mut factory = map.hasher().clone();\nlet hasher = |tuple: &(i32, SharedValue<&'static str>)| {\n let mut hasher = factory.build_hasher();\n tuple.0.hash(&mut hasher);\n hasher.finish()\n};\nlet data = (42, SharedValue::new(\"forty two\"));\nlet hash = hasher(&data);\nmap.shards_mut()[shard_ind].get_mut().insert(hash, data, hasher);\nassert_eq!(*map.get(&42).unwrap(), \"forty two\");Consumes this DashMap and returns the inner shards.\nYou should probably not use this unless you know what you are doing.
Requires the raw-api feature to be enabled.
See [DashMap::shards()] and [DashMap::shards_mut()] for more information.
Finds which shard a certain key is stored in.\nYou should probably not use this unless you know what you are doing.\nNote that shard selection is dependent on the default or provided HashBuilder.
\nRequires the raw-api feature to be enabled.
use dashmap::DashMap;\n\nlet map = DashMap::new();\nmap.insert(\"coca-cola\", 1.4);\nprintln!(\"coca-cola is stored in shard: {}\", map.determine_map(\"coca-cola\"));Finds which shard a certain hash is stored in.
\nRequires the raw-api feature to be enabled.
use dashmap::DashMap;\n\nlet map: DashMap<i32, i32> = DashMap::new();\nlet key = \"key\";\nlet hash = map.hash_usize(&key);\nprintln!(\"hash is stored in shard: {}\", map.determine_shard(hash));Returns a reference to the map’s BuildHasher.
use dashmap::DashMap;\nuse std::collections::hash_map::RandomState;\n\nlet hasher = RandomState::new();\nlet map: DashMap<i32, i32> = DashMap::new();\nlet hasher: &RandomState = map.hasher();Inserts a key and a value into the map. Returns the old value associated with the key if there was one.
\nLocking behaviour: May deadlock if called when holding any sort of reference into the map.
\nuse dashmap::DashMap;\n\nlet map = DashMap::new();\nmap.insert(\"I am the key!\", \"And I am the value!\");Removes an entry from the map, returning the key and value if they existed in the map.
\nLocking behaviour: May deadlock if called when holding any sort of reference into the map.
\nuse dashmap::DashMap;\n\nlet soccer_team = DashMap::new();\nsoccer_team.insert(\"Jack\", \"Goalie\");\nassert_eq!(soccer_team.remove(\"Jack\").unwrap().1, \"Goalie\");Removes an entry from the map, returning the key and value\nif the entry existed and the provided conditional function returned true.
\nLocking behaviour: May deadlock if called when holding any sort of reference into the map.
\n\nuse dashmap::DashMap;\n\nlet soccer_team = DashMap::new();\nsoccer_team.insert(\"Sam\", \"Forward\");\nsoccer_team.remove_if(\"Sam\", |_, position| position == &\"Goalie\");\nassert!(soccer_team.contains_key(\"Sam\"));use dashmap::DashMap;\n\nlet soccer_team = DashMap::new();\nsoccer_team.insert(\"Sam\", \"Forward\");\nsoccer_team.remove_if(\"Sam\", |_, position| position == &\"Forward\");\nassert!(!soccer_team.contains_key(\"Sam\"));Creates an iterator over a DashMap yielding immutable references.
\nLocking behaviour: May deadlock if called when holding a mutable reference into the map.
\nuse dashmap::DashMap;\n\nlet words = DashMap::new();\nwords.insert(\"hello\", \"world\");\nassert_eq!(words.iter().count(), 1);Iterator over a DashMap yielding mutable references.
\nLocking behaviour: May deadlock if called when holding any sort of reference into the map.
\nuse dashmap::DashMap;\n\nlet map = DashMap::new();\nmap.insert(\"Johnny\", 21);\nmap.iter_mut().for_each(|mut r| *r += 1);\nassert_eq!(*map.get(\"Johnny\").unwrap(), 22);Get an immutable reference to an entry in the map
\nLocking behaviour: May deadlock if called when holding a mutable reference into the map.
\nuse dashmap::DashMap;\n\nlet youtubers = DashMap::new();\nyoutubers.insert(\"Bosnian Bill\", 457000);\nassert_eq!(*youtubers.get(\"Bosnian Bill\").unwrap(), 457000);Get a mutable reference to an entry in the map
\nLocking behaviour: May deadlock if called when holding any sort of reference into the map.
\nuse dashmap::DashMap;\n\nlet class = DashMap::new();\nclass.insert(\"Albin\", 15);\n*class.get_mut(\"Albin\").unwrap() -= 1;\nassert_eq!(*class.get(\"Albin\").unwrap(), 14);Get an immutable reference to an entry in the map, if the shard is not locked.\nIf the shard is locked, the function will return [TryResult::Locked].
\nuse dashmap::DashMap;\nuse dashmap::try_result::TryResult;\n\nlet map = DashMap::new();\nmap.insert(\"Johnny\", 21);\n\nassert_eq!(*map.try_get(\"Johnny\").unwrap(), 21);\n\nlet _result1_locking = map.get_mut(\"Johnny\");\n\nlet result2 = map.try_get(\"Johnny\");\nassert!(result2.is_locked());Get a mutable reference to an entry in the map, if the shard is not locked.\nIf the shard is locked, the function will return [TryResult::Locked].
\nuse dashmap::DashMap;\nuse dashmap::try_result::TryResult;\n\nlet map = DashMap::new();\nmap.insert(\"Johnny\", 21);\n\n*map.try_get_mut(\"Johnny\").unwrap() += 1;\nassert_eq!(*map.get(\"Johnny\").unwrap(), 22);\n\nlet _result1_locking = map.get(\"Johnny\");\n\nlet result2 = map.try_get_mut(\"Johnny\");\nassert!(result2.is_locked());Remove excess capacity to reduce memory usage.
\nLocking behaviour: May deadlock if called when holding any sort of reference into the map.
\nuse dashmap::DashMap;\nuse dashmap::try_result::TryResult;\n\nlet map = DashMap::new();\nmap.insert(\"Johnny\", 21);\nassert!(map.capacity() > 0);\nmap.remove(\"Johnny\");\nmap.shrink_to_fit();\nassert_eq!(map.capacity(), 0);Retain elements that whose predicates return true\nand discard elements whose predicates return false.
\nLocking behaviour: May deadlock if called when holding any sort of reference into the map.
\nuse dashmap::DashMap;\n\nlet people = DashMap::new();\npeople.insert(\"Albin\", 15);\npeople.insert(\"Jones\", 22);\npeople.insert(\"Charlie\", 27);\npeople.retain(|_, v| *v > 20);\nassert_eq!(people.len(), 2);Fetches the total number of key-value pairs stored in the map.
\nLocking behaviour: May deadlock if called when holding a mutable reference into the map.
\nuse dashmap::DashMap;\n\nlet people = DashMap::new();\npeople.insert(\"Albin\", 15);\npeople.insert(\"Jones\", 22);\npeople.insert(\"Charlie\", 27);\nassert_eq!(people.len(), 3);Checks if the map is empty or not.
\nLocking behaviour: May deadlock if called when holding a mutable reference into the map.
\nuse dashmap::DashMap;\n\nlet map = DashMap::<(), ()>::new();\nassert!(map.is_empty());Removes all key-value pairs in the map.
\nLocking behaviour: May deadlock if called when holding any sort of reference into the map.
\nuse dashmap::DashMap;\n\nlet stats = DashMap::new();\nstats.insert(\"Goals\", 4);\nassert!(!stats.is_empty());\nstats.clear();\nassert!(stats.is_empty());Returns how many key-value pairs the map can store without reallocating.
\nLocking behaviour: May deadlock if called when holding a mutable reference into the map.
\nModify a specific value according to a function.
\nLocking behaviour: May deadlock if called when holding any sort of reference into the map.
\nuse dashmap::DashMap;\n\nlet stats = DashMap::new();\nstats.insert(\"Goals\", 4);\nstats.alter(\"Goals\", |_, v| v * 2);\nassert_eq!(*stats.get(\"Goals\").unwrap(), 8);If the given closure panics, then alter will abort the process
Modify every value in the map according to a function.
\nLocking behaviour: May deadlock if called when holding any sort of reference into the map.
\nuse dashmap::DashMap;\n\nlet stats = DashMap::new();\nstats.insert(\"Wins\", 4);\nstats.insert(\"Losses\", 2);\nstats.alter_all(|_, v| v + 1);\nassert_eq!(*stats.get(\"Wins\").unwrap(), 5);\nassert_eq!(*stats.get(\"Losses\").unwrap(), 3);If the given closure panics, then alter_all will abort the process
Scoped access into an item of the map according to a function.
\nLocking behaviour: May deadlock if called when holding any sort of reference into the map.
\nuse dashmap::DashMap;\n\nlet warehouse = DashMap::new();\nwarehouse.insert(4267, (\"Banana\", 100));\nwarehouse.insert(2359, (\"Pear\", 120));\nlet fruit = warehouse.view(&4267, |_k, v| *v);\nassert_eq!(fruit, Some((\"Banana\", 100)));If the given closure panics, then view will abort the process
Checks if the map contains a specific key.
\nLocking behaviour: May deadlock if called when holding a mutable reference into the map.
\nuse dashmap::DashMap;\n\nlet team_sizes = DashMap::new();\nteam_sizes.insert(\"Dakota Cherries\", 23);\nassert!(team_sizes.contains_key(\"Dakota Cherries\"));Advanced entry API that tries to mimic std::collections::HashMap.\nSee the documentation on dashmap::mapref::entry for more details.
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
\nAdvanced entry API that tries to mimic std::collections::HashMap.\nSee the documentation on dashmap::mapref::entry for more details.
Returns None if the shard is currently locked.
\nAdvanced entry API that tries to mimic std::collections::HashMap::try_reserve.\nTries to reserve capacity for at least shard * additional\nand may reserve more space to avoid frequent reallocations.
If the capacity overflows, or the allocator reports a failure, then an error is returned.
\nextend_one)extend_one)