NamespaceHasher

Struct NamespaceHasher 

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

A utility struct for namespacing keys using XXH3 hashing.

This ensures that keys are uniquely identified within a given namespace, even if they share the same suffix. By hashing both the namespace and key separately before combining them, it prevents unintended collisions.

§Example:

use simd_r_drive::utils::NamespaceHasher;

let hasher = NamespaceHasher::new(b"opt");
let namespaced_key = hasher.namespace(b"my_key");
assert_eq!(namespaced_key.len(), 16, "Namespaced key should be exactly 16 bytes");

Implementations§

Source§

impl NamespaceHasher

Source

pub fn new(prefix: &[u8]) -> Self

Creates a new NamespaceHasher with a given prefix.

The prefix itself is hashed using XXH3 to ensure a unique namespace identifier. This avoids collisions between different namespaces while keeping the hashing fast.

§Arguments
  • prefix: A byte slice representing the namespace prefix.
§Returns
  • A NamespaceHasher instance with a precomputed prefix hash.
Source

pub fn namespace(&self, key: &[u8]) -> Vec<u8>

Computes a namespaced key, returning it as a 16-byte vector.

The final namespaced key is derived by:

  1. Hashing the key separately to ensure uniqueness.
  2. Combining it with the precomputed namespace hash.
  3. Returning the concatenation of both hashes as a 16-byte key.

This ensures that:

  • Different namespaces do not generate overlapping keys.
  • Keys within a namespace remain uniquely identifiable.
§Arguments
  • key: A byte slice representing the key to be namespaced.
§Returns
  • A Vec<u8> containing the 16-byte namespaced key (8-byte prefix hash + 8-byte key hash).

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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