#[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: NonZeroU64Implementations§
Source§impl DualHashKey
impl DualHashKey
Sourcepub const fn from_dual_bytes(high: &[u8], low: &[u8]) -> Option<Self>
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.
Sourcepub const fn from_dual_str(high: &str, low: &str) -> Option<Self>
pub const fn from_dual_str(high: &str, low: &str) -> Option<Self>
Creates a new DualHashKey from the pair of high and low strings.
Sourcepub const fn from_high_bytes(high: &[u8]) -> Option<Self>
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.
Sourcepub const fn from_high_str(high: &str) -> Option<Self>
pub const fn from_high_str(high: &str) -> Option<Self>
Creates a new DualHashKey from the high string, with the low-half zeroed.
Sourcepub const fn with_high_half_bytes(&self, high: &[u8]) -> Option<Self>
pub const fn with_high_half_bytes(&self, high: &[u8]) -> Option<Self>
Creates a copy with the high-half replaced.
Sourcepub const fn with_high_half_str(&self, high: &str) -> Option<Self>
pub const fn with_high_half_str(&self, high: &str) -> Option<Self>
Creates a copy with the high-half replaced.
Sourcepub const fn with_low_half_bytes(&self, low: &[u8]) -> Option<Self>
pub const fn with_low_half_bytes(&self, low: &[u8]) -> Option<Self>
Creates a copy with the low-half replaced.
Sourcepub const fn with_low_half_str(&self, low: &str) -> Option<Self>
pub const fn with_low_half_str(&self, low: &str) -> Option<Self>
Creates a copy with the low-half replaced.
Sourcepub const fn from_raw_dual(high: u32, low: u32) -> Option<Self>
pub const fn from_raw_dual(high: u32, low: u32) -> Option<Self>
Safely creates a new DualHashKey from two raw u32 values.
Sourcepub const fn from_raw_high(high: u32) -> Option<Self>
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.
Sourcepub const fn from_raw(hash: u64) -> Option<Self>
pub const fn from_raw(hash: u64) -> Option<Self>
Safely creates a new DualHashKey from a raw u64 value.
Sourcepub const unsafe fn from_raw_unchecked(hash: u64) -> Self
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.
Sourcepub const unsafe fn from_raw_dual_unchecked(high: u32, low: u32) -> Self
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.
Sourcepub const fn get_low_as_high(&self) -> Option<Self>
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.
Sourcepub const fn with_high_half_raw(&self, high: u32) -> Option<Self>
pub const fn with_high_half_raw(&self, high: u32) -> Option<Self>
Creates a copy with the high-half replaced.
Sourcepub const fn with_low_half_raw(&self, low: u32) -> Option<Self>
pub const fn with_low_half_raw(&self, low: u32) -> Option<Self>
Creates a copy with the low-half replaced.
Sourcepub const fn get_hash(&self) -> NonZeroU64
pub const fn get_hash(&self) -> NonZeroU64
Gets the wrapped hash value.
Sourcepub const fn get_hash_raw(&self) -> u64
pub const fn get_hash_raw(&self) -> u64
Gets the wrapped hash value as u64.
This is the same as dhk.get_hash().get().
Sourcepub const fn get_hash_high_half(&self) -> u32
pub const fn get_hash_high_half(&self) -> u32
Gets the high-half of the hash.
Sourcepub const fn get_hash_low_half(&self) -> u32
pub const fn get_hash_low_half(&self) -> u32
Gets the low-half of the hash.
Sourcepub const fn is_hash_low_half_set(&self) -> bool
pub const fn is_hash_low_half_set(&self) -> bool
Checks if the low-half of the hash has any of its bits set.
Sourcepub const fn is_hash_low_half_clear(&self) -> bool
pub const fn is_hash_low_half_clear(&self) -> bool
Checks if the low-half of the hash has none of its bits set.
Sourcepub const fn get_hash_low_half_min_raw(&self) -> u64
pub const fn get_hash_low_half_min_raw(&self) -> u64
Returns the hash with the low-half cleared.
Sourcepub const fn get_hash_low_half_max_raw(&self) -> u64
pub const fn get_hash_low_half_max_raw(&self) -> u64
Returns the hash with the low-half filled.
Sourcepub const fn get_hash_low_half_min(&self) -> Option<Self>
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.
Sourcepub const fn get_hash_low_half_max(&self) -> Self
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
impl Clone for DualHashKey
Source§fn clone(&self) -> DualHashKey
fn clone(&self) -> DualHashKey
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DualHashKey
impl Debug for DualHashKey
Source§impl Display for DualHashKey
impl Display for DualHashKey
Source§impl From<NonZero<u64>> for DualHashKey
impl From<NonZero<u64>> for DualHashKey
Source§fn from(hash: NonZeroU64) -> Self
fn from(hash: NonZeroU64) -> Self
Source§impl Hash for DualHashKey
Hash-implementation: Writes the hash via write_u64. That’s it.
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§impl Ord for DualHashKey
impl Ord for DualHashKey
Source§fn cmp(&self, other: &DualHashKey) -> Ordering
fn cmp(&self, other: &DualHashKey) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for DualHashKey
impl PartialEq for DualHashKey
Source§impl PartialOrd for DualHashKey
impl PartialOrd for DualHashKey
Source§impl TryFrom<&[u8]> for DualHashKey
impl TryFrom<&[u8]> for DualHashKey
Source§impl TryFrom<&str> for DualHashKey
impl TryFrom<&str> for DualHashKey
Source§impl TryFrom<u64> for DualHashKey
impl TryFrom<u64> for DualHashKey
impl Copy for DualHashKey
impl Eq for DualHashKey
impl IsEnabled for DualHashKey
nohash-hasher only.The DualHashKey is already a hash and must not be hashed again.