Skip to main content

RandomSlices

Struct RandomSlices 

Source
pub struct RandomSlices { /* private fields */ }
Expand description

Slice table indexed by u64 hash values.

A RandomSlices instance owns three parallel arrays: the ascending interval lower bounds, the per-interval sizes (kept for diagnostics), and the per-interval claimant names. All builders maintain the parallel-array invariant; do not construct this struct by hand.

Implementations§

Source§

impl RandomSlices

Source

pub fn from_uniform(claimants: &[&str]) -> Result<Self, RandomSlicesError>

Build an equal-sized partition for claimants. Each claimant gets an interval of u64::MAX / N values; the last claimant absorbs the rounding remainder so coverage is exact.

§Errors

Returns RandomSlicesError::EmptyClaimants when the list is empty and RandomSlicesError::DuplicateClaimant when two entries share a name.

§Examples
use dynomite::hashkit::random_slicing::RandomSlices;
let s = RandomSlices::from_uniform(&["a", "b", "c"]).unwrap();
assert_eq!(s.len(), 3);
Source

pub fn from_weights( weights: &[(String, f64)], decimal_digits: usize, ) -> Result<Self, RandomSlicesError>

Build a weighted partition. Each weight is rounded to decimal_digits places before normalising; the sum is then translated into per-claimant u64 sizes by floor(u64::MAX * w / sum). The last claimant absorbs the remainder so coverage is exact.

§Errors

Returns RandomSlicesError::EmptyClaimants, RandomSlicesError::DuplicateClaimant, or RandomSlicesError::InvalidWeight (for non-finite, negative, or all-zero rounded weights).

§Examples
use dynomite::hashkit::random_slicing::RandomSlices;
let s = RandomSlices::from_weights(
    &[("a".to_string(), 1.0), ("b".to_string(), 2.0)],
    2,
).unwrap();
assert_eq!(s.len(), 2);
Source

pub fn from_sizes(sizes: &[(String, u64)]) -> Result<Self, RandomSlicesError>

Build a partition from explicit (name, size) pairs.

The supplied sizes are taken at face value; the only transformation is bumping the tail interval up by the remainder when the sum is below u64::MAX. Sums above u64::MAX are rejected with RandomSlicesError::OversizedSizeSum.

§Errors

Returns RandomSlicesError::EmptyClaimants, RandomSlicesError::DuplicateClaimant, RandomSlicesError::ZeroInterval, or RandomSlicesError::OversizedSizeSum.

§Examples
use dynomite::hashkit::random_slicing::RandomSlices;
let s = RandomSlices::from_sizes(&[
    ("a".into(), 100),
    ("b".into(), 200),
]).unwrap();
assert_eq!(s.len(), 2);
Source

pub fn len(&self) -> usize

Number of claimants / intervals in the table.

§Examples
use dynomite::hashkit::random_slicing::RandomSlices;
assert_eq!(RandomSlices::from_uniform(&["a", "b"]).unwrap().len(), 2);
Source

pub fn is_empty(&self) -> bool

True when the table holds no claimants. The builders reject empty inputs, so this can only be observed via the (private) raw constructor; included for completeness behind clippy’s len lint.

§Examples
use dynomite::hashkit::random_slicing::RandomSlices;
assert!(!RandomSlices::from_uniform(&["a"]).unwrap().is_empty());
Source

pub fn claimant_for(&self, hash: u64) -> Option<&str>

Look up the claimant that owns hash.

Returns the borrowed claimant name. Returns None only when the table is empty (which the builders prevent).

§Examples
use dynomite::hashkit::random_slicing::RandomSlices;
let s = RandomSlices::from_uniform(&["a", "b"]).unwrap();
assert!(s.claimant_for(0).is_some());
Source

pub fn index_for(&self, hash: u64) -> Option<usize>

Look up the index of the claimant that owns hash.

Returns None only when the table is empty.

Source

pub fn claimants(&self) -> &[String]

Borrow the claimant list (parallel to Self::lower_bounds and Self::interval_sizes).

Source

pub fn lower_bounds(&self) -> &[u64]

Borrow the lower-bound array.

Source

pub fn interval_sizes(&self) -> &[u64]

Borrow the per-interval size array.

Source

pub fn intervals(&self) -> impl Iterator<Item = (&str, u64, u64)> + '_

Iterate (claimant, lower_bound, size) for diagnostics.

§Examples
use dynomite::hashkit::random_slicing::RandomSlices;
let s = RandomSlices::from_uniform(&["a", "b"]).unwrap();
let n = s.intervals().count();
assert_eq!(n, 2);

Trait Implementations§

Source§

impl Clone for RandomSlices

Source§

fn clone(&self) -> RandomSlices

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RandomSlices

Source§

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

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

impl PartialEq for RandomSlices

Source§

fn eq(&self, other: &RandomSlices) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for RandomSlices

Source§

impl StructuralPartialEq for RandomSlices

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,