#[repr(u32)]
pub enum BlockSizeRelation {
    Far,
    NearLt,
    NearEq,
    NearGt,
}
Expand description

A type to represent relation between two block sizes.

Because the core comparison method can only compare two block hashes with the same block size, we cannot compare two fuzzy hashes if their block sizes are not near enough.

There are three cases where we can perform actual block hash comparison:

  1. Equals (NearEq)
    bs_a == bs_b
  2. Less than (NearLt)
    bs_a < bs_b && bs_a * 2 == bs_b
  3. Greater than (NearGt)
    bs_a > bs_b && bs_a == bs_b * 2

This type represents those near cases (three variants) and the case which two fuzzy hashes cannot perform a block hash comparison, the far case (the Far variant).

In this crate, it can efficiently handle such relations by using the base-2 logarithms form of the block size (no multiplication required).

Variants§

§

Far

Two block sizes are far and a block hash comparison cannot be performed.

§

NearLt

Two block sizes are near and the block hash 2 (one with a larger block size) of the left side (of comparison) can be compared with the block hash 1 (one with a smaller block size) of the right side.

§

NearEq

Two block sizes are not just near but the same. We compare both block hashes with the other and take the maximum value for the output.

§

NearGt

Two block sizes are near and the block hash 1 (one with a smaller block size) of the left side (of comparison) can be compared with the block hash 2 (one with a larger block size) of the right side.

Implementations§

source§

impl BlockSizeRelation

source

pub fn is_near(&self) -> bool

Checks whether a given value denotes one of the three near cases.

Trait Implementations§

source§

impl Clone for BlockSizeRelation

source§

fn clone(&self) -> BlockSizeRelation

Returns a copy 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 BlockSizeRelation

source§

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

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

impl PartialEq<BlockSizeRelation> for BlockSizeRelation

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for BlockSizeRelation

source§

impl Eq for BlockSizeRelation

source§

impl StructuralEq for BlockSizeRelation

source§

impl StructuralPartialEq for BlockSizeRelation

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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, U> Into<U> for Twhere 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 Twhere T: Clone,

§

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 Twhere 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 Twhere 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.