Struct SeqMap

Source
pub struct SeqMap<K: Hash + PartialEq + Eq + Copy + Clone + Send + Sync + 'static, V: Copy + Clone + Send + Sync + 'static, H: Hasher + Default = DefaultHasher> { /* private fields */ }
Expand description

A concurrent, lock-free hash map implementation that can sustain rapid expansion and high contention on every key, while allowing for concurrent reads and writes.

Based on the interior mutability provided by SeqArray, this map uses open addressing with linear probing to provide a highly concurrent map interface, and can be safely shared and passed between threads. without issue.

use seqmap::SeqMap;

let map = SeqMap::<u64, u8>::new();

map.insert(1, 42);
map.insert(2, 43);

std::thread::scope(|s| {
   s.spawn(|| {
       assert_eq!(map.get(1), Some(42));
       map.insert(3, 100);
   });
   s.spawn(|| {
      assert_eq!(map.get(2), Some(43));
      map.insert(4, 101);
   });
});

assert_eq!(map.get(1), Some(42));
assert_eq!(map.get(2), Some(43));
assert_eq!(map.get(3), Some(100));
assert_eq!(map.get(4), Some(101));

Implementations§

Source§

impl<K: Hash + PartialEq + Eq + Copy + Clone + Send + Sync + 'static, V: Copy + Clone + Send + Sync + 'static, H: Hasher + Default> SeqMap<K, V, H>

Source

pub fn new() -> Self

Creates a new SeqMap with an initial capacity of 10.

Source

pub fn with_capacity(size: usize) -> Self

Creates a new SeqMap with the specified initial capacity.

Source

pub fn insert(&self, key: K, value: V)
where K: Debug, V: Debug + PartialEq,

Inserts a key-value pair into the map, resizing if necessary.

If a resize or snapshot (i.e. Clone) is already in progress, it will block until the resize or snapshot is complete.

Source

pub fn get(&self, key: K) -> Option<V>

Retrieves a value by key from the map.

If a resize is in progress, it will block until the resize is complete.

Trait Implementations§

Source§

impl<K: Clone + Hash + PartialEq + Eq + Copy + Clone + Send + Sync + 'static, V: Clone + Copy + Clone + Send + Sync + 'static, H: Clone + Hasher + Default> Clone for SeqMap<K, V, H>

Source§

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

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<K: Default + Hash + PartialEq + Eq + Copy + Clone + Send + Sync + 'static, V: Default + Copy + Clone + Send + Sync + 'static, H: Default + Hasher + Default> Default for SeqMap<K, V, H>

Source§

fn default() -> SeqMap<K, V, H>

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

impl<K: PartialEq + Hash + PartialEq + Eq + Copy + Clone + Send + Sync + 'static, V: PartialEq + Copy + Clone + Send + Sync + 'static, H: PartialEq + Hasher + Default> PartialEq for SeqMap<K, V, H>

Source§

fn eq(&self, other: &SeqMap<K, V, H>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<K: Eq + Hash + PartialEq + Eq + Copy + Clone + Send + Sync + 'static, V: Eq + Copy + Clone + Send + Sync + 'static, H: Eq + Hasher + Default> Eq for SeqMap<K, V, H>

Source§

impl<K: Hash + PartialEq + Eq + Copy + Clone + Send + Sync + 'static, V: Copy + Clone + Send + Sync + 'static, H: Hasher + Default> StructuralPartialEq for SeqMap<K, V, H>

Auto Trait Implementations§

§

impl<K, V, H = DefaultHasher> !Freeze for SeqMap<K, V, H>

§

impl<K, V, H = DefaultHasher> !RefUnwindSafe for SeqMap<K, V, H>

§

impl<K, V, H> Send for SeqMap<K, V, H>
where H: Send,

§

impl<K, V, H> Sync for SeqMap<K, V, H>
where H: Sync,

§

impl<K, V, H> Unpin for SeqMap<K, V, H>
where H: Unpin,

§

impl<K, V, H = DefaultHasher> !UnwindSafe for SeqMap<K, V, H>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

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

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

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.