pub struct ExampleStaticMapU16<K: Copy, V, const N: usize> { /* private fields */ }
Expand description
Implementations§
Source§impl<V, const N: usize> ExampleStaticMapU16<u16, V, N>
impl<V, const N: usize> ExampleStaticMapU16<u16, V, N>
Sourcepub fn insert_move(&mut self, key: u16, value: V) -> Result<(), NotEnoughSpace> ⓘ
pub fn insert_move(&mut self, key: u16, value: V) -> Result<(), NotEnoughSpace> ⓘ
Inserts a key-value pair, consuming the value.
Sourcepub fn replace(&mut self, key: u16, replacement: V) -> Option<V> ⓘ
pub fn replace(&mut self, key: u16, replacement: V) -> Option<V> ⓘ
Removes and returns the value for a given key, replacing it with a provided value.
Sourcepub fn replace_default(&mut self, key: u16) -> Option<V> ⓘwhere
V: Default,
pub fn replace_default(&mut self, key: u16) -> Option<V> ⓘwhere
V: Default,
Removes and returns the value for a given key, replacing it with V::default()
.
Sourcepub fn replace_with<F>(&mut self, key: u16, replacement: F) -> Option<V> ⓘwhere
F: FnOnce() -> V,
pub fn replace_with<F>(&mut self, key: u16, replacement: F) -> Option<V> ⓘwhere
F: FnOnce() -> V,
Removes and returns the value for a given key, replacing it with a custom value.
Sourcepub const fn hash_index(&self, key: u16) -> usize
pub const fn hash_index(&self, key: u16) -> usize
Computes a hash index.
Source§impl<V, const N: usize> ExampleStaticMapU16<u16, V, N>
impl<V, const N: usize> ExampleStaticMapU16<u16, V, N>
Source§impl<V, const N: usize> ExampleStaticMapU16<u16, V, N>
impl<V, const N: usize> ExampleStaticMapU16<u16, V, N>
Sourcepub fn new() -> Selfwhere
V: Default,
pub fn new() -> Selfwhere
V: Default,
Constructs a new static map with runtime EMPTY and TOMB values.
Sourcepub fn get_ref(&self, key: u16) -> Option<&V> ⓘ
pub fn get_ref(&self, key: u16) -> Option<&V> ⓘ
Retrieves some shared reference to the value associated with the given key.
Sourcepub fn get_mut(&mut self, key: u16) -> Option<&mut V> ⓘ
pub fn get_mut(&mut self, key: u16) -> Option<&mut V> ⓘ
Retrieves some exclusive reference to the value associated with the given key.
Sourcepub fn entry(&mut self, key: u16) -> StaticMapEntry<'_, V>
pub fn entry(&mut self, key: u16) -> StaticMapEntry<'_, V>
Retrieves an entry for a given key.
Sourcepub fn should_rebuild(&self) -> bool
pub fn should_rebuild(&self) -> bool
Determines if rebuilding the table would improve efficiency.
§Heuristic:
- Rebuild if
TOMB
slots exceedN / 2
(half the table size).
Sourcepub fn deleted_count(&self) -> usize
pub fn deleted_count(&self) -> usize
Returns the number of deleted (TOMB) slots.
Sourcepub fn load_factor(&self) -> f32
pub fn load_factor(&self) -> f32
Returns the load factor as a fraction of total capacity.
Sourcepub fn insert(&mut self, key: u16, value: V) -> Result<(), NotEnoughSpace> ⓘ
pub fn insert(&mut self, key: u16, value: V) -> Result<(), NotEnoughSpace> ⓘ
Inserts a key-value pair.
§Returns
Ok(())
if the insertion succeeds.Err(
[NotEnoughSpace
])
if no slots are available.
§Behavior
- Computes the hash index of the key.
- If the slot is
EMPTY
, inserts immediately. - If the slot contains
TOMB
, the firstTOMB
encountered is used if no empty slots exist earlier in probing. - If the slot contains another key, probes forward until an open slot is found.
- If no open slots exist, returns an error.
Source§impl<V: Copy, const N: usize> ExampleStaticMapU16<u16, V, N>
impl<V: Copy, const N: usize> ExampleStaticMapU16<u16, V, N>
Sourcepub fn remove(&mut self, key: u16) -> bool
pub fn remove(&mut self, key: u16) -> bool
Removes a key-value pair.
§Returns
true
if the key was found and removed.false
if the key was not found in the map.
§Behavior
- Marks the slot as deleted (
TOMB
). - Future lookups will continue probing past deleted entries.
- Does NOT free the slot for immediate reuse.
- New insertions only reuse a
TOMB
slot if no earlierEMPTY
slots exist.
Source§impl<V: Copy + Default, const N: usize> ExampleStaticMapU16<u16, V, N>
impl<V: Copy + Default, const N: usize> ExampleStaticMapU16<u16, V, N>
Sourcepub fn remove_rebuild(&mut self, key: u16) -> bool
pub fn remove_rebuild(&mut self, key: u16) -> bool
Removes a key-value pair and optionally rebuilds the table.
§Behavior
- Calls
remove()
, returningtrue
if the key was found. - If
should_rebuild()
returnstrue
, callsrebuild()
.
Sourcepub fn rebuild(&mut self)
pub fn rebuild(&mut self)
Rebuilds the table by removing TOMB
slots and optimizing key placement.
Calls Self::rebuilt()
and replaces self
with the optimized table.
§When to Call?
- When many deletions have occurred.
- If lookups start taking significantly longer.
Trait Implementations§
Source§impl<K: Clone + Copy, V: Clone, const N: usize> Clone for ExampleStaticMapU16<K, V, N>
impl<K: Clone + Copy, V: Clone, const N: usize> Clone for ExampleStaticMapU16<K, V, N>
Source§fn clone(&self) -> ExampleStaticMapU16<K, V, N>
fn clone(&self) -> ExampleStaticMapU16<K, V, N>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<K: PartialEq + Copy, V: PartialEq, const N: usize> PartialEq for ExampleStaticMapU16<K, V, N>
impl<K: PartialEq + Copy, V: PartialEq, const N: usize> PartialEq for ExampleStaticMapU16<K, V, N>
Source§fn eq(&self, other: &ExampleStaticMapU16<K, V, N>) -> bool
fn eq(&self, other: &ExampleStaticMapU16<K, V, N>) -> bool
self
and other
values to be equal, and is used by ==
.impl<K: Copy + Copy, V: Copy, const N: usize> Copy for ExampleStaticMapU16<K, V, N>
impl<K: Eq + Copy, V: Eq, const N: usize> Eq for ExampleStaticMapU16<K, V, N>
impl<K: Copy, V, const N: usize> StructuralPartialEq for ExampleStaticMapU16<K, V, N>
Auto Trait Implementations§
impl<K, V, const N: usize> Freeze for ExampleStaticMapU16<K, V, N>
impl<K, V, const N: usize> RefUnwindSafe for ExampleStaticMapU16<K, V, N>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V, const N: usize> Send for ExampleStaticMapU16<K, V, N>
impl<K, V, const N: usize> Sync for ExampleStaticMapU16<K, V, N>
impl<K, V, const N: usize> Unpin for ExampleStaticMapU16<K, V, N>
impl<K, V, const N: usize> UnwindSafe for ExampleStaticMapU16<K, V, N>where
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ByteSized for T
impl<T> ByteSized for T
Source§const BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
Source§fn byte_align(&self) -> usize
fn byte_align(&self) -> usize
Source§fn ptr_size_ratio(&self) -> [usize; 2]
fn ptr_size_ratio(&self) -> [usize; 2]
Source§impl<T, R> Chain<R> for Twhere
T: ?Sized,
impl<T, R> Chain<R> for Twhere
T: ?Sized,
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> ExtAny for T
impl<T> ExtAny for T
Source§fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
TypeId
of Self
using a custom hasher.Source§fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
Source§impl<T> ExtMem for Twhere
T: ?Sized,
impl<T> ExtMem for Twhere
T: ?Sized,
Source§const NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Source§fn mem_align_of<T>() -> usize
fn mem_align_of<T>() -> usize
Source§fn mem_align_of_val(&self) -> usize
fn mem_align_of_val(&self) -> usize
Source§fn mem_size_of<T>() -> usize
fn mem_size_of<T>() -> usize
Source§fn mem_size_of_val(&self) -> usize
fn mem_size_of_val(&self) -> usize
Source§fn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
true
if dropping values of this type matters. Read moreSource§fn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
self
without running its destructor. Read moreSource§fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
Source§unsafe fn mem_zeroed<T>() -> T
unsafe fn mem_zeroed<T>() -> T
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§fn mem_as_bytes(&self) -> &[u8] ⓘ
fn mem_as_bytes(&self) -> &[u8] ⓘ
unsafe_slice
only.§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Hook for T
impl<T> Hook for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more