Struct VFunc

Source
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 a BitFieldVec<W> or a Box<[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 of W, thus forcing the number of bits to the number of bits of W, 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 possibly FuseLge3NoShards) 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 is FuseLge3Shards. For small sets of keys you might try FuseLge3NoShards, possibly coupled with [u64; 1] signatures. For functions with more than a few dozen billion keys, you might try FuseLge3FullSigs.

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>

Source

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

pub fn get(&self, key: impl Borrow<T>) -> W

Returns the value associated with the given key, or a random value if the key is not present.

Source

pub fn len(&self) -> usize

Returns the number of keys in the function.

Source

pub fn is_empty(&self) -> bool

Returns whether the function has no keys.

Source§

impl<T: ?Sized + ToSig<S>, W: ZeroCopy + Word, S: Sig, E: ShardEdge<S, 3>> VFunc<T, W, BitFieldVec<W>, S, E>

Source

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.

Source

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>

Source§

fn align_hash(hasher: &mut impl Hasher, _offset_of: &mut usize)

Accumulate alignment information in hasher assuming to be positioned at offset_of.
Source§

fn align_hash_val(&self, hasher: &mut impl Hasher, offset_of: &mut usize)

Call 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>

Source§

impl<T: ?Sized + ToSig<S>, W: ZeroCopy + Word, D, S: Sig, E> CopyType for VFunc<T, W, D, S, E>

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>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
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>,

Source§

type DeserType<'epserde_desertype> = VFunc<T, W, <D as DeserializeInner>::DeserType<'epserde_desertype>, S, <E as DeserializeInner>::DeserType<'epserde_desertype>>

The deserialization type associated with this type. It can be retrieved conveniently with the alias DeserType.
Source§

fn _deserialize_full_inner( backend: &mut impl ReadWithPos, ) -> Result<Self, Error>

Source§

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>

Source§

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

Source§

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>

Source§

fn mem_size(&self, _memsize_flags: SizeFlags) -> usize

Returns the (recursively computed) overall memory size of the structure in bytes.
Source§

impl<T: ?Sized + ToSig<S>, W: ZeroCopy + Word, D, S: Sig, E> SerializeInner for VFunc<T, W, D, S, E>

Source§

const IS_ZERO_COPY: bool

Inner constant used by the derive macros to keep track recursively of whether the type satisfies the conditions for being zero-copy. It is checked at runtime against the trait implemented by the type, and if a ZeroCopy type has this constant set to false serialization will panic.
Source§

const ZERO_COPY_MISMATCH: bool

Inner constant used by the derive macros to keep track of whether all fields of a type are zero-copy but neither the attribute #[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>

This is the type that will be written in the header of the file, and thus the type that will be deserialized. In most cases it is Self, but in some cases, as for references to slices, it is customized.
Source§

fn _serialize_inner(&self, backend: &mut impl WriteWithNames) -> Result<()>

Serialize this structure using the given backend.
Source§

impl<T: ?Sized + ToSig<S>, W: ZeroCopy + Word, D, S: Sig, E> TypeHash for VFunc<T, W, D, S, E>

Source§

fn type_hash(hasher: &mut impl Hasher)

Accumulate type information in hasher.
Source§

fn type_hash_val(&self, hasher: &mut impl Hasher)

Call TypeHash::type_hash on a value.

Auto Trait Implementations§

§

impl<T, W, D, S, E> Freeze for VFunc<T, W, D, S, E>
where E: Freeze, D: Freeze, T: ?Sized,

§

impl<T, W, D, S, E> RefUnwindSafe for VFunc<T, W, D, S, E>

§

impl<T, W, D, S, E> Send for VFunc<T, W, D, S, E>
where D: Send, T: Send + ?Sized, S: Send,

§

impl<T, W, D, S, E> Sync for VFunc<T, W, D, S, E>
where D: Sync, T: Sync + ?Sized, S: Sync,

§

impl<T, W, D, S, E> Unpin for VFunc<T, W, D, S, E>
where E: Unpin, D: Unpin, T: Unpin + ?Sized, W: Unpin, S: Unpin,

§

impl<T, W, D, S, E> UnwindSafe for VFunc<T, W, D, S, E>

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> CastableFrom<T> for T

Source§

fn cast_from(value: T) -> T

Call Self as W
Source§

impl<T, U> CastableInto<U> for T
where U: CastableFrom<T>,

Source§

fn cast(self) -> U

Call W::cast_from(self)
Source§

impl<T> Deserialize for T

Source§

fn deserialize_full(backend: &mut impl ReadNoStd) -> Result<T, Error>

Fully deserialize a structure of this type from the given backend.
Source§

fn deserialize_eps( backend: &[u8], ) -> Result<<T as DeserializeInner>::DeserType<'_>, Error>

ε-copy deserialize a structure of this type from the given backend.
Source§

fn load_full(path: impl AsRef<Path>) -> Result<Self, Error>

Convenience method to fully deserialize from a file.
Source§

fn load_mem<'a>( path: impl AsRef<Path>, ) -> Result<MemCase<Self::DeserType<'a>>, Error>

Load a file into heap-allocated memory and ε-deserialize a data structure from it, returning a MemCase containing the data structure and the memory. Excess bytes are zeroed out. Read more
Source§

fn load_mmap<'a>( path: impl AsRef<Path>, flags: Flags, ) -> Result<MemCase<Self::DeserType<'a>>, Error>

Load a file into mmap()-allocated memory and ε-deserialize a data structure from it, returning a MemCase containing the data structure and the memory. Excess bytes are zeroed out. Read more
Source§

fn mmap<'a>( path: impl AsRef<Path>, flags: Flags, ) -> Result<MemCase<Self::DeserType<'a>>, Error>

Memory map a file and ε-deserialize a data structure from it, returning a MemCase containing the data structure and the memory mapping. Read more
Source§

impl<T> DowncastableFrom<T> for T

Source§

fn downcast_from(value: T) -> T

Truncate the current UnsignedInt to a possibly smaller size
Source§

impl<T, U> DowncastableInto<U> for T
where U: DowncastableFrom<T>,

Source§

fn downcast(self) -> U

Call W::downcast_from(self)
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> MemDbg for T
where T: MemDbgImpl,

Source§

fn mem_dbg(&self, flags: DbgFlags) -> Result<(), Error>

Writes to stderr debug infos about the structure memory usage, expanding all levels of nested structures.
Source§

fn mem_dbg_on( &self, writer: &mut impl Write, flags: DbgFlags, ) -> Result<(), Error>

Writes to a 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>

Writes to stderr debug infos about the structure memory usage as 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>

Writes to a 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.
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> Splat<T> for T

Source§

fn splat(value: T) -> T

Source§

impl<T> To<T> for T

Source§

fn to(self) -> T

Source§

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

Source§

type Error = Infallible

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

impl<T> UpcastableFrom<T> for T

Source§

fn upcast_from(value: T) -> T

Extend the current UnsignedInt to a possibly bigger size.
Source§

impl<T, U> UpcastableInto<U> for T
where U: UpcastableFrom<T>,

Source§

fn upcast(self) -> U

Call W::upcast_from(self)
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeepCopy for T
where T: CopyType<Copy = Deep>,