SyncHashMapB

Struct SyncHashMapB 

Source
pub struct SyncHashMapB<K, V>
where K: Eq + Hash,
{ /* private fields */ }
Expand description

Bucketed hash map, distributing data to multiple sub-maps to improve concurrency performance 分桶哈希映射,将数据分散到多个子映射中以提高并发性能

Implementations§

Source§

impl<K, V> SyncHashMapB<K, V>
where K: Eq + Hash,

Source

pub fn new(bucket_count: Option<usize>) -> Self

Create a new bucketed hash map 创建新的分桶哈希映射

§Arguments
  • bucket_count - Number of buckets, defaults to 10 if None
  • bucket_count - 分桶数量,如果为None则默认为10
§Examples
use fast_able::map_hash::buckets::SyncHashMapB;

let map = SyncHashMapB::new(None);
map.insert(1, "a");
map.insert(2, "b");
assert_eq!(*map.get(&1).unwrap(), "a");
assert_eq!(*map.get(&2).unwrap(), "b");
assert!(map.get(&3).is_none());
Source

pub fn insert(&self, k: K, v: V) -> Option<V>

Insert a key-value pair 插入键值对

Source

pub fn insert_mut(&mut self, k: K, v: V) -> Option<V>

Insert operation under mutable reference 可变引用下的插入操作

Source

pub fn remove(&self, k: &K) -> Option<V>

Remove a key-value pair 移除键值对

Source

pub fn is_empty(&self) -> bool

Check if empty 检查是否为空

Source

pub fn len(&self) -> usize

Get total length 获取总长度

Source

pub fn clear(&self)

Clear all buckets 清空所有桶

Source

pub fn get(&self, k: &K) -> Option<MapReadGuard<'_, V>>

Get a reference to the value corresponding to the key, protected by read lock (value no lock) 获取键对应的值引用,使用读锁保护 (值无锁)

Returns a ReadGuardNoLock that holds the read lock until the guard is dropped. 返回一个 ReadGuardNoLock,在 guard 被释放前持有读锁。

Source

pub fn get_mut(&self, k: &K) -> Option<WriteGuard<'_, V>>

Get a mutable reference to the value corresponding to the key, protected by write lock 获取键对应的可变值引用,使用写锁保护

Returns a WriteGuard that holds the write lock until the guard is dropped, ensuring concurrent access safety. 返回一个 WriteGuard,在 guard 被释放前持有写锁,保证并发访问安全。

Source

pub fn bucket_count(&self) -> usize

Get the number of buckets 获取桶数量

Source

pub fn keys(&self) -> impl Iterator<Item = &K>

Get an iterator of all keys 获取所有键的迭代器

Source

pub fn get_clone(&self, k: &K) -> Option<V>
where V: Clone,

Get a clone of the value corresponding to the key 获取键对应的值的克隆

Trait Implementations§

Source§

impl<K, V: Clone> Clone for SyncHashMapB<K, V>
where K: Eq + Hash + Clone,

Source§

fn clone(&self) -> SyncHashMapB<K, V>

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K, V: Debug> Debug for SyncHashMapB<K, V>
where K: Eq + Hash + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K, V> Default for SyncHashMapB<K, V>
where K: Eq + Hash,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<K, V> Freeze for SyncHashMapB<K, V>

§

impl<K, V> !RefUnwindSafe for SyncHashMapB<K, V>

§

impl<K, V> Send for SyncHashMapB<K, V>

§

impl<K, V> Sync for SyncHashMapB<K, V>

§

impl<K, V> Unpin for SyncHashMapB<K, V>
where K: Unpin, V: Unpin,

§

impl<K, V> UnwindSafe for SyncHashMapB<K, V>
where K: UnwindSafe, V: UnwindSafe,

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.