Struct sux::func::VFunc

source ·
pub struct VFunc<T: ?Sized + ToSig, O: ZeroCopy + SerializeInner + DeserializeInner + Word + IntoAtomic = usize, S: BitFieldSlice<O> = BitFieldVec<O>> { /* private fields */ }
Expand description

Static functions with 10%-11% space overhead for large key sets, fast parallel construction, and fast queries.

Instances of this structure are immutable; they are built using a VFuncBuilder, and can be serialized using ε-serde.

Implementations§

source§

impl<T: ?Sized + ToSig, O: ZeroCopy + SerializeInner + DeserializeInner + Word + IntoAtomic, S: BitFieldSlice<O>> VFunc<T, O, S>

source

pub fn get_by_sig(&self, sig: &[u64; 2]) -> O

Return the value associated with the given signature.

This method is mainly useful in the construction of compound functions.

source

pub fn get(&self, key: &T) -> O

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

Examples found in repository?
examples/bench_vfunc.rs (line 45)
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
fn main() -> Result<()> {
    env_logger::builder()
        .filter_level(log::LevelFilter::Info)
        .try_init()?;

    let mut pl = ProgressLogger::default();

    let args = Args::parse();

    if let Some(filename) = args.filename {
        let func = VFunc::<_>::load_mem(&args.func)?;
        let keys: Vec<_> = LineLender::from_path(filename)?
            .map_into_iter(|x| x.unwrap().to_owned())
            .take(args.n)
            .collect();
        pl.start("Querying...");
        for (i, key) in keys.iter().enumerate() {
            assert_eq!(i, func.get(key));
        }
        pl.done_with_count(keys.len());
    } else {
        let func = VFunc::<_>::load_mem(&args.func)?;
        pl.start("Querying...");
        for i in 0..args.n {
            assert_eq!(i, func.get(&i));
        }
        pl.done_with_count(args.n);
    }

    Ok(())
}
source

pub fn len(&self) -> usize

Return the number of keys in the function.

source

pub fn is_empty(&self) -> bool

Return whether the function has no keys.

Trait Implementations§

source§

impl<T: ?Sized + ToSig, O: ZeroCopy + SerializeInner + DeserializeInner + Word + IntoAtomic, S: BitFieldSlice<O>> CopyType for VFunc<T, O, S>

§

type Copy = Deep

source§

impl<T: ?Sized + ToSig, O: ZeroCopy + SerializeInner + DeserializeInner + Word + IntoAtomic, S> CopyType for VFunc<T, O, S>

§

type Copy = False

source§

impl<T: Debug + ?Sized + ToSig, O: Debug + ZeroCopy + SerializeInner + DeserializeInner + Word + IntoAtomic, S: Debug + BitFieldSlice<O>> Debug for VFunc<T, O, S>

source§

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

Formats the value using the given formatter. Read more
source§

impl<T: ?Sized + ToSig, O: ZeroCopy + SerializeInner + DeserializeInner + Word + IntoAtomic, S> DeserializeInner for VFunc<T, O, S>

source§

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

§

type DeserType<'epserde_desertype> = VFunc<T, O, <S as DeserializeInner>::DeserType<'epserde_desertype>>

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

fn _deserialize_eps_inner<'a>( backend: &mut SliceWithPos<'a> ) -> Result<Self::DeserType<'a>, Error>

source§

impl<T: ?Sized + ToSig, O: ZeroCopy + SerializeInner + DeserializeInner + Word + IntoAtomic, S> MemDbgImpl for VFunc<T, O, S>

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§

impl<T: ?Sized + ToSig, O: ZeroCopy + SerializeInner + DeserializeInner + Word + IntoAtomic, S> MemSize for VFunc<T, O, S>

source§

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

Return the (recursively computed) overall memory size of the structure in bytes.
source§

impl<T: ?Sized + ToSig + ReprHash, O: ZeroCopy + SerializeInner + DeserializeInner + Word + IntoAtomic + ReprHash, S: BitFieldSlice<O> + ReprHash> ReprHash for VFunc<T, O, S>

source§

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

Accumulate representional information in hasher assuming to be positioned at offset_of.
source§

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

Call ReprHash::repr_hash on a value.
source§

impl<T: ?Sized + ToSig, O: ZeroCopy + SerializeInner + DeserializeInner + Word + IntoAtomic, S> SerializeInner for VFunc<T, O, S>

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§

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

Serialize this structure using the given backend.
source§

impl<T: ?Sized + ToSig + TypeHash, O: ZeroCopy + SerializeInner + DeserializeInner + Word + IntoAtomic + TypeHash, S: BitFieldSlice<O> + TypeHash> TypeHash for VFunc<T, O, S>

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: ?Sized, O, S> Freeze for VFunc<T, O, S>
where S: Freeze,

§

impl<T: ?Sized, O, S> RefUnwindSafe for VFunc<T, O, S>

§

impl<T: ?Sized, O, S> Send for VFunc<T, O, S>
where S: Send, T: Send,

§

impl<T: ?Sized, O, S> Sync for VFunc<T, O, S>
where S: Sync, T: Sync,

§

impl<T: ?Sized, O, S> Unpin for VFunc<T, O, S>
where O: Unpin, S: Unpin, T: Unpin,

§

impl<T: ?Sized, O, S> UnwindSafe for VFunc<T, O, S>
where O: UnwindSafe, S: UnwindSafe, T: 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> 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>

Commodity 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> MemDbg for T
where T: MemDbgImpl,

source§

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

Write to stdout 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>

Write to a core::fmt::Write debug infos about the structure memory usage, expanding all levels of nested structures.
source§

fn mem_dbg_depth( &self, total_size: usize, max_depth: usize, flags: DbgFlags ) -> Result<(), Error>

Write to stdout debug infos about the structure memory usage, but expanding only up to max_depth levels of nested structures.
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, flags: DbgFlags ) -> Result<(), Error>

Write to a core::fmt::Write debug infos about the structure memory usage, 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.
§

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

source§

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

Serialize the type using the given WriteWithNames.

source§

fn serialize(&self, backend: &mut impl WriteNoStd) -> Result<usize, Error>

Serialize the type using the given backend.
source§

fn serialize_with_schema( &self, backend: &mut impl WriteNoStd ) -> Result<Schema, Error>

Serialize the type using the given backend and return a schema describing the data that has been written. Read more
source§

fn store(&self, path: impl AsRef<Path>) -> Result<(), Error>

Commodity method to serialize to a file.
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>,

§

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

§

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<T> DeepCopy for T
where T: CopyType<Copy = Deep>,