pub struct VFunc<T: ?Sized + ToSig<S>, W: ZeroCopy + Word = usize, D: BitFieldSlice<W> = Box<[W]>, S: Sig = [u64; 2], E: ShardEdge<S, 3> = FuseLge3Shards> { /* private fields */ }
Expand description
Static functions with low space overhead, fast parallel construction, and fast queries.
Static functions map keys to values, but they do not store the keys:
querying a static function with a key outside of the original set will lead
to an arbitrary result. Another name for static functions retrieval data
structure. Values are retrieved using the get
method. On
some architectures, and with some constraints,
get_unaligned
might be faster.
In exchange, static functions have a very low space overhead, and make it possible to store the association between keys and values just in the space required by the values (with a small overhead).
This structure is based on “ε-Cost Sharding: Scaling Hypergraph-Based
Static Functions and Filters to Trillions of
Keys”. Space overhead with respect to the
optimum depends on the ShardEdge
type. The default is
FuseLge3Shards
, which provides 10.5% space overhead for large key sets
(above a few million keys), which grow up to 12% going towards smaller key
sets. Details on other possible ShardEdge
implementations can be found
in the shard_edge
module documentation.
Instances of this structure are immutable; they are built using a
VBuilder
and can be serialized using
ε-serde. Please see the documentation of
VBuilder
for examples.
§Generics
T
: The type of the keys.W
: The word used to store the data, which is also the output type. It can be any unsigned type.D
: The backend storing the function data. It can be aBitFieldVec<W>
or aBox<[W]>
. In the first case, the data is stored using exactly the number of bits needed, but access is slightly slower, while in the second case the data is stored in a boxed slice ofW
, thus forcing the number of bits to the number of bits ofW
, but access will be faster. Note that for most bit sizes in the first case on some architectures you can use unaligned reads to get faster queries.S
: The signature type. The default is[u64; 2]
. You can switch to[u64; 1]
(and possiblyFuseLge3NoShards
) for slightly faster construction and queries, but the construction will not scale beyond 3.8 billion keys.E
: The sharding and edge logic type. The default isFuseLge3Shards
. For small sets of keys you might tryFuseLge3NoShards
, possibly coupled with[u64; 1]
signatures. For functions with more than a few dozen billion keys, you might tryFuseLge3FullSigs
.
Implementations§
Source§impl<T: ?Sized + ToSig<S>, W: ZeroCopy + Word, D: BitFieldSlice<W>, S: Sig, E: ShardEdge<S, 3>> VFunc<T, W, D, S, E>
impl<T: ?Sized + ToSig<S>, W: ZeroCopy + Word, D: BitFieldSlice<W>, S: Sig, E: ShardEdge<S, 3>> VFunc<T, W, D, S, E>
Sourcepub fn get_by_sig(&self, sig: S) -> W
pub fn get_by_sig(&self, sig: S) -> W
Returns the value associated with the given signature, or a random value if the signature is not the signature of a key.
This method is mainly useful in the construction of compound functions.
Source§impl<T: ?Sized + ToSig<S>, W: ZeroCopy + Word, S: Sig, E: ShardEdge<S, 3>> VFunc<T, W, BitFieldVec<W>, S, E>
impl<T: ?Sized + ToSig<S>, W: ZeroCopy + Word, S: Sig, E: ShardEdge<S, 3>> VFunc<T, W, BitFieldVec<W>, S, E>
Sourcepub fn get_by_sig_unaligned(&self, sig: S) -> W
pub fn get_by_sig_unaligned(&self, sig: S) -> W
Returns the value associated with the given signature, or a random value if the signature is not the signature of a key, using unaligned reads.
This method uses BitFieldVec::get_unaligned
, and has
the same constraints.
This method is mainly useful in the construction of compound functions.
Sourcepub fn get_unaligned(&self, key: impl Borrow<T>) -> W
pub fn get_unaligned(&self, key: impl Borrow<T>) -> W
Returns the value associated with the given key, or a random value if the key is not present, using unaligned reads.
This method uses BitFieldVec::get_unaligned
, and has
the same constraints.
Trait Implementations§
Source§impl<T: ?Sized + ToSig<S>, W: ZeroCopy + Word, D, S: Sig, E> AlignHash for VFunc<T, W, D, S, E>where
E: AlignHash + ShardEdge<S, 3>,
D: AlignHash + BitFieldSlice<W>,
PhantomData<T>: AlignHash,
PhantomData<W>: AlignHash,
PhantomData<S>: AlignHash,
impl<T: ?Sized + ToSig<S>, W: ZeroCopy + Word, D, S: Sig, E> AlignHash for VFunc<T, W, D, S, E>where
E: AlignHash + ShardEdge<S, 3>,
D: AlignHash + BitFieldSlice<W>,
PhantomData<T>: AlignHash,
PhantomData<W>: AlignHash,
PhantomData<S>: AlignHash,
Source§fn align_hash(hasher: &mut impl Hasher, _offset_of: &mut usize)
fn align_hash(hasher: &mut impl Hasher, _offset_of: &mut usize)
hasher
assuming to be positioned
at offset_of
.Source§fn align_hash_val(&self, hasher: &mut impl Hasher, offset_of: &mut usize)
fn align_hash_val(&self, hasher: &mut impl Hasher, offset_of: &mut usize)
AlignHash::align_hash
on a value.Source§impl<T: ?Sized + ToSig<S>, W: ZeroCopy + Word, D: BitFieldSlice<W>, S: Sig, E: ShardEdge<S, 3>> CopyType for VFunc<T, W, D, S, E>
impl<T: ?Sized + ToSig<S>, W: ZeroCopy + Word, D: BitFieldSlice<W>, S: Sig, E: ShardEdge<S, 3>> CopyType for VFunc<T, W, D, S, E>
Source§impl<T: ?Sized + ToSig<S>, W: ZeroCopy + Word, D, S: Sig, E> CopyType for VFunc<T, W, D, S, E>where
E: MemSize + ShardEdge<S, 3>,
u64: MemSize,
usize: MemSize,
D: MemSize + BitFieldSlice<W>,
PhantomData<T>: MemSize,
PhantomData<W>: MemSize,
PhantomData<S>: MemSize,
impl<T: ?Sized + ToSig<S>, W: ZeroCopy + Word, D, S: Sig, E> CopyType for VFunc<T, W, D, S, E>where
E: MemSize + ShardEdge<S, 3>,
u64: MemSize,
usize: MemSize,
D: MemSize + BitFieldSlice<W>,
PhantomData<T>: MemSize,
PhantomData<W>: MemSize,
PhantomData<S>: MemSize,
Source§impl<T: Debug + ?Sized + ToSig<S>, W: Debug + ZeroCopy + Word, D: Debug + BitFieldSlice<W>, S: Debug + Sig, E: Debug + ShardEdge<S, 3>> Debug for VFunc<T, W, D, S, E>
impl<T: Debug + ?Sized + ToSig<S>, W: Debug + ZeroCopy + Word, D: Debug + BitFieldSlice<W>, S: Debug + Sig, E: Debug + ShardEdge<S, 3>> Debug for VFunc<T, W, D, S, E>
Source§impl<T: ?Sized + ToSig<S>, W: ZeroCopy + Word, D, S: Sig, E> DeserializeInner for VFunc<T, W, D, S, E>where
E: DeserializeInner + ShardEdge<S, 3>,
u64: DeserializeInner,
usize: DeserializeInner,
D: DeserializeInner + BitFieldSlice<W>,
PhantomData<T>: DeserializeInner,
PhantomData<W>: DeserializeInner,
PhantomData<S>: DeserializeInner,
for<'epserde_desertype> <D as DeserializeInner>::DeserType<'epserde_desertype>: BitFieldSlice<W>,
for<'epserde_desertype> <E as DeserializeInner>::DeserType<'epserde_desertype>: ShardEdge<S, 3>,
impl<T: ?Sized + ToSig<S>, W: ZeroCopy + Word, D, S: Sig, E> DeserializeInner for VFunc<T, W, D, S, E>where
E: DeserializeInner + ShardEdge<S, 3>,
u64: DeserializeInner,
usize: DeserializeInner,
D: DeserializeInner + BitFieldSlice<W>,
PhantomData<T>: DeserializeInner,
PhantomData<W>: DeserializeInner,
PhantomData<S>: DeserializeInner,
for<'epserde_desertype> <D as DeserializeInner>::DeserType<'epserde_desertype>: BitFieldSlice<W>,
for<'epserde_desertype> <E as DeserializeInner>::DeserType<'epserde_desertype>: ShardEdge<S, 3>,
Source§type DeserType<'epserde_desertype> = VFunc<T, W, <D as DeserializeInner>::DeserType<'epserde_desertype>, S, <E as DeserializeInner>::DeserType<'epserde_desertype>>
type DeserType<'epserde_desertype> = VFunc<T, W, <D as DeserializeInner>::DeserType<'epserde_desertype>, S, <E as DeserializeInner>::DeserType<'epserde_desertype>>
DeserType
.fn _deserialize_full_inner( backend: &mut impl ReadWithPos, ) -> Result<Self, Error>
fn _deserialize_eps_inner<'deserialize_eps_inner_lifetime>( backend: &mut SliceWithPos<'deserialize_eps_inner_lifetime>, ) -> Result<Self::DeserType<'deserialize_eps_inner_lifetime>, Error>
Source§impl<T: ?Sized + ToSig<S>, W: ZeroCopy + Word, D, S: Sig, E> MemDbgImpl for VFunc<T, W, D, S, E>where
E: MemDbgImpl + ShardEdge<S, 3>,
u64: MemDbgImpl,
usize: MemDbgImpl,
D: MemDbgImpl + BitFieldSlice<W>,
PhantomData<T>: MemDbgImpl,
PhantomData<W>: MemDbgImpl,
PhantomData<S>: MemDbgImpl,
impl<T: ?Sized + ToSig<S>, W: ZeroCopy + Word, D, S: Sig, E> MemDbgImpl for VFunc<T, W, D, S, E>where
E: MemDbgImpl + ShardEdge<S, 3>,
u64: MemDbgImpl,
usize: MemDbgImpl,
D: MemDbgImpl + BitFieldSlice<W>,
PhantomData<T>: MemDbgImpl,
PhantomData<W>: MemDbgImpl,
PhantomData<S>: MemDbgImpl,
fn _mem_dbg_rec_on( &self, _memdbg_writer: &mut impl Write, _memdbg_total_size: usize, _memdbg_max_depth: usize, _memdbg_prefix: &mut String, _memdbg_is_last: bool, _memdbg_flags: DbgFlags, ) -> Result
fn _mem_dbg_depth_on( &self, writer: &mut impl Write, total_size: usize, max_depth: usize, prefix: &mut String, field_name: Option<&str>, is_last: bool, padded_size: usize, flags: DbgFlags, ) -> Result<(), Error>
Source§impl<T: ?Sized + ToSig<S>, W: ZeroCopy + Word, D, S: Sig, E> MemSize for VFunc<T, W, D, S, E>where
E: MemSize + ShardEdge<S, 3>,
u64: MemSize,
usize: MemSize,
D: MemSize + BitFieldSlice<W>,
PhantomData<T>: MemSize,
PhantomData<W>: MemSize,
PhantomData<S>: MemSize,
impl<T: ?Sized + ToSig<S>, W: ZeroCopy + Word, D, S: Sig, E> MemSize for VFunc<T, W, D, S, E>where
E: MemSize + ShardEdge<S, 3>,
u64: MemSize,
usize: MemSize,
D: MemSize + BitFieldSlice<W>,
PhantomData<T>: MemSize,
PhantomData<W>: MemSize,
PhantomData<S>: MemSize,
Source§impl<T: ?Sized + ToSig<S>, W: ZeroCopy + Word, D, S: Sig, E> SerializeInner for VFunc<T, W, D, S, E>where
E: SerializeInner + ShardEdge<S, 3>,
u64: SerializeInner,
usize: SerializeInner,
D: SerializeInner + BitFieldSlice<W>,
PhantomData<T>: SerializeInner,
PhantomData<W>: SerializeInner,
PhantomData<S>: SerializeInner,
<D as SerializeInner>::SerType: BitFieldSlice<W>,
<E as SerializeInner>::SerType: ShardEdge<S, 3>,
impl<T: ?Sized + ToSig<S>, W: ZeroCopy + Word, D, S: Sig, E> SerializeInner for VFunc<T, W, D, S, E>where
E: SerializeInner + ShardEdge<S, 3>,
u64: SerializeInner,
usize: SerializeInner,
D: SerializeInner + BitFieldSlice<W>,
PhantomData<T>: SerializeInner,
PhantomData<W>: SerializeInner,
PhantomData<S>: SerializeInner,
<D as SerializeInner>::SerType: BitFieldSlice<W>,
<E as SerializeInner>::SerType: ShardEdge<S, 3>,
Source§const IS_ZERO_COPY: bool
const IS_ZERO_COPY: bool
ZeroCopy
type has this constant set to false
serialization will panic.Source§const ZERO_COPY_MISMATCH: bool
const ZERO_COPY_MISMATCH: bool
#[zero_copy]
nor the attribute #[deep_copy]
was specified. It is checked at runtime, and if it is true
a warning will be issued, as the type could be zero-copy,
which would be more efficient.Source§type SerType = VFunc<T, W, <D as SerializeInner>::SerType, S, <E as SerializeInner>::SerType>
type SerType = VFunc<T, W, <D as SerializeInner>::SerType, S, <E as SerializeInner>::SerType>
Self
, but
in some cases, as for references to slices,
it is customized.Source§fn _serialize_inner(&self, backend: &mut impl WriteWithNames) -> Result<()>
fn _serialize_inner(&self, backend: &mut impl WriteWithNames) -> Result<()>
Source§impl<T: ?Sized + ToSig<S>, W: ZeroCopy + Word, D, S: Sig, E> TypeHash for VFunc<T, W, D, S, E>where
E: TypeHash + ShardEdge<S, 3>,
D: TypeHash + BitFieldSlice<W>,
PhantomData<T>: TypeHash,
PhantomData<W>: TypeHash,
PhantomData<S>: TypeHash,
impl<T: ?Sized + ToSig<S>, W: ZeroCopy + Word, D, S: Sig, E> TypeHash for VFunc<T, W, D, S, E>where
E: TypeHash + ShardEdge<S, 3>,
D: TypeHash + BitFieldSlice<W>,
PhantomData<T>: TypeHash,
PhantomData<W>: TypeHash,
PhantomData<S>: TypeHash,
Source§fn type_hash_val(&self, hasher: &mut impl Hasher)
fn type_hash_val(&self, hasher: &mut impl Hasher)
TypeHash::type_hash
on a value.Auto Trait Implementations§
impl<T, W, D, S, E> Freeze for VFunc<T, W, D, S, E>
impl<T, W, D, S, E> RefUnwindSafe for VFunc<T, W, D, S, E>where
E: RefUnwindSafe,
D: RefUnwindSafe,
T: RefUnwindSafe + ?Sized,
W: RefUnwindSafe,
S: RefUnwindSafe,
impl<T, W, D, S, E> Send for VFunc<T, W, D, S, E>
impl<T, W, D, S, E> Sync for VFunc<T, W, D, S, E>
impl<T, W, D, S, E> Unpin for VFunc<T, W, D, S, E>
impl<T, W, D, S, E> UnwindSafe for VFunc<T, W, D, S, E>
Blanket Implementations§
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, U> CastableInto<U> for Twhere
U: CastableFrom<T>,
impl<T, U> CastableInto<U> for Twhere
U: CastableFrom<T>,
Source§impl<T> Deserialize for T
impl<T> Deserialize for T
Source§fn deserialize_full(backend: &mut impl ReadNoStd) -> Result<T, Error>
fn deserialize_full(backend: &mut impl ReadNoStd) -> Result<T, Error>
Source§fn deserialize_eps(
backend: &[u8],
) -> Result<<T as DeserializeInner>::DeserType<'_>, Error>
fn deserialize_eps( backend: &[u8], ) -> Result<<T as DeserializeInner>::DeserType<'_>, Error>
Source§fn load_full(path: impl AsRef<Path>) -> Result<Self, Error>
fn load_full(path: impl AsRef<Path>) -> Result<Self, Error>
Source§impl<T> DowncastableFrom<T> for T
impl<T> DowncastableFrom<T> for T
Source§fn downcast_from(value: T) -> T
fn downcast_from(value: T) -> T
Source§impl<T, U> DowncastableInto<U> for Twhere
U: DowncastableFrom<T>,
impl<T, U> DowncastableInto<U> for Twhere
U: DowncastableFrom<T>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> MemDbg for Twhere
T: MemDbgImpl,
impl<T> MemDbg for Twhere
T: MemDbgImpl,
Source§fn mem_dbg(&self, flags: DbgFlags) -> Result<(), Error>
fn mem_dbg(&self, flags: DbgFlags) -> Result<(), Error>
Source§fn mem_dbg_on(
&self,
writer: &mut impl Write,
flags: DbgFlags,
) -> Result<(), Error>
fn mem_dbg_on( &self, writer: &mut impl Write, flags: DbgFlags, ) -> Result<(), Error>
core::fmt::Write
debug infos about the structure memory
usage, expanding all levels of nested structures.Source§fn mem_dbg_depth(&self, max_depth: usize, flags: DbgFlags) -> Result<(), Error>
fn mem_dbg_depth(&self, max_depth: usize, flags: DbgFlags) -> Result<(), Error>
mem_dbg
, but expanding only up to max_depth
levels of nested structures.Source§fn mem_dbg_depth_on(
&self,
writer: &mut impl Write,
max_depth: usize,
flags: DbgFlags,
) -> Result<(), Error>
fn mem_dbg_depth_on( &self, writer: &mut impl Write, max_depth: usize, flags: DbgFlags, ) -> Result<(), Error>
core::fmt::Write
debug infos about the structure memory
usage as mem_dbg_on
, but expanding only up to
max_depth
levels of nested structures.