DualHashKey

Struct DualHashKey 

Source
#[repr(transparent)]
pub struct DualHashKey { pub hash: NonZeroU64, }
Expand description

A 64-bit key made of two hashes, whose raw value is never zero.

The HIGH-half source should be a superset-or-parent of the LOW-half source,
such that any ORDEREDMAP<DualHashKey, _> can be walked in hierarchical order,
by performing range-queries using the Self::get_hash_low_half_min and Self::get_hash_low_half_max functions.

For example, passing in root/mid/low as HIGH and root/mid/low/name as LOW, results in a dual-hash of E05F2E55.0CB0216D.

Print formats:

  • Display: DualHashKey({HIGH:0>8X}.{LOW:0>8X})
  • Debug: {HIGH:0>8X}.{LOW:0>8X}

Fields§

§hash: NonZeroU64

Implementations§

Source§

impl DualHashKey

Source

pub const fn from_dual_bytes(high: &[u8], low: &[u8]) -> Option<Self>

Creates a new DualHashKey from the pair of high and low sequences of bytes.

Source

pub const fn from_dual_str(high: &str, low: &str) -> Option<Self>

Creates a new DualHashKey from the pair of high and low strings.

Source

pub const fn from_high_bytes(high: &[u8]) -> Option<Self>

Creates a new DualHashKey from the high sequence of bytes, with the low-half zeroed.

Source

pub const fn from_high_str(high: &str) -> Option<Self>

Creates a new DualHashKey from the high string, with the low-half zeroed.

Source

pub const fn with_high_half_bytes(&self, high: &[u8]) -> Option<Self>

Creates a copy with the high-half replaced.

Source

pub const fn with_high_half_str(&self, high: &str) -> Option<Self>

Creates a copy with the high-half replaced.

Source

pub const fn with_low_half_bytes(&self, low: &[u8]) -> Option<Self>

Creates a copy with the low-half replaced.

Source

pub const fn with_low_half_str(&self, low: &str) -> Option<Self>

Creates a copy with the low-half replaced.

Source

pub const fn from_raw_dual(high: u32, low: u32) -> Option<Self>

Safely creates a new DualHashKey from two raw u32 values.

Source

pub const fn from_raw_high(high: u32) -> Option<Self>

Safely creates a new DualHashKey from a raw u32 value for the high-half, leaving the low-half zeroed out.

Source

pub const fn from_raw(hash: u64) -> Option<Self>

Safely creates a new DualHashKey from a raw u64 value.

Source

pub const unsafe fn from_raw_unchecked(hash: u64) -> Self

Directly creates a new DualHashKey from a raw u64 value.

§Safety

This function is safe to call if-and-only-if the provided hash value is non-zero.

Source

pub const unsafe fn from_raw_dual_unchecked(high: u32, low: u32) -> Self

Directly creates a new DualHashKey from two raw u32 values.

§Safety

This function is safe to call if-and-only-if at least one of the provided values is non-zero.

Source

pub const fn swapped(&self) -> Self

Swaps the low and high halfes.

Source

pub const fn get_low_as_high(&self) -> Option<Self>

Returns a new DualHashKey with the low-half of the current key as high-half; since the low-half may be all-zero, this may return None.

Source

pub const fn with_high_half_raw(&self, high: u32) -> Option<Self>

Creates a copy with the high-half replaced.

Source

pub const fn with_low_half_raw(&self, low: u32) -> Option<Self>

Creates a copy with the low-half replaced.

Source

pub const fn get_hash(&self) -> NonZeroU64

Gets the wrapped hash value.

Source

pub const fn get_hash_raw(&self) -> u64

Gets the wrapped hash value as u64.

This is the same as dhk.get_hash().get().

Source

pub const fn get_hash_high_half(&self) -> u32

Gets the high-half of the hash.

Source

pub const fn get_hash_low_half(&self) -> u32

Gets the low-half of the hash.

Source

pub const fn is_hash_low_half_set(&self) -> bool

Checks if the low-half of the hash has any of its bits set.

Source

pub const fn is_hash_low_half_clear(&self) -> bool

Checks if the low-half of the hash has none of its bits set.

Source

pub const fn get_hash_low_half_min_raw(&self) -> u64

Returns the hash with the low-half cleared.

Source

pub const fn get_hash_low_half_max_raw(&self) -> u64

Returns the hash with the low-half filled.

Source

pub const fn get_hash_low_half_min(&self) -> Option<Self>

Returns the hash with the low-half cleared.

Since this may result in an all-zero value, an Option<DualHashKey> is returned.

Source

pub const fn get_hash_low_half_max(&self) -> Self

Returns the hash with the low-half filled.

Since the low-half is filled with bits, making the DualHashKeys value non-zero, this method can never fail.

Trait Implementations§

Source§

impl Clone for DualHashKey

Source§

fn clone(&self) -> DualHashKey

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for DualHashKey

Source§

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

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

impl Display for DualHashKey

Source§

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

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

impl From<NonZero<u64>> for DualHashKey

Source§

fn from(hash: NonZeroU64) -> Self

Converts to this type from the input type.
Source§

impl Hash for DualHashKey

Hash-implementation: Writes the hash via write_u64. That’s it.

One should use a passthru/nohash-hasher when using the DualHashKey.

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for DualHashKey

Source§

fn cmp(&self, other: &DualHashKey) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for DualHashKey

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 PartialOrd for DualHashKey

Source§

fn partial_cmp(&self, other: &DualHashKey) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl TryFrom<&[u8]> for DualHashKey

Source§

type Error = &'static str

The type returned in the event of a conversion error.
Source§

fn try_from(value: &[u8]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&str> for DualHashKey

Source§

type Error = &'static str

The type returned in the event of a conversion error.
Source§

fn try_from(value: &str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<u64> for DualHashKey

Source§

type Error = &'static str

The type returned in the event of a conversion error.
Source§

fn try_from(value: u64) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Copy for DualHashKey

Source§

impl Eq for DualHashKey

Source§

impl IsEnabled for DualHashKey

Available on crate feature nohash-hasher only.

The DualHashKey is already a hash and must not be hashed again.

Source§

impl StructuralPartialEq for DualHashKey

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<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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.