autocommit 2022-02-04 16:52:11 CET
This commit is contained in:
parent
bb1639a2ae
commit
89bfd2ffcd
21 changed files with 599 additions and 46 deletions
|
|
@ -17,6 +17,14 @@ impl<K, V, const N: usize> Default for SmallMap<K, V, N> {
|
|||
}
|
||||
|
||||
impl<K: Eq, V, const N: usize> SmallMap<K, V, N> {
|
||||
pub fn new_with(k: K, v: V) -> Self {
|
||||
let mut sv = SmallVec::new();
|
||||
sv.push((k, v));
|
||||
Self {
|
||||
m: UnsafeCell::new(sv),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
m: UnsafeCell::new(SmallVec::new_const()),
|
||||
|
|
@ -40,6 +48,10 @@ impl<K: Eq, V, const N: usize> SmallMap<K, V, N> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
unsafe { self.m.get().deref_mut().is_empty() }
|
||||
}
|
||||
|
||||
pub fn remove(&self, k: &K) -> Option<V> {
|
||||
unsafe {
|
||||
let m = self.m.get().deref_mut();
|
||||
|
|
@ -52,6 +64,12 @@ impl<K: Eq, V, const N: usize> SmallMap<K, V, N> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn clear(&self) {
|
||||
unsafe {
|
||||
let _v = mem::replace(self.m.get().deref_mut(), SmallVec::new());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn take(&self) -> SmallVec<[(K, V); N]> {
|
||||
unsafe { mem::take(self.m.get().deref_mut()) }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue