### Rust SCC Stack Example Source: https://docs.rs/scc/2.4.0/scc/index Provides an example of using the concurrent lock-free LIFO container 'Stack'. It demonstrates pushing elements onto the stack and popping them in LIFO order. ```Rust use scc::Stack; let stack: Stack = Stack::default(); stack.push(1); stack.push(2); assert_eq!(stack.pop().map(|e| **e), Some(2)); assert_eq!(stack.pop().map(|e| **e), Some(1)); assert!(stack.pop().is_none()); ``` -------------------------------- ### HashIndex entry_async Method Example Source: https://docs.rs/scc/2.4.0/scc/hash_index/struct Shows an example of asynchronously retrieving an entry from a HashIndex for in-place manipulation. This method returns a future that resolves to the entry. ```Rust use scc::HashIndex; let hashindex: HashIndex = HashIndex::default(); let future_entry = hashindex.entry_async('b'); ``` -------------------------------- ### Rust SCC Queue Example Source: https://docs.rs/scc/2.4.0/scc/index Illustrates the functionality of the concurrent lock-free FIFO container 'Queue'. The example shows pushing elements, conditionally pushing elements using a predicate, and popping elements. ```Rust use scc::Queue; let queue: Queue = Queue::default(); queue.push(1); assert!(queue.push_if(2, |e| e.map_or(false, |x| **x == 1)).is_ok()); assert!(queue.push_if(3, |e| e.map_or(false, |x| **x == 1)).is_err()); assert_eq!(queue.pop().map(|e| **e), Some(1)); assert_eq!(queue.pop().map(|e| **e), Some(2)); assert!(queue.pop().is_none()); ``` -------------------------------- ### HashMap Async Entry Source: https://docs.rs/scc/2.4.0/scc/hash_map/struct Provides an example of using the asynchronous `entry_async` method to get an entry from the HashMap. This method returns a future that resolves to the entry. ```Rust use scc::HashMap; let hashmap: HashMap = HashMap::default(); let future_entry = hashmap.entry_async('b'); ``` -------------------------------- ### Example: Using take_inner with Stack in Rust Source: https://docs.rs/scc/2.4.0/scc/struct Provides an example of using the `take_inner` method on an entry popped from a `scc::Stack`. It shows how to safely extract the value stored within the entry. ```Rust use scc::Stack; let stack: Stack = Stack::default(); stack.push(37); let mut entry = stack.pop().unwrap(); let pushed = unsafe { entry.get_mut().unwrap().take_inner() }; assert_eq!(pushed, 37); ``` -------------------------------- ### HashIndex entry Method Example Source: https://docs.rs/scc/2.4.0/scc/hash_index/struct Demonstrates how to use the 'entry' method to get mutable access to a value associated with a key in a HashIndex. It allows modifying existing entries or inserting new ones. ```Rust use scc::HashIndex; let hashindex: HashIndex = HashIndex::default(); for ch in "a short treatise on fungi".chars() { unsafe { hashindex.entry(ch).and_modify(|counter| *counter += 1).or_insert(1); } } assert_eq!(hashindex.peek_with(&'s', |_, v| *v), Some(2)); assert_eq!(hashindex.peek_with(&'t', |_, v| *v), Some(3)); assert!(hashindex.peek_with(&'y', |_, v| *v).is_none()); ``` -------------------------------- ### HashCache: Capacity and basic operations Source: https://docs.rs/scc/2.4.0/scc/index Demonstrates the capacity range and basic put, get, and remove operations for HashCache, a concurrent cache implementation. ```rust use scc::HashCache; let hashcache: HashCache = HashCache::with_capacity(100, 2000); /// The capacity cannot exceed the maximum capacity. assert_eq!(hashcache.capacity_range(), 128..=2048); /// If the bucket corresponding to `1` or `2` is full, the LRU entry will be evicted. assert!(hashcache.put(1, 0).is_ok()); assert!(hashcache.put(2, 0).is_ok()); /// `1` becomes the most recently accessed entry in the bucket. assert!(hashcache.get(&1).is_some()); /// An entry can be normally removed. assert_eq!(hashcache.remove(&2).unwrap(), (2, 0)); ``` -------------------------------- ### Rust SCC Bag Example Source: https://docs.rs/scc/2.4.0/scc/index Demonstrates the basic usage of the concurrent lock-free unordered container 'Bag'. It shows how to create a Bag, push elements, check if it's empty, and pop elements. ```Rust use scc::Bag; let bag: Bag = Bag::default(); bag.push(1); assert!(!bag.is_empty()); assert_eq!(bag.pop(), Some(1)); assert!(bag.is_empty()); ``` -------------------------------- ### Get Capacity of HashSet (Rust) Source: https://docs.rs/scc/2.4.0/scc/hash_set/struct Demonstrates how to retrieve the current capacity of a HashSet. It shows examples for default, inserted, and pre-allocated capacities. ```Rust use scc::HashSet; let hashset_default: HashSet = HashSet::default(); assert_eq!(hashset_default.capacity(), 0); assert!(hashset_default.insert(1).is_ok()); assert_eq!(hashset_default.capacity(), 64); let hashset: HashSet = HashSet::with_capacity(1000); assert_eq!(hashset.capacity(), 1024); ``` -------------------------------- ### Get First Entry Asynchronously Source: https://docs.rs/scc/2.4.0/scc/hash_index/struct Provides an example of asynchronously retrieving the first occupied entry from a HashIndex. This is useful in async contexts for in-place manipulation. ```rust use scc::HashIndex; let hashindex: HashIndex = HashIndex::default(); let future_entry = hashindex.first_entry_async(); ``` -------------------------------- ### HashIndex reserve Method Example Source: https://docs.rs/scc/2.4.0/scc/hash_index/struct Illustrates the usage of the 'reserve' method to increase the capacity of a HashIndex. It demonstrates successful reservations, failure with excessive capacity requests, and the effect of dropping the Reserve guard. ```Rust use scc::HashIndex; let hashindex: HashIndex = HashIndex::with_capacity(1000); assert_eq!(hashindex.capacity(), 1024); let reserved = hashindex.reserve(10000); assert!(reserved.is_some()); assert_eq!(hashindex.capacity(), 16384); assert!(hashindex.reserve(usize::MAX).is_none()); assert_eq!(hashindex.capacity(), 16384); for i in 0..16 { assert!(hashindex.insert(i, i).is_ok()); } drop(reserved); assert_eq!(hashindex.capacity(), 1024); ``` -------------------------------- ### Find Entry Asynchronously by Predicate Source: https://docs.rs/scc/2.4.0/scc/hash_index/struct Shows an example of asynchronously finding an entry in a HashIndex based on a predicate, suitable for async operations. ```rust use scc::HashIndex; let hashindex: HashIndex = HashIndex::default(); let future_entry = hashindex.any_entry_async(|k, _| *k == 2); ``` -------------------------------- ### Rust SCC HashIndex Capacity Retrieval Source: https://docs.rs/scc/2.4.0/scc/hash_index/struct Shows how to retrieve the current capacity of the `HashIndex`. Examples include the default capacity and capacity after insertion or explicit reservation. ```Rust use scc::HashIndex; let hashindex_default: HashIndex = HashIndex::default(); assert_eq!(hashindex_default.capacity(), 0); assert!(hashindex_default.insert(1, 0).is_ok()); assert_eq!(hashindex_default.capacity(), 64); let hashindex: HashIndex = HashIndex::with_capacity(1000); assert_eq!(hashindex.capacity(), 1024); ``` -------------------------------- ### HashMap Entry Manipulation Source: https://docs.rs/scc/2.4.0/scc/hash_map/struct Illustrates how to use the `entry` method to get or insert values into a HashMap. It shows how to modify existing entries or insert new ones based on the key's presence. ```Rust use scc::HashMap; let hashmap: HashMap = HashMap::default(); for ch in "a short treatise on fungi".chars() { hashmap.entry(ch).and_modify(|counter| *counter += 1).or_insert(1); } assert_eq!(hashmap.read(&'s', |_, v| *v), Some(2)); assert_eq!(hashmap.read(&'t', |_, v| *v), Some(3)); assert!(hashmap.read(&'y', |_, v| *v).is_none()); ``` -------------------------------- ### Get and Mutate First Entry in HashIndex Source: https://docs.rs/scc/2.4.0/scc/hash_index/struct Shows how to get the first occupied entry from a HashIndex, mutate its value, and then check for the next entry. This illustrates in-place manipulation. ```rust use scc::HashIndex; let hashindex: HashIndex = HashIndex::default(); assert!(hashindex.insert(1, 0).is_ok()); let mut first_entry = hashindex.first_entry().unwrap(); unsafe { *first_entry.get_mut() = 2; } assert!(first_entry.next().is_none()); assert_eq!(hashindex.peek_with(&1, |_, v| *v), Some(2)); ``` -------------------------------- ### SCC HashIndex: Get Entry for Modification Source: https://docs.rs/scc/2.4.0/scc/hash_index/struct Illustrates how to retrieve an `OccupiedEntry` for in-place modification using the `get` method. This provides exclusive access to the entry. It also shows basic insertion and retrieval. ```rust use scc::HashIndex; let hashindex: HashIndex = HashIndex::default(); assert!(hashindex.get(&1).is_none()); assert!(hashindex.insert(1, 10).is_ok()); assert_eq!(*hashindex.get(&1).unwrap().get(), 10); assert_eq!(*hashindex.get(&1).unwrap(), 10); ``` -------------------------------- ### SCC HashMap first_entry Source: https://docs.rs/scc/2.4.0/scc/hash_map/struct Demonstrates how to get the first occupied entry in the HashMap for in-place manipulation. It shows how to retrieve an entry, modify its value, and then check for the next entry. ```rust use scc::HashMap; let hashmap: HashMap = HashMap::default(); assert!(hashmap.insert(1, 0).is_ok()); let mut first_entry = hashmap.first_entry().unwrap(); *first_entry.get_mut() = 2; assert!(first_entry.next().is_none()); assert_eq!(hashmap.read(&1, |_, v| *v), Some(2)); ``` -------------------------------- ### Rust SCC HashIndex Emptiness Check Source: https://docs.rs/scc/2.4.0/scc/hash_index/struct Provides an example of checking if the `HashIndex` is empty. This is a common operation to determine if any data has been added. ```Rust use scc::HashIndex; let hashindex: HashIndex = HashIndex::default(); assert!(hashindex.is_empty()); assert!(hashindex.insert(1, 0).is_ok()); assert!(!hashindex.is_empty()); ``` -------------------------------- ### SCC HashIndex: Async Get Entry Source: https://docs.rs/scc/2.4.0/scc/hash_index/struct Demonstrates retrieving an `OccupiedEntry` asynchronously for in-place modification using `get_async`. This method returns a future that resolves to the entry if found. ```rust use scc::HashIndex; let hashindex: HashIndex = HashIndex::default(); let future_insert = hashindex.insert_async(11, 17); let future_get = hashindex.get_async(&11); ``` -------------------------------- ### SCC HashMap Basic Operations Source: https://docs.rs/scc/2.4.0/scc/hash_map/struct Demonstrates basic HashMap operations like default creation and insertion. It shows how to insert a key-value pair and check if the insertion was successful. It also shows how to check for the existence of an entry. ```rust use scc::HashMap; let hashmap: HashMap = HashMap::default(); assert!(hashmap.insert(0, 1).is_ok()); assert!(hashmap.try_entry(0).is_some()); ``` -------------------------------- ### Get TypeId of Self (Rust) Source: https://docs.rs/scc/2.4.0/scc/queue/struct Gets the `TypeId` of the current type instance. ```Rust fn type_id(&self) -> TypeId ``` -------------------------------- ### HashIndex: Entry API for updates Source: https://docs.rs/scc/2.4.0/scc/index Illustrates how to use the Entry API of HashIndex to update existing entries, including creating new versions and in-place modifications. ```rust use scc::HashIndex; let hashindex: HashIndex = HashIndex::default(); assert!(hashindex.insert(1, 1).is_ok()); if let Some(mut o) = hashindex.get(&1) { // Create a new version of the entry. o.update(2); }; if let Some(mut o) = hashindex.get(&1) { // Update the entry in place. unsafe { *o.get_mut() = 3; } }; ``` -------------------------------- ### Get Capacity Range of HashSet (Rust) Source: https://docs.rs/scc/2.4.0/scc/hash_set/struct Illustrates how to get the capacity range of a HashSet. It shows the initial range and the range after reserving capacity. ```Rust use scc::HashSet; let hashset: HashSet = HashSet::default(); assert_eq!(hashset.capacity_range(), 0..=(1_usize << (usize::BITS - 1))); let reserved = hashset.reserve(1000); assert_eq!(hashset.capacity_range(), 1000..=(1_usize << (usize::BITS - 1))); ``` -------------------------------- ### Get Length of HashSet (Rust) Source: https://docs.rs/scc/2.4.0/scc/hash_set/struct Illustrates how to get the number of elements in a HashSet using the `len` method. Note that this operation has O(N) complexity. ```Rust use scc::HashSet; let hashset: HashSet = HashSet::default(); assert!(hashset.insert(1).is_ok()); assert_eq!(hashset.len(), 1); ``` -------------------------------- ### Initialize and Insert into HashIndex Source: https://docs.rs/scc/2.4.0/scc/hash_index/struct Demonstrates the basic initialization of a HashIndex and inserting a key-value pair. It checks if the insertion was successful and if an entry can be retrieved. ```rust use scc::HashIndex; let hashindex: HashIndex = HashIndex::default(); assert!(hashindex.insert(0, 1).is_ok()); assert!(hashindex.try_entry(0).is_some()); ``` -------------------------------- ### HashIndex: Lock-free peek and async operations Source: https://docs.rs/scc/2.4.0/scc/index Demonstrates the lock-free `peek` and `peek_with` methods of HashIndex, along with asynchronous insert and remove operations. ```rust use scc::HashIndex; let hashindex: HashIndex = HashIndex::default(); assert!(hashindex.insert(1, 0).is_ok()); // `peek` and `peek_with` are lock-free. assert_eq!(hashindex.peek_with(&1, |_, v| *v).unwrap(), 0); let future_insert = hashindex.insert_async(2, 1); let future_remove = hashindex.remove_if_async(&1, |_| true); ``` -------------------------------- ### SCC HashMap any_entry Source: https://docs.rs/scc/2.4.0/scc/hash_map/struct Demonstrates finding an entry that satisfies a given predicate for in-place manipulation. It shows how to insert multiple entries and then retrieve and assert the value of an entry matching the predicate. ```rust use scc::HashMap; let hashmap: HashMap = HashMap::default(); assert!(hashmap.insert(1, 0).is_ok()); assert!(hashmap.insert(2, 3).is_ok()); let mut entry = hashmap.any_entry(|k, _| *k == 2).unwrap(); assert_eq!(*entry.get(), 3); ``` -------------------------------- ### Utilize scc::HashMap Entry API for complex workflows in Rust Source: https://docs.rs/scc/2.4.0/scc/index Illustrates the usage of the `Entry` API of `scc::HashMap` for more complex workflows. It demonstrates how to use `or_insert` and `and_modify` methods to conditionally insert or modify entries in the hash map. ```Rust use scc::HashMap; let hashmap: HashMap = HashMap::default(); hashmap.entry(3).or_insert(7); assert_eq!(hashmap.read(&3, |_, v| *v), Some(7)); hashmap.entry(4).and_modify(|v| { *v += 1 }).or_insert(5); assert_eq!(hashmap.read(&4, |_, v| *v), Some(5)); ``` -------------------------------- ### HashSet Struct Documentation Source: https://docs.rs/scc/2.4.0/scc/hash_set/index Documentation for the HashSet struct, which is a scalable concurrent hash set. It details its purpose and usage within the scc crate. ```Rust HashSet Scalable concurrent hash set. ``` -------------------------------- ### Get TypeId of Self Source: https://docs.rs/scc/2.4.0/scc/bag/struct Retrieves the `TypeId` of the current type. This is a fundamental method for runtime type identification. ```Rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Get HashMap Capacity (Rust) Source: https://docs.rs/scc/2.4.0/scc/hash_map/struct Returns the current capacity of the HashMap. The capacity represents the number of buckets available. ```rust use scc::HashMap; let hashmap_default: HashMap = HashMap::default(); assert_eq!(hashmap_default.capacity(), 0); assert!(hashmap_default.insert(1, 0).is_ok()); assert_eq!(hashmap_default.capacity(), 64); let hashmap: HashMap = HashMap::with_capacity(1000); assert_eq!(hashmap.capacity(), 1024); ``` -------------------------------- ### Create Default HashSet Source: https://docs.rs/scc/2.4.0/scc/hash_set/struct Illustrates the creation of a HashSet using the default constructor, which has a default capacity of 64. ```Rust use scc::HashSet; let hashset: HashSet = HashSet::default(); let result = hashset.capacity(); assert_eq!(result, 0); ``` -------------------------------- ### Rust: Get TypeId of an entry Source: https://docs.rs/scc/2.4.0/scc/struct Obtains the `TypeId` of the current instance. This is a common method for runtime type identification. ```Rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Create New HashSet (Rust) Source: https://docs.rs/scc/2.4.0/scc/hash_set/struct Demonstrates the creation of a new, empty HashSet with default parameters using the `new` function. ```Rust use scc::HashSet; let hashset: HashSet = HashSet::new(); ``` -------------------------------- ### SCC Crate Features Source: https://docs.rs/scc/2.4.0/scc/index This snippet outlines the features supported by the scc crate, including asynchronous counterparts, support for Equivalent, Loom, and Serde, and SIMD lookup capabilities. SIMD lookup requires specific RUSTFLAGS. ```Rust features = ["equivalent", "loom", "serde"] RUSTFLAGS='-C target_feature=+avx2' ``` -------------------------------- ### Get Reference to Entry Key Source: https://docs.rs/scc/2.4.0/scc/hash_index/enum Retrieves an immutable reference to the key associated with this `HashIndex` entry. ```Rust pub fn key(&self) -> &K ``` -------------------------------- ### Rust SCC HashIndex Default Initialization and Async Operations Source: https://docs.rs/scc/2.4.0/scc/hash_index/struct Demonstrates the default initialization of a `HashIndex` and performing asynchronous insert and retain operations. This is useful for understanding non-blocking data manipulation. ```Rust use scc::HashIndex; let hashindex: HashIndex = HashIndex::default(); let future_insert = hashindex.insert_async(1, 0); let future_retain = hashindex.retain_async(|k, v| *k == 1); ``` -------------------------------- ### Get Reference to Entry Key Source: https://docs.rs/scc/2.4.0/scc/hash_map/enum The `key` method returns an immutable reference to the key associated with this `Entry`. ```Rust pub fn key(&self) -> &K ``` -------------------------------- ### Use scc::HashMap for concurrent data storage in Rust Source: https://docs.rs/scc/2.4.0/scc/index Demonstrates basic operations on scc::HashMap, including inserting, updating, reading, and removing entries synchronously and asynchronously. It showcases the use of `insert`, `upsert`, `update`, `read`, `remove`, `insert_async`, and `remove_async` methods. ```Rust use scc::HashMap; let hashmap: HashMap = HashMap::default(); assert!(hashmap.insert(1, 0).is_ok()); assert!(hashmap.insert(1, 1).is_err()); assert_eq!(hashmap.upsert(1, 1).unwrap(), 0); assert_eq!(hashmap.update(&1, |_, v| { *v = 3; *v }).unwrap(), 3); assert_eq!(hashmap.read(&1, |_, v| *v).unwrap(), 3); assert_eq!(hashmap.remove(&1).unwrap(), (1, 3)); hashmap.entry(7).or_insert(17); assert_eq!(hashmap.read(&7, |_, v| *v).unwrap(), 17); let future_insert = hashmap.insert_async(2, 1); let future_remove = hashmap.remove_async(&1); ``` -------------------------------- ### Get HashMap Capacity Range (Rust) Source: https://docs.rs/scc/2.4.0/scc/hash_map/struct Returns the current capacity range of the HashMap. This indicates the minimum and maximum number of buckets. ```rust use scc::HashMap; let hashmap: HashMap = HashMap::default(); assert_eq!(hashmap.capacity_range(), 0..=(1_usize << (usize::BITS - 1))); let reserved = hashmap.reserve(1000); assert_eq!(hashmap.capacity_range(), 1000..=(1_usize << (usize::BITS - 1))); ``` -------------------------------- ### Create HashSet Source: https://docs.rs/scc/2.4.0/scc/hash_set/struct Demonstrates the creation of an empty HashSet with a capacity of 0. ```Rust use scc::HashSet; let hashset: HashSet = HashSet::new(); let result = hashset.capacity(); assert_eq!(result, 0); ``` -------------------------------- ### Get HashMap Length (Rust) Source: https://docs.rs/scc/2.4.0/scc/hash_map/struct Returns the number of entries in the HashMap. Note that this operation has a time complexity of O(N) as it iterates through the bucket array. ```rust use scc::HashMap; let hashmap: HashMap = HashMap::default(); assert!(hashmap.insert(1, 0).is_ok()); assert_eq!(hashmap.len(), 1); ``` -------------------------------- ### Get Type ID of a Trait Object (Rust) Source: https://docs.rs/scc/2.4.0/scc/stack/struct Retrieves the `TypeId` of the concrete type underlying a trait object. This is part of the `Any` trait implementation. ```Rust fn type_id(&self) -> TypeId where T: 'static + ?Sized, ``` -------------------------------- ### Create HashSet with Capacity Source: https://docs.rs/scc/2.4.0/scc/hash_set/struct Shows how to create a HashSet with a specified initial capacity. The actual capacity may be greater than the specified value. ```Rust use scc::HashSet; let hashset: HashSet = HashSet::with_capacity(1000); let result = hashset.capacity(); assert_eq!(result, 1024); ``` -------------------------------- ### TreeIndex: Insert, peek, remove, and async operations Source: https://docs.rs/scc/2.4.0/scc/index Shows basic operations for TreeIndex, including inserting, peeking with a predicate, removing, and performing asynchronous insert and conditional remove operations. ```rust use scc::TreeIndex; let treeindex: TreeIndex = TreeIndex::new(); assert!(treeindex.insert(1, 2).is_ok()); // `peek` and `peek_with` are lock-free. assert_eq!(treeindex.peek_with(&1, |_, v| *v).unwrap(), 2); assert!(treeindex.remove(&1)); let future_insert = treeindex.insert_async(2, 3); let future_remove = treeindex.remove_if_async(&1, |v| *v == 2); ``` -------------------------------- ### Rust: Get owned version of data Source: https://docs.rs/scc/2.4.0/scc/struct Creates owned data from borrowed data, typically by cloning. This is the primary method for the `ToOwned` trait. ```Rust fn to_owned(&self) -> T ``` -------------------------------- ### Use scc::HashSet for concurrent set operations in Rust Source: https://docs.rs/scc/2.4.0/scc/index Demonstrates basic operations on `scc::HashSet`, including inserting, reading, and removing elements synchronously and asynchronously. It showcases the use of `insert`, `read`, `insert_async`, and `remove_async` methods. ```Rust use scc::HashSet; let hashset: HashSet = HashSet::default(); assert!(hashset.read(&1, |_| true).is_none()); assert!(hashset.insert(1).is_ok()); assert!(hashset.read(&1, |_| true).unwrap()); let future_insert = hashset.insert_async(2); let future_remove = hashset.remove_async(&1); ``` -------------------------------- ### Get HashMap Bucket Index (Rust) Source: https://docs.rs/scc/2.4.0/scc/hash_map/struct Returns the index of the bucket that may contain the given key. The number of buckets is determined by dividing the capacity by 32. ```rust use scc::HashMap; let hashmap: HashMap = HashMap::with_capacity(1024); let bucket_index = hashmap.bucket_index(&11); assert!(bucket_index < hashmap.capacity() / 32); ``` -------------------------------- ### Rust SCC HashIndex Capacity Range Source: https://docs.rs/scc/2.4.0/scc/hash_index/struct Demonstrates how to get the inclusive range of the current capacity of the `HashIndex`. This is useful for understanding the bounds of the index's storage. ```Rust use scc::HashIndex; let hashindex: HashIndex = HashIndex::default(); assert_eq!(hashindex.capacity_range(), 0..=(1_usize << (usize::BITS - 1))); let reserved = hashindex.reserve(1000); assert_eq!(hashindex.capacity_range(), 1000..=(1_usize << (usize::BITS - 1))); ``` -------------------------------- ### SCC HashMap any_entry_async Source: https://docs.rs/scc/2.4.0/scc/hash_map/struct Demonstrates the asynchronous search for an entry satisfying a predicate. This method returns a Future that resolves to an Option containing the entry for in-place manipulation. ```rust use scc::HashMap; let hashmap: HashMap = HashMap::default(); let future_entry = hashmap.any_entry_async(|k, _| *k == 2); ``` -------------------------------- ### Rust: From Method Source: https://docs.rs/scc/2.4.0/scc/hash_index/struct Demonstrates the `from` method, which returns the argument unchanged in Rust. This is part of the `From for T` implementation. ```Rust fn from(t: T) -> T ``` -------------------------------- ### Rust Debug Implementation for VacantEntry Source: https://docs.rs/scc/2.4.0/scc/hash_cache/struct Provides a Debug implementation for VacantEntry, allowing it to be formatted for debugging purposes. This requires the key and value types to also implement Debug. ```Rust impl Debug for VacantEntry<'_, K, V, H> where K: Debug + Eq + Hash, V: Debug, H: BuildHasher, { fn fmt(&self, f: &mut Formatter<'_>) -> Result } ``` -------------------------------- ### TreeIndex: Lock-free iteration Source: https://docs.rs/scc/2.4.0/scc/index Demonstrates how to iterate over entries in a TreeIndex without acquiring locks, using an sdd::Guard for memory safety. ```rust use scc::TreeIndex; use sdd::Guard; let treeindex: TreeIndex = TreeIndex::new(); assert!(treeindex.insert(1, 10).is_ok()); assert!(treeindex.insert(2, 11).is_ok()); assert!(treeindex.insert(3, 13).is_ok()); let guard = Guard::new(); // `iter` iterates over entries without acquiring a lock. let mut iter = treeindex.iter(&guard); assert_eq!(iter.next().unwrap(), (&1, &10)); assert_eq!(iter.next().unwrap(), (&2, &11)); assert_eq!(iter.next().unwrap(), (&3, &13)); assert!(iter.next().is_none()); ``` -------------------------------- ### Rust SCC HashIndex Length Calculation Source: https://docs.rs/scc/2.4.0/scc/hash_index/struct Demonstrates how to get the number of entries currently stored in the `HashIndex`. Note that this operation has a time complexity of O(N) and might overcount during resizing. ```Rust use scc::HashIndex; let hashindex: HashIndex = HashIndex::default(); assert!(hashindex.insert(1, 0).is_ok()); assert_eq!(hashindex.len(), 1); ``` -------------------------------- ### Rust: Get next shared entry Source: https://docs.rs/scc/2.4.0/scc/struct Retrieves a `Shared` handle to the closest next valid entry in the SCC data structure. This function is part of the `Entry` struct's methods. ```Rust fn next_shared(&self, order: Ordering, guard: &Guard) -> Option> ``` -------------------------------- ### TreeIndex: Range scanning with EBR Guard Source: https://docs.rs/scc/2.4.0/scc/index Illustrates scanning a specific range of keys in a TreeIndex using an EBR Guard for safe, lock-free access. ```rust use scc::ebr::Guard; use scc::TreeIndex; let treeindex: TreeIndex = TreeIndex::new(); for i in 0..10 { assert!(treeindex.insert(i, 10).is_ok()); } let guard = Guard::new(); assert_eq!(treeindex.range(1..1, &guard).count(), 0); assert_eq!(treeindex.range(4..8, &guard).count(), 4); assert_eq!(treeindex.range(4..=8, &guard).count(), 5); ``` -------------------------------- ### Implement LinkedList for Entry in Rust Source: https://docs.rs/scc/2.4.0/scc/struct Covers the `LinkedList` trait implementation for `Entry`, providing methods for managing linked list operations like getting links, marking, and deleting entries. ```Rust fn link_ref(&self) -> &AtomicShared ``` ```Rust fn is_clear(&self, order: Ordering) -> bool ``` ```Rust fn mark(&self, order: Ordering) -> bool ``` ```Rust fn unmark(&self, order: Ordering) -> bool ``` ```Rust fn is_marked(&self, order: Ordering) -> bool ``` ```Rust fn delete_self(&self, order: Ordering) -> bool ``` ```Rust fn is_deleted(&self, order: Ordering) -> bool ``` ```Rust fn push_back<'g>( &self, entry: Shared, mark: bool, order: Ordering, guard: &'g Guard, ) -> Result, Shared> ``` ```Rust fn next_ptr<'g>(&self, order: Ordering, guard: &'g Guard) -> Ptr<'g, Self> ``` -------------------------------- ### Get SCC HashMap Entry for In-place Modification Synchronously Source: https://docs.rs/scc/2.4.0/scc/hash_map/struct Retrieves an `OccupiedEntry` for a given key, allowing in-place modification. Returns `None` if the key does not exist. `OccupiedEntry` provides exclusive access. ```rust use scc::HashMap; let hashmap: HashMap = HashMap::default(); assert!(hashmap.get(&1).is_none()); assert!(hashmap.insert(1, 10).is_ok()); assert_eq!(*hashmap.get(&1).unwrap().get(), 10); *hashmap.get(&1).unwrap() = 11; assert_eq!(*hashmap.get(&1).unwrap(), 11); ``` -------------------------------- ### Create Instance from Value (Rust) Source: https://docs.rs/scc/2.4.0/scc/queue/struct Returns the argument unchanged, used for creating an instance from itself. ```Rust fn from(t: T) -> T ``` -------------------------------- ### Standard Iterator Adapters Source: https://docs.rs/scc/2.4.0/scc/queue/struct Showcases common iterator adapters that can be applied to the `Iter` struct, including `size_hint`, `count`, `last`, `nth`, `step_by`, `chain`, `zip`, `intersperse`, `intersperse_with`, `map`, `for_each`, `filter`, and `filter_map`. These adapters allow for flexible data processing. ```Rust fn size_hint(&self) -> (usize, Option) fn count(self) -> usize where Self: Sized, fn last(self) -> Option where Self: Sized, fn nth(&mut self, n: usize) -> Option fn step_by(self, step: usize) -> StepBy where Self: Sized, fn chain(self, other: U) -> Chain::IntoIter> where Self: Sized, U: IntoIterator, fn zip(self, other: U) -> Zip::IntoIter> where Self: Sized, U: IntoIterator, fn intersperse(self, separator: Self::Item) -> Intersperse where Self: Sized, Self::Item: Clone, fn intersperse_with(self, separator: G) -> IntersperseWith where Self: Sized, G: FnMut() -> Self::Item, fn map(self, f: F) -> Map where Self: Sized, F: FnMut(Self::Item) -> B, fn for_each(self, f: F) where Self: Sized, F: FnMut(Self::Item), fn filter

