pub struct MapStaticU16Example<K: Copy, V, const N: usize> { /* private fields */ }Expand description
✨ 🗃️
A runtime static hashmap with stored empty and tomb markers.
This variant stores its marker values as fields, enabling runtime initialization, cloning, and dynamic configuration. All operations follow the same hashing and probing logic as the const variant, but methods are non-const to allow greater flexibility.
Implementations§
Source§impl<V, const N: usize> MapStaticU16Example<u16, V, N>
impl<V, const N: usize> MapStaticU16Example<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> MapStaticU16Example<u16, V, N>
impl<V, const N: usize> MapStaticU16Example<u16, V, N>
Source§impl<V, const N: usize> MapStaticU16Example<u16, V, N>
impl<V, const N: usize> MapStaticU16Example<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
TOMBslots 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 firstTOMBencountered 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> MapStaticU16Example<u16, V, N>
impl<V: Copy, const N: usize> MapStaticU16Example<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
trueif the key was found and removed.falseif 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
TOMBslot if no earlierEMPTYslots exist.
Source§impl<V: Copy + Default, const N: usize> MapStaticU16Example<u16, V, N>
impl<V: Copy + Default, const N: usize> MapStaticU16Example<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(), returningtrueif 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 MapStaticU16Example<K, V, N>
impl<K: Clone + Copy, V: Clone, const N: usize> Clone for MapStaticU16Example<K, V, N>
Source§fn clone(&self) -> MapStaticU16Example<K, V, N>
fn clone(&self) -> MapStaticU16Example<K, V, N>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl<K: Copy + Copy, V: Copy, const N: usize> Copy for MapStaticU16Example<K, V, N>
impl<K: Eq + Copy, V: Eq, const N: usize> Eq for MapStaticU16Example<K, V, N>
Source§impl<K: PartialEq + Copy, V: PartialEq, const N: usize> PartialEq for MapStaticU16Example<K, V, N>
impl<K: PartialEq + Copy, V: PartialEq, const N: usize> PartialEq for MapStaticU16Example<K, V, N>
Source§fn eq(&self, other: &MapStaticU16Example<K, V, N>) -> bool
fn eq(&self, other: &MapStaticU16Example<K, V, N>) -> bool
self and other values to be equal, and is used by ==.impl<K: Copy, V, const N: usize> StructuralPartialEq for MapStaticU16Example<K, V, N>
Auto Trait Implementations§
impl<K, V, const N: usize> Freeze for MapStaticU16Example<K, V, N>
impl<K, V, const N: usize> RefUnwindSafe for MapStaticU16Example<K, V, N>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V, const N: usize> Send for MapStaticU16Example<K, V, N>
impl<K, V, const N: usize> Sync for MapStaticU16Example<K, V, N>
impl<K, V, const N: usize> Unpin for MapStaticU16Example<K, V, N>
impl<K, V, const N: usize> UnsafeUnpin for MapStaticU16Example<K, V, N>where
K: UnsafeUnpin,
V: UnsafeUnpin,
impl<K, V, const N: usize> UnwindSafe for MapStaticU16Example<K, V, N>where
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations§
Source§impl<T> AnyExt for T
impl<T> AnyExt 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§fn as_any_box(self: Box<Self>) -> Box<dyn Any>where
Self: Sized,
fn as_any_box(self: Box<Self>) -> Box<dyn Any>where
Self: Sized,
alloc only.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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> MemExt for Twhere
T: ?Sized,
impl<T> MemExt 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.