#[repr(u32)]
pub enum BlockSizeRelation { NearLt = 0, NearEq = 1, NearGt = 2, Far = 3, }
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).

A value of this type can be retrieved by using block_size::compare_sizes() or FuzzyHashData::compare_block_sizes().

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

Compatibility Note

Since the version 0.3, the representation of this enum will not be specified as specific representation of this enum is not important.

Variants§

§

NearLt = 0

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 = 1

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 = 2

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.

§

Far = 3

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

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

§

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

§

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

§

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.