(self, predicate: P) -> Filter where Self: Sized, P: FnMut(&Self::Item) -> bool, fn filter_map(self, f: F) -> FilterMap where Self: Sized, F: FnMut(Self::Item) -> Option, ``` -------------------------------- ### Rust VacantEntry::key() - Get Reference to Key Source: https://docs.rs/scc/2.4.0/scc/hash_cache/struct Retrieves an immutable reference to the key associated with the vacant entry. This method is useful for inspecting the key without consuming the entry. ```Rust use scc::HashCache; let hashcache: HashCache = HashCache::default(); assert_eq!(hashcache.entry(11).key(), &11); ``` -------------------------------- ### Create HashSet with Capacity and Hasher Source: https://docs.rs/scc/2.4.0/scc/hash_set/struct Creates an empty HashSet with a specified initial capacity and a BuildHasher. The actual capacity will be equal to or greater than the specified value. ```Rust use scc::HashSet; use std::collections::hash_map::RandomState; let hashset: HashSet = HashSet::with_capacity_and_hasher(1000, RandomState::new()); let result = hashset.capacity(); assert_eq!(result, 1024); ``` -------------------------------- ### Implement Sync for Entry in Rust Source: https://docs.rs/scc/2.4.0/scc/hash_cache/enum This snippet shows the implementation of the `Sync` trait for the `Entry` struct. The key `K` must be `Sync` and `Send`, and the value `V` must be `Sync` and `Send`. The `BuildHasher` `H` must also be `Sync`. ```Rust impl<'h, K, V, H> Sync for Entry<'h, K, V, H> where K: Sync + Send, H: Sync, V: Sync + Send ``` -------------------------------- ### Get Additional Capacity in Rust Source: https://docs.rs/scc/2.4.0/scc/hash_set/type This Rust function, `additional_capacity`, is part of the `Reserve` implementation. It returns the number of reserved slots, indicating how much extra capacity is being maintained. ```Rust pub fn additional_capacity(&self) -> usize ``` -------------------------------- ### Implement Clone for Entry in Rust Source: https://docs.rs/scc/2.4.0/scc/struct Illustrates the `Clone` trait implementation for `Entry`, enabling the creation of duplicate entries. It includes both `clone` and `clone_from` methods. ```Rust fn clone(&self) -> Self ``` ```Rust fn clone_from(&mut self, source: &Self) ``` -------------------------------- ### Get SCC HashMap Entry for In-place Modification Asynchronously Source: https://docs.rs/scc/2.4.0/scc/hash_map/struct Retrieves an `OccupiedEntry` for a given key asynchronously, allowing in-place modification. Returns `None` if the key does not exist. This method returns an `impl Future`. ```rust use scc::HashMap; let hashmap: HashMap = HashMap::default(); let future_insert = hashmap.insert_async(11, 17); let future_get = hashmap.get_async(&11); ``` -------------------------------- ### HashMap Reserve Functionality Source: https://docs.rs/scc/2.4.0/scc/hash_map/struct Demonstrates how to temporarily increase the minimum capacity of a HashMap using the `reserve` method. It shows how to handle successful reservations and cases where a too-large number is provided, as well as the effect of dropping the `Reserve` guard. ```Rust use scc::HashMap; let hashmap: HashMap = HashMap::with_capacity(1000); assert_eq!(hashmap.capacity(), 1024); let reserved = hashmap.reserve(10000); assert!(reserved.is_some()); assert_eq!(hashmap.capacity(), 16384); assert!(hashmap.reserve(usize::MAX).is_none()); assert_eq!(hashmap.capacity(), 16384); for i in 0..16 { assert!(hashmap.insert(i, i).is_ok()); } drop(reserved); assert_eq!(hashmap.capacity(), 1024); ``` -------------------------------- ### Get Bucket Index for Key in HashSet (Rust) Source: https://docs.rs/scc/2.4.0/scc/hash_set/struct Shows how to find the bucket index for a given key in a HashSet. The index is calculated based on the key's hash and the HashSet's capacity. ```Rust use scc::HashSet; let hashset: HashSet = HashSet::with_capacity(1024); let bucket_index = hashset.bucket_index(&11); assert!(bucket_index < hashset.capacity() / 32); ``` -------------------------------- ### Implement Send for Entry in Rust Source: https://docs.rs/scc/2.4.0/scc/hash_cache/enum This code illustrates the implementation of the `Send` trait for the `Entry` struct. The key `K` must be `Send`, `Eq`, `Hash`, and `Sync`. The value `V` must be `Send` and `Sync`, and the `BuildHasher` `H` must be `Sync`. ```Rust impl<'h, K, V, H> Send for Entry<'h, K, V, H> where K: Send + Eq + Hash + Sync, V: Send + Sync, H: Sync ``` -------------------------------- ### SCC HashMap first_entry_async Source: https://docs.rs/scc/2.4.0/scc/hash_map/struct Demonstrates the asynchronous retrieval of the first occupied entry in the HashMap. This method returns a Future that resolves to an Option containing the entry for in-place manipulation. ```rust use scc::HashMap; let hashmap: HashMap = HashMap::default(); let future_entry = hashmap.first_entry_async(); ``` -------------------------------- ### Rust VacantEntry::put_entry() - Insert Value and Get OccupiedEntry Source: https://docs.rs/scc/2.4.0/scc/hash_cache/struct Inserts a value into the vacant entry using its associated key. It returns an OccupiedEntry and potentially an EvictedEntry if a previous entry was removed to make space. ```Rust use scc::HashCache; use scc::hash_cache::Entry; let hashcache: HashCache = HashCache::default(); if let Entry::Vacant(o) = hashcache.entry(19) { o.put_entry(29); } assert_eq!(*hashcache.get(&19).unwrap().get(), 29); ``` -------------------------------- ### Implement Debug for Entry in Rust Source: https://docs.rs/scc/2.4.0/scc/hash_index/enum This snippet shows the implementation of the `Debug` trait for the `Entry` type in Rust. It requires the key `K` and value `V` to be `Clone`, `Debug`, and have a `'static` lifetime, and the hasher `H` to implement `BuildHasher`. The `fmt` function is used to format the entry for debugging. ```Rust impl Debug for Entry<'_, K, V, H> where K: 'static + Clone + Debug + Eq + Hash, V: 'static + Clone + Debug, H: BuildHasher ``` -------------------------------- ### Implement TryInto for T in Rust Source: https://docs.rs/scc/2.4.0/scc/hash_cache/enum This code shows the blanket implementation of `TryInto` for `T`, provided that `U` implements `TryFrom`. It defines the `Error` type based on `U`'s `TryFrom` error and provides a `try_into` method. ```Rust impl where U: TryFrom TryInto for T { type Error = >::Error; fn try_into(self) -> Result>::Error> } ``` -------------------------------- ### OccupiedEntry Struct Documentation Source: https://docs.rs/scc/2.4.0/scc/hash_index/index Documentation for the OccupiedEntry struct, representing a view into an occupied entry within a HashIndex. It allows interaction with existing key-value pairs. ```Rust /// `OccupiedEntry` is a view into an occupied entry in a `HashIndex`. pub struct OccupiedEntry ``` -------------------------------- ### Reserve Struct Documentation Source: https://docs.rs/scc/2.4.0/scc/hash_index/index Documentation for the Reserve struct, used to maintain a minimum capacity for a HashIndex. It ensures that the hash index's capacity stays above a specified threshold. ```Rust /// `Reserve` keeps the capacity of the associated `HashIndex` higher than a certain level. pub struct Reserve ``` -------------------------------- ### SCC HashIndex: Read-Optimized Concurrent Hash Map Source: https://docs.rs/scc/2.4.0/scc/index The scc::HashIndex is a concurrent and asynchronous hash map optimized for read operations. It offers efficient data retrieval in scenarios with a high volume of reads compared to writes. ```Rust use scc::HashIndex; // Example usage (conceptual): let mut index: HashIndex = HashIndex::new(); index.insert("data_key", 123); let data = index.get("data_key"); ``` -------------------------------- ### SCC HashMap insert Source: https://docs.rs/scc/2.4.0/scc/hash_map/struct Demonstrates inserting a key-value pair into the HashMap and handling potential errors. It shows a successful insertion and an attempt to insert a key that already exists, which returns an error. ```rust use scc::HashMap; let hashmap: HashMap = HashMap::default(); assert!(hashmap.insert(1, 0).is_ok()); assert_eq!(hashmap.insert(1, 1).unwrap_err(), (1, 1)); ```