Struct ZeroMap2d
struct ZeroMap2d<'a, K0, K1, V> { ... }
where
K0: ZeroMapKV<'a> + ?Sized,
K1: ZeroMapKV<'a> + ?Sized,
V: ZeroMapKV<'a> + ?Sized
A zero-copy, two-dimensional map datastructure .
This is an extension of ZeroMap that supports two layers of keys. For example,
to map a pair of an integer and a string to a buffer, you can write:
# use zerovec::ZeroMap2d;
let _: ZeroMap2d<u32, str, [u8]> = unimplemented!();
Internally, ZeroMap2d stores four zero-copy vectors, one for each type argument plus
one more to match between the two vectors of keys.
Examples
use ZeroMap2d;
// Example byte buffer representing the map { 1: {2: "three" } }
let BINCODE_BYTES: & = &;
// Deserializing to ZeroMap requires no heap allocations.
let zero_map: =
deserialize
.expect;
assert_eq!;
Implementations
impl<'a, K0, K1, V> ZeroMap2d<'a, K0, K1, V>
fn new() -> SelfCreates a new, empty
ZeroMap2d.Examples
use ZeroMap2d; let zm: = new; assert!;fn with_capacity(capacity: usize) -> SelfConstruct a new
ZeroMap2dwith a given capacityfn as_borrowed(self: &'a Self) -> ZeroMap2dBorrowed<'a, K0, K1, V>Obtain a borrowed version of this map
fn len(self: &Self) -> usizeThe number of values in the
ZeroMap2dfn is_empty(self: &Self) -> boolWhether the
ZeroMap2dis emptyfn clear(self: &mut Self)Remove all elements from the
ZeroMap2dfn reserve(self: &mut Self, additional: usize)Reserve capacity for
additionalmore elements to be inserted into theZeroMap2dto avoid frequent reallocations.See
Vec::reserve()for more information.fn iter0<'l>(self: &'l Self) -> impl Iterator<Item = ZeroMap2dCursor<'l, 'a, K0, K1, V>> + 'lProduce an ordered iterator over keys0, which can then be used to get an iterator over keys1 for a particular key0.
Example
Loop over all elements of a ZeroMap2d:
use ZeroMap2d; let mut map: = new; map.insert; map.insert; map.insert; let mut total_value = 0; for cursor in map.iter0 assert_eq!;
impl<'a, K0, K1, V> ZeroMap2d<'a, K0, K1, V>
fn get_copied_2d(self: &Self, key0: &K0, key1: &K1) -> Option<V>For cases when
Vis fixed-size, obtain a direct copy ofVinstead ofV::ULEExamples
# use ZeroMap2d; let mut map: = new; map.insert; map.insert; map.insert; assert_eq!;
impl<'a, K0, K1, V> ZeroMap2d<'a, K0, K1, V>
fn get_2d(self: &Self, key0: &K0, key1: &K1) -> Option<&<V as >::GetType>Get the value associated with
key0andkey1, if it exists.For more fine-grained error handling, use
ZeroMap2d::get0.use ZeroMap2d; let mut map = new; map.insert; map.insert; map.insert; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!;fn insert(self: &mut Self, key0: &K0, key1: &K1, value: &V) -> Option<<V as >::OwnedType>Insert
valuewithkey, returning the existing value if it exists.use ZeroMap2d; let mut map = new; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!;fn remove(self: &mut Self, key0: &K0, key1: &K1) -> Option<<V as >::OwnedType>Remove the value at
key, returning it if it exists.use ZeroMap2d; let mut map = new; map.insert; map.insert; assert_eq!; assert_eq!; assert_eq!;fn try_append<'b>(self: &mut Self, key0: &'b K0, key1: &'b K1, value: &'b V) -> Option<(&'b K0, &'b K1, &'b V)>Appends
valuewithkeyto the end of the underlying vector, returningkeyandvalueif it failed. Useful for extending with an existing sorted list.use ZeroMap2d; 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, K0, K1, V> ZeroMap2d<'a, K0, K1, V>
fn get0<'l>(self: &'l Self, key0: &K0) -> Option<ZeroMap2dCursor<'l, 'a, K0, K1, V>>Gets a cursor for
key0. IfNone, thenkey0is not in the map. IfSome, thenkey0is in the map, andkey1can be queried.use ZeroMap2d; let mut map = new; map.insert; map.insert; map.insert; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!;fn get0_by<'l, impl FnMut(&K0) -> Ordering: FnMut(&K0) -> Ordering>(self: &'l Self, predicate: impl FnMut(&K0) -> Ordering) -> Option<ZeroMap2dCursor<'l, 'a, K0, K1, V>>Binary search the map for
key0, returning a cursor.use ZeroMap2d; let mut map = new; map.insert; map.insert; assert!; assert!;fn contains_key0(self: &Self, key0: &K0) -> boolReturns whether
key0is contained in this mapuse ZeroMap2d; let mut map = new; map.insert; map.insert; assert!; assert!;
impl<'a, 'b, K0, K1, V> PartialEq for ZeroMap2d<'a, K0, K1, V>
fn eq(self: &Self, other: &ZeroMap2d<'b, K0, K1, V>) -> bool
impl<'a, A, B, C, K0, K1, V> FromIterator for ZeroMap2d<'a, K0, K1, V>
fn from_iter<T>(iter: T) -> Self where T: IntoIterator<Item = (A, B, C)>
impl<'a, K0, K1, V> Clone for ZeroMap2d<'a, K0, K1, V>
fn clone(self: &Self) -> Self
impl<'a, K0, K1, V> Debug for ZeroMap2d<'a, K0, K1, V>
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result<(), Error>
impl<'a, K0, K1, V> Default for ZeroMap2d<'a, K0, K1, V>
fn default() -> Self
impl<'a, K0, K1, V> Freeze for ZeroMap2d<'a, K0, K1, V>
impl<'a, K0, K1, V> From for ZeroMap2d<'a, K0, K1, V>
fn from(other: ZeroMap2dBorrowed<'a, K0, K1, V>) -> Self
impl<'a, K0, K1, V> RefUnwindSafe for ZeroMap2d<'a, K0, K1, V>
impl<'a, K0, K1, V> Send for ZeroMap2d<'a, K0, K1, V>
impl<'a, K0, K1, V> Sync for ZeroMap2d<'a, K0, K1, V>
impl<'a, K0, K1, V> Unpin for ZeroMap2d<'a, K0, K1, V>
impl<'a, K0, K1, V> UnsafeUnpin for ZeroMap2d<'a, K0, K1, V>
impl<'a, K0, K1, V> UnwindSafe for ZeroMap2d<'a, K0, K1, V>
impl<'a, K0, K1, V> Yokeable for ZeroMap2d<'static, K0, K1, 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, K0, K1, V> ZeroFrom for ZeroMap2d<'zf, K0, K1, V>
fn zero_from(other: &'zf ZeroMap2d<'s, K0, K1, V>) -> Self
impl<T> Any for ZeroMap2d<'a, K0, K1, V>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for ZeroMap2d<'a, K0, K1, V>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for ZeroMap2d<'a, K0, K1, V>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for ZeroMap2d<'a, K0, K1, V>
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> ErasedDestructor for ZeroMap2d<'a, K0, K1, V>
impl<T> From for ZeroMap2d<'a, K0, K1, V>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for ZeroMap2d<'a, K0, K1, V>
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T, U> Into for ZeroMap2d<'a, K0, K1, 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 ZeroMap2d<'a, K0, K1, V>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for ZeroMap2d<'a, K0, K1, V>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>