Struct ZeroMap
struct ZeroMap<'a, K, V> { ... }
where
K: ZeroMapKV<'a> + ?Sized,
V: ZeroMapKV<'a> + ?Sized
A zero-copy map datastructure, built on sorted binary-searchable ZeroVec
and VarZeroVec.
This type, like ZeroVec and VarZeroVec, is able to zero-copy
deserialize from appropriately formatted byte buffers. It is internally copy-on-write, so it can be mutated
afterwards as necessary.
Internally, a ZeroMap is a zero-copy vector for keys paired with a zero-copy vector for
values, sorted by the keys. Therefore, all types used in ZeroMap need to work with either
ZeroVec or VarZeroVec.
This does mean that for fixed-size data, one must use the regular type (u32, u8, char, etc),
whereas for variable-size data, ZeroMap will use the dynamically sized version (str not String,
ZeroSlice not ZeroVec, FooULE not Foo for custom types)
Examples
use ZeroMap;
let mut map = new;
map.insert;
map.insert;
map.insert;
let data = Data ;
let bincode_bytes =
serialize.expect;
// Will deserialize without any allocations
let deserialized: Data = deserialize
.expect;
assert_eq!;
assert_eq!;
Implementations
impl<'a, K, V> ZeroMap<'a, K, V>
fn insert_var_v<VE: EncodeAsVarULE<V>>(self: &mut Self, key: &K, value: &VE) -> Option<Box<V>>Same as
insert(), but allows using EncodeAsVarULE types with the value to avoid an extra allocation when dealing with custom ULE types.use Cow; use ZeroMap; let mut map: = new; map.insert_var_v; map.insert_var_v; assert_eq!; assert!;
impl<'a, K, V> ZeroMap<'a, K, V>
fn iter<'b>(self: &'b Self) -> impl ExactSizeIterator<Item = (&'b <K as ZeroMapKV<'a>>::GetType, &'b <V as ZeroMapKV<'a>>::GetType)>Produce an ordered iterator over key-value pairs
fn iter_keys<'b>(self: &'b Self) -> impl ExactSizeIterator<Item = &'b <K as ZeroMapKV<'a>>::GetType>Produce an ordered iterator over keys
fn iter_values<'b>(self: &'b Self) -> impl ExactSizeIterator<Item = &'b <V as ZeroMapKV<'a>>::GetType>Produce an iterator over values, ordered by keys
impl<'a, K, V> ZeroMap<'a, K, V>
fn cast_zv_k_unchecked<P>(self: Self) -> ZeroMap<'a, P, V> where P: AsULE<ULE = <K as >::ULE> + ZeroMapKV<'a, Container = ZeroVec<'a, P>>Cast a
ZeroMap<K, V>toZeroMap<P, V>whereKandPareAsULEtypes with the same representation.Unchecked Invariants
If
KandPhave different ordering semantics, unexpected behavior may occur.fn try_convert_zv_k_unchecked<P>(self: Self) -> Result<ZeroMap<'a, P, V>, UleError> where P: AsULE + ZeroMapKV<'a, Container = ZeroVec<'a, P>>Convert a
ZeroMap<K, V>toZeroMap<P, V>whereKandPareAsULEtypes with the same size.Unchecked Invariants
If
KandPhave different ordering semantics, unexpected behavior may occur.Panics
Panics if
K::ULEandP::ULEare not the same size.
impl<'a, K, V> ZeroMap<'a, K, V>
fn get(self: &Self, key: &K) -> Option<&<V as >::GetType>Get the value associated with
key, if it exists.For fixed-size (
AsULE)Vtypes, this will return their correspondingAsULE::ULEtype. If you wish to work with theVtype directly, [Self::get_copied()] exists for convenience.use ZeroMap; let mut map = new; map.insert; map.insert; assert_eq!; assert_eq!;fn get_by<impl FnMut(&K) -> Ordering: FnMut(&K) -> Ordering>(self: &Self, predicate: impl FnMut(&K) -> Ordering) -> Option<&<V as >::GetType>Binary search the map with
predicateto find a key, returning the value.use ZeroMap; let mut map = new; map.insert; map.insert; assert_eq!; assert_eq!;fn contains_key(self: &Self, key: &K) -> boolReturns whether
keyis contained in this mapuse ZeroMap; let mut map = new; map.insert; map.insert; assert!; assert!;fn insert(self: &mut Self, key: &K, value: &V) -> Option<<V as >::OwnedType>Insert
valuewithkey, returning the existing value if it exists.use ZeroMap; let mut map = new; map.insert; map.insert; assert_eq!; assert_eq!;fn remove(self: &mut Self, key: &K) -> Option<<V as >::OwnedType>Remove the value at
key, returning it if it exists.use ZeroMap; let mut map = new; map.insert; map.insert; assert_eq!; assert_eq!;fn try_append<'b>(self: &mut Self, key: &'b K, value: &'b V) -> Option<(&'b K, &'b V)>Appends
valuewithkeyto the end of the underlying vector, returningkeyandvalueif it failed. Useful for extending with an existing sorted list.use ZeroMap; let mut map = new; assert!; assert!; let unsuccessful = map.try_append; assert!; let unsuccessful = map.try_append; assert!; assert_eq!; // contains the original value for the key: 3 assert_eq!; // not appended since it wasn't in order assert_eq!;
impl<'a, K, V> ZeroMap<'a, K, V>
fn iter_copied<'b>(self: &'b Self) -> impl Iterator<Item = (K, V)> + 'bSimilar to [
Self::iter()] except it returns a direct copy of the keys values instead of references toK::ULEandV::ULE, in cases whenKandVare fixed-size
impl<'a, K, V> ZeroMap<'a, K, V>
fn cast_zv_v_unchecked<P>(self: Self) -> ZeroMap<'a, K, P> where P: AsULE<ULE = <V as >::ULE> + ZeroMapKV<'a, Container = ZeroVec<'a, P>>Cast a
ZeroMap<K, V>toZeroMap<K, P>whereVandPareAsULEtypes with the same representation.Unchecked Invariants
If
VandPhave different ordering semantics, unexpected behavior may occur.fn try_convert_zv_v_unchecked<P>(self: Self) -> Result<ZeroMap<'a, K, P>, UleError> where P: AsULE + ZeroMapKV<'a, Container = ZeroVec<'a, P>>Convert a
ZeroMap<K, V>toZeroMap<K, P>whereVandPareAsULEtypes with the same size.Unchecked Invariants
If
VandPhave different ordering semantics, unexpected behavior may occur.Panics
Panics if
V::ULEandP::ULEare not the same size.
impl<'a, K, V> ZeroMap<'a, K, V>
fn iter_copied_values<'b>(self: &'b Self) -> impl Iterator<Item = (&'b <K as ZeroMapKV<'a>>::GetType, V)>Similar to [
Self::iter()] except it returns a direct copy of the values instead of references toV::ULE, in cases whenVis fixed-size
impl<'a, K, V> ZeroMap<'a, K, V>
fn get_copied(self: &Self, key: &K) -> Option<V>For cases when
Vis fixed-size, obtain a direct copy ofVinstead ofV::ULE.Examples
use ZeroMap; let mut map = new; map.insert; map.insert; assert_eq!; assert_eq!;fn get_copied_by<impl FnMut(&K) -> Ordering: FnMut(&K) -> Ordering>(self: &Self, predicate: impl FnMut(&K) -> Ordering) -> Option<V>Binary search the map with
predicateto find a key, returning the value.For cases when
Vis fixed-size, use this method to obtain a direct copy ofVinstead ofV::ULE.Examples
use ZeroMap; let mut map = new; map.insert; map.insert; assert_eq!; assert_eq!;
impl<'a, K, V> ZeroMap<'a, K, V>
fn new() -> SelfCreates a new, empty
ZeroMap<K, V>.Examples
use ZeroMap; let zm: = new; assert!;fn with_capacity(capacity: usize) -> SelfConstruct a new
ZeroMapwith a given capacityfn as_borrowed(self: &'a Self) -> ZeroMapBorrowed<'a, K, V>Obtain a borrowed version of this map
fn len(self: &Self) -> usizeThe number of elements in the
ZeroMapfn is_empty(self: &Self) -> boolWhether the
ZeroMapis emptyfn clear(self: &mut Self)Remove all elements from the
ZeroMapfn reserve(self: &mut Self, additional: usize)Reserve capacity for
additionalmore elements to be inserted into theZeroMapto avoid frequent reallocations.See
Vec::reserve()for more information.
impl<'a, 'b, K, V> PartialEq for ZeroMap<'a, K, V>
fn eq(self: &Self, other: &ZeroMap<'b, K, V>) -> bool
impl<'a, A, B, K, V> FromIterator for ZeroMap<'a, K, V>
fn from_iter<T>(iter: T) -> Self where T: IntoIterator<Item = (A, B)>
impl<'a, K, V> Clone for ZeroMap<'a, K, V>
fn clone(self: &Self) -> Self
impl<'a, K, V> Debug for ZeroMap<'a, K, V>
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result<(), Error>
impl<'a, K, V> Default for ZeroMap<'a, K, V>
fn default() -> Self
impl<'a, K, V> Freeze for ZeroMap<'a, K, V>
impl<'a, K, V> From for ZeroMap<'a, K, V>
fn from(other: ZeroMapBorrowed<'a, K, V>) -> Self
impl<'a, K, V> RefUnwindSafe for ZeroMap<'a, K, V>
impl<'a, K, V> Send for ZeroMap<'a, K, V>
impl<'a, K, V> Sync for ZeroMap<'a, K, V>
impl<'a, K, V> Unpin for ZeroMap<'a, K, V>
impl<'a, K, V> UnsafeUnpin for ZeroMap<'a, K, V>
impl<'a, K, V> UnwindSafe for ZeroMap<'a, K, V>
impl<'a, K, V> Yokeable for ZeroMap<'static, K, V>
fn transform(self: &'a Self) -> &'a <Self as >::Outputfn transform_owned(self: Self) -> <Self as >::Outputunsafe fn make(from: <Self as >::Output) -> Selffn transform_mut<F>(self: &'a mut Self, f: F) where F: 'static + for<'b> FnOnce(&'b mut <Self as >::Output)
impl<'zf, 's, K, V> ZeroFrom for ZeroMap<'zf, K, V>
fn zero_from(other: &'zf ZeroMap<'s, K, V>) -> Self
impl<T> Any for ZeroMap<'a, K, V>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for ZeroMap<'a, K, V>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for ZeroMap<'a, K, V>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for ZeroMap<'a, K, V>
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> ErasedDestructor for ZeroMap<'a, K, V>
impl<T> From for ZeroMap<'a, K, V>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for ZeroMap<'a, K, V>
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T, U> Into for ZeroMap<'a, K, V>
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for ZeroMap<'a, K, V>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for ZeroMap<'a, K, V>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>