Skip to main content

CMap

Struct CMap 

Source
pub struct CMap<C, S = BuildWyHash> {
    pub value_fragments: Map<S>,
    pub value_coding: C,
}
Expand description

Compressed static function (immutable map) that maps hashable keys to values of any type.

To represent a function f:X→Y, it uses the space slightly larger than |X|H (the overhead is 23% or slightly more), where H is the entropy of the distribution of the f values over X. The time complexity is O(c) for evaluation and O(|X|c) for construction (not counting building the encoding dictionary), where c is the average codeword length (given in code fragments) of the values.

It uses Map based on solving linear system to store fragments of value codes and usually minimum_redundancy::Coding to compress values.

Fields§

§value_fragments: Map<S>§value_coding: C

Implementations§

Source§

impl<C, S> CMap<C, S>

Source

pub fn write_bytes(&self, bytes_per_value: usize) -> usize

Returns the number of bytes which write will write, assuming that each call to write_value writes bytes_per_value bytes.

Source

pub fn write<F>( &self, output: &mut dyn Write, write_value: F, ) -> Result<(), Error>
where F: FnMut(&mut dyn Write, &<C as Coding>::Value) -> Result<(), Error>,

Writes self to the output using write_value to write values.

Source

pub fn read_with_hasher<F>( input: &mut dyn Read, read_value: F, hasher: S, ) -> Result<CMap<C, S>, Error>
where F: FnMut(&mut dyn Read) -> Result<<C as Coding>::Value, Error>,

Reads self from the input, using read_value to read values (hasher must be the same as used by stored BDZHMap).

Source§

impl<C> CMap<C, BuildHasherDefault<DefaultHasher>>

Source

pub fn read<F>( input: &mut dyn Read, read_value: F, ) -> Result<CMap<C, BuildHasherDefault<DefaultHasher>>, Error>
where F: FnMut(&mut dyn Read) -> Result<<C as Coding>::Value, Error>,

Reads BDZHMap from the input using read_value to read values. Only BDZHMaps that use default hasher can be read by this method.

Source§

impl<C, S> CMap<C, S>

Source

pub fn try_from_mapf_with_coding_conf<'a, K, V, KvIntoIter, FKvIntoIter, BM>( map: FKvIntoIter, value_coding: C, conf: MapConf<BM, S>, extra_bits_per_fragment: u8, ) -> Option<CMap<C, S>>
where K: Hash + 'a, V: Borrow<<C as Coding>::Value> + 'a, KvIntoIter: IntoIterator<Item = (&'a K, &'a V)> + 'a, FKvIntoIter: Fn() -> KvIntoIter, BM: ValuesPreFiller,

Underlying Map uses value_coding.bits_per_fragment()+extra_bits_per_fragment bits per fragment. extra_bits_per_fragment>0 increases a chance of detection absence of the key by get and get_stats.

Source

pub fn try_from_map_with_coding_conf<K, MS, BM, V>( map: &HashMap<K, V, MS>, value_coding: C, conf: MapConf<BM, S>, bdz_extra_bits_per_fragment: u8, ) -> Option<CMap<C, S>>
where K: Hash, BM: ValuesPreFiller, V: Borrow<<C as Coding>::Value>,

Source

pub fn try_from_kv_with_coding_conf<K, BM, V>( keys: &[K], values: &[V], value_coding: C, conf: MapConf<BM, S>, bdz_extra_bits_per_fragment: u8, ) -> Option<CMap<C, S>>
where K: Hash, BM: ValuesPreFiller, V: Borrow<<C as Coding>::Value>,

Source§

impl<C> CMap<C>
where C: Coding,

Source

pub fn try_from_map_with_coding<K, MS, V>( map: &HashMap<K, V, MS>, value_coding: C, bdz_extra_bits_per_fragment: u8, ) -> Option<CMap<C>>
where K: Hash, V: Borrow<<C as Coding>::Value>,

Source

pub fn try_from_mapf_with_coding<'a, K, KvIntoIter, FKvIntoIter, V>( map: FKvIntoIter, value_coding: C, bdz_extra_bits_per_fragment: u8, ) -> Option<CMap<C>>
where K: Hash + 'a, V: Borrow<<C as Coding>::Value> + 'a, KvIntoIter: IntoIterator<Item = (&'a K, &'a V)> + 'a, FKvIntoIter: Fn() -> KvIntoIter,

Source

pub fn try_from_kv_with_coding<K, V>( keys: &[K], values: &[V], value_coding: C, bdz_extra_bits_per_fragment: u8, ) -> Option<CMap<C>>
where K: Hash, V: Borrow<<C as Coding>::Value>,

Source§

impl<C, S> CMap<C, S>

Source

pub fn try_from_map_with_builder_bpf_conf<K, MS, BM, BC>( map: &HashMap<K, <C as Coding>::Value, MS>, build_coding: &BC, bits_per_fragment: u8, conf: MapConf<BM, S>, bdz_extra_bits_per_fragment: u8, ) -> Option<CMap<C, S>>
where K: Hash, BM: ValuesPreFiller, BC: BuildCoding<<C as Coding>::Value, Coding = C>,

Source

pub fn try_from_map_with_builder_conf<K, MS, BM, BC>( map: &HashMap<K, <C as Coding>::Value, MS>, build_coding: &BC, conf: MapConf<BM, S>, bdz_extra_bits_per_fragment: u8, ) -> Option<CMap<C, S>>
where K: Hash, BM: ValuesPreFiller, BC: BuildCoding<<C as Coding>::Value, Coding = C>,

Source

pub fn try_from_kv_with_builder_bpf_conf<K, BM, BC>( keys: &[K], values: &[<C as Coding>::Value], build_coding: &BC, bits_per_fragment: u8, conf: MapConf<BM, S>, bdz_extra_bits_per_fragment: u8, ) -> Option<CMap<C, S>>
where K: Hash, BM: ValuesPreFiller, BC: BuildCoding<<C as Coding>::Value, Coding = C>,

Source

pub fn try_from_kv_with_builder_conf<K, BM, BC>( keys: &[K], values: &[<C as Coding>::Value], build_coding: &BC, conf: MapConf<BM, S>, bdz_extra_bits_per_fragment: u8, ) -> Option<CMap<C, S>>
where K: Hash, BM: ValuesPreFiller, BC: BuildCoding<<C as Coding>::Value, Coding = C>,

Source§

impl<V, S> CMap<Coding<V>, S>
where V: Hash + Eq + Clone, S: BuildSeededHasher,

Source

pub fn try_from_map_with_conf<K, MS, BM>( map: &HashMap<K, V, MS>, bits_per_fragment: u8, conf: MapConf<BM, S>, bdz_extra_bits_per_fragment: u8, ) -> Option<CMap<Coding<V>, S>>
where K: Hash, BM: ValuesPreFiller,

Source

pub fn try_from_kv_with_conf<K, BM>( keys: &[K], values: &[V], bits_per_fragment: u8, conf: MapConf<BM, S>, bdz_extra_bits_per_fragment: u8, ) -> Option<CMap<Coding<V>, S>>
where K: Hash, BM: ValuesPreFiller,

Source§

impl<V> CMap<Coding<V>>
where V: Hash + Eq + Clone,

Source

pub fn try_from_map<K, MS>( map: &HashMap<K, V, MS>, bits_per_fragment: u8, bdz_extra_bits_per_fragment: u8, ) -> Option<CMap<Coding<V>>>
where K: Hash,

Source

pub fn try_from_mapf<'a, K, KvIntoIter, FKvIntoIter, BM>( map: FKvIntoIter, bits_per_fragment: u8, bdz_extra_bits_per_fragment: u8, ) -> Option<CMap<Coding<V>>>
where K: Hash + 'a, V: 'a, KvIntoIter: IntoIterator<Item = (&'a K, &'a V)> + 'a, FKvIntoIter: Fn() -> KvIntoIter,

Source

pub fn try_from_kv<K>( keys: &[K], values: &[V], bits_per_fragment: u8, bdz_extra_bits_per_fragment: u8, ) -> Option<CMap<Coding<V>>>
where K: Hash,

Source§

impl<C, S> CMap<C, S>

Source

pub fn get_stats<K, A>( &self, k: &K, access_stats: &mut A, ) -> Option<<<C as Coding>::Decoder<'_> as Decoder>::Decoded>

Gets the value associated with the given key k and reports statistics to access_stats.

Source

pub fn get<K>( &self, k: &K, ) -> Option<<<C as Coding>::Decoder<'_> as Decoder>::Decoded>
where K: Hash + ?Sized,

Gets the value associated with the given key k.

Trait Implementations§

Source§

impl<C, S> CompressedSlice for CMap<C, S>

Source§

fn size_bytes(&self) -> usize

The size of self in bytes (including dynamically allocated memory).
Source§

fn write(&self, output: &mut dyn Write) -> Result<()>

Writes given slice to the output.
Source§

impl<C, S> GetSize for CMap<C, S>
where C: GetSize,

Source§

const USES_DYN_MEM: bool

true if and only if the variables of this type can use dynamic (heap) memory.
Source§

fn size_bytes_dyn(&self) -> usize

Returns approximate number of bytes occupied by dynamic (heap) part of self. Same as self.size_bytes() - std::mem::size_of_val(self).
Source§

fn size_bytes_content_dyn(&self) -> usize

Returns approximate number of bytes occupied by dynamic (heap) part of self content. It usually equals to size_bytes_dyn(). However, sometimes it is smaller by the amount of memory reserved but not yet used (e.g., size_bytes_content_dyn() only takes into account the length of the vector and not its capacity).
Source§

fn size_bytes(&self) -> usize

Returns approximate, total (including heap memory) number of bytes occupied by self.
Source§

impl<InSliceGamePosition, C, S> NimbersProvider<InSliceGamePosition> for CMap<C, S>
where InSliceGamePosition: Hash, C: Coding<Value = u8>, S: BuildSeededHasher,

Source§

fn get_nimber(&self, position: &InSliceGamePosition) -> Option<u8>

Returns nimber of the given position or None if self does not know the nimber.
Source§

fn get_nimber_and_self_organize( &mut self, position: &GamePosition, ) -> Option<u8>

Returns nimber of the given position or None if self does not know the nimber. Read more

Auto Trait Implementations§

§

impl<C, S> Freeze for CMap<C, S>
where Map<S>: Freeze, C: Freeze,

§

impl<C, S> RefUnwindSafe for CMap<C, S>

§

impl<C, S> Send for CMap<C, S>
where Map<S>: Send, C: Send,

§

impl<C, S> Sync for CMap<C, S>
where Map<S>: Sync, C: Sync,

§

impl<C, S> Unpin for CMap<C, S>
where Map<S>: Unpin, C: Unpin,

§

impl<C, S> UnsafeUnpin for CMap<C, S>
where Map<S>: UnsafeUnpin, C: UnsafeUnpin,

§

impl<C, S> UnwindSafe for CMap<C, S>
where Map<S>: UnwindSafe, C: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.