Struct ssdeep::FuzzyHashData
source · #[repr(align(8))]pub struct FuzzyHashData<const S1: usize, const S2: usize, const NORM: bool>where
BlockHashSize<S1>: ConstrainedBlockHashSize,
BlockHashSize<S2>: ConstrainedBlockHashSize,
BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,{ /* private fields */ }Expand description
An efficient fixed size fuzzy hash representation.
Fuzzy Hash Internals
A fuzzy hash consists of four parts:
-
Block size (reciprocal of average piece-splitting probability per byte)
-
Block hash 1. 6-bit hash per “piece”, variable length up to
BlockHash::FULL_SIZE.Average piece-splitting probability is given as
1/block_size. -
Block hash 2. 6-bit hash per “piece”, variable length up to either
BlockHash::HALF_SIZE(truncated / short / regular) orBlockHash::FULL_SIZE(non-truncated / long).
Average piece-splitting probability is given as
1/block_size/2). -
(optional) Input file name, which is ignored by the parser on this type.
This struct stores first three parts of a fuzzy hash.
You can see the following figure for an example:
196608:DfiQF5UWAC2qctjBemsqz7yHlHr4bMCE2J8Y:jBp/Fqz7mlHZCE2J8Y,"/usr/local/bin/rustc"
\____/|\__________________________________/|\________________/|\____________________/
| | Block hash 1 | Block hash 2 | File name (optional)
| | | |
| +-- (sep:colon) +-- (sep:colon) +-- (sep,comma (optional))
|
+-- Block size
Block Size
In an example above, 1 / 196 608 is the average probability for piece-splitting per byte on the block hash 1. On the block hash 2, the probability is 1 / 393 216 per byte, the half of the probability on the block hash 1.
Because ssdeep uses a 32-bit hash function to decide whether to perform a piece-splitting, this probability will get inaccurate as the block size gets larger.
There is an important property of the block size: all valid block sizes
can be represented as BlockSize::MIN * 2n (n ≧ 0).
In this crate, the block size is stored as n (the base 2 logarithm
form of the block size) for higher efficiency.
log_block_size() method returns this raw
representation. If you need an actual block size as used in the string
representation, block_size() can be used instead.
Block Hashes
A fuzzy hash has two block hashes (1 and 2).
They are variable length fields which stores array of 6-bit “piece” hash values (represented as Base64 characters in the string representaion and internally stored as Base64 indices).
Relations with Block Size
The reason a fuzzy hash having two block hashes is, to enable comparing fuzzy hashes with similar block sizes (but not too far).
In principle, we can only compare block hashes with the same block size directly. Think following fuzzy hash for example:
6144:SIsMYod+X3oI+YnsMYod+X3oI+YZsMYod+X3oI+YLsMYod+X3oI+YQ:Z5d+X395d+X3X5d+X315d+X3+
\____________________________________________________/ \_______________________/
Block hash 1 Block hash 2
(effective block size: 6144) (effective block size: 12288)
[*] 12288 == 6144 * 2
You can easily compare with another fuzzy hash with the same block size (but actual block hash similarity scoring only occurs after checking common substring).
Unaligned:
[A] 6144:SIsMYod+X3oI+YnsMYod+X3oI+YZsMYod+X3oI+YLsMYod+X3oI+YQ:Z5d+X395d+X3X5d+X315d+X3+
[B] 6144:SAsMYod+X3oI+YEWnnsMYod+X3oI+Y5sMYod+X3oI+YLsMYod+X3oI+YQ:H5d+X36WnL5d+X3v5d+X315d+X3+
Aligned:
[A] 6144:SIsMYod+X3oI+YnsMYod+X3oI+YZsMYod+X3oI+YLsMYod+X3oI+YQ :Z5d+X395d+X3X5d+X315d+X3+
[B] 6144:SAsMYod+X3oI+YEWnnsMYod+X3oI+Y5sMYod+X3oI+YLsMYod+X3oI+YQ:H5d+X36WnL5d+X3v5d+X315d+X3+
\_______________________________________________________/ \__________________________/
Comparison 1 Comparison 2
(score([A1], [B1], 6144) = 94) (score([A2], [B2], 12288) = 85)
score_final([A], [B], 6144) = max(94, 85) = 94
The final similarity score is the maximum of two block hash comparisons
(note that score function on small block sizes will cap the score to
prevent exaggeration of matches).
If you have two fuzzy hashes with different block sizes but they are near enough, we can still perform a block hash comparison.
Unaligned:
[A] 3072:S+IiyfkMY+BES09JXAnyrZalI+YuyfkMY+BES09JXAnyrZalI+YQ:S+InsMYod+X3oI+YLsMYod+X3oI+YQ
[B] 6144:SIsMYod+X3oI+YnsMYod+X3oI+YZsMYod+X3oI+YLsMYod+X3oI+YQ:Z5d+X395d+X3X5d+X315d+X3+
[C] 12288:Z5d+X3pz5d+X3985d+X3X5d+X315d+X3+:1+Jr+d++H+5+e
Aligned:
[A] 3072 :S+IiyfkMY+BES09JXAnyrZalI+YuyfkMY+BES09JXAnyrZalI+YQ:S+InsMYod+X3oI+YLsMYod+X3oI+YQ
[B] 6144 : SIsMYod+X3oI+YnsMYod+X3oI+YZsMYod+X3oI+YLsMYod+X3oI+YQ:Z5d+X395d+X3X5d+X315d+X3+
[C] 12288: Z5d+X3pz5d+X3985d+X3X5d+X315d+X3+:1+Jr+d++H+5+e
\__________________________________________________/ \____________________________________________________/ \_______________________________/ \___________/
Eff.B.S.=3072 Eff.B.S.=6144 Eff.B.S.=12288 Eff.B.S.=24576
Comparison between [A2] and [B1] Comparison between [B2] and [C1]
(score([A2], [B1], 6144) = 72) (score([B2], [C1], 12288) = 88)
score_final([A], [B], 3072) = score([A2], [B1], 6144) = 72
score_final([B], [C], 6144) = score([B2], [C1], 12288) = 88
score_final([A], [C], 3072) = 0 (since there's no block hashes to compare)
Such cases are handled with BlockSizeRelation and BlockSize
utility functions. We can outline the relation in the table below.
Note that each block size is denoted as
“Actual block size (block size in base 2 logarithm)”.
Left (lhs) | Right (rhs) | Relation |
|---|---|---|
| 3072 (10) | 6144 (11) | NearLt |
| 6144 (11) | 3072 (10) | NearGt |
| 6144 (11) | 6144 (11) | NearEq |
| 6144 (11) | 12288 (12) | NearLt |
| 12288 (12) | 6144 (11) | NearGt |
| 3072 (10) | 12288 (12) | Far |
For highly optimized clustering applications, being aware of the block size relation will be important.
See also: BlockSizeRelation
Normalization
To prevent exaggerating the comparison score from repeating patterns,
ssdeep processes each block hash before comparison so that a sequence
consisting of the same character longer than
BlockHash::MAX_SEQUENCE_SIZE cannot exist.
For instance, after processing a block hash 122333444455555, it is
converted to 122333444555 (four 4s and five 5s are shortened into
three 4s and three 5s because BlockHash::MAX_SEQUENCE_SIZE is
defined to be three (3)).
In this crate, this process is called normalization.
ssdeep normally generates (as well as Generator) not
normalized, raw fuzzy hashes. So, making a distinction between normalized
and raw forms are important.
Truncation
ssdeep normally generates (as well as Generator)
truncated fuzzy hashes. In the truncated fuzzy hash, length of block hash
2 is limited to BlockHash::HALF_SIZE, the half of the maximum length of
block hash 1 (BlockHash::FULL_SIZE).
While libfuzzy allows generating non-truncated, long fuzzy hashes, they are
typically useless. So, most operations are performed in short, truncated
fuzzy hashes by default. Short variants of FuzzyHashData is smaller
than longer variants so it can be used to reduce memory footprint.
Implementations§
source§impl<const S1: usize, const S2: usize> FuzzyHashData<S1, S2, true>where
BlockHashSize<S1>: ConstrainedBlockHashSize,
BlockHashSize<S2>: ConstrainedBlockHashSize,
BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
impl<const S1: usize, const S2: usize> FuzzyHashData<S1, S2, true>where BlockHashSize<S1>: ConstrainedBlockHashSize, BlockHashSize<S2>: ConstrainedBlockHashSize, BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
Additional implementation for normalized fuzzy hashes, enabling comparison between two fuzzy hashes directly.
sourcepub fn compare(&self, other: impl AsRef<Self>) -> u32
pub fn compare(&self, other: impl AsRef<Self>) -> u32
Compare two fuzzy hashes and retrieves the similarity score.
sourcepub unsafe fn compare_unequal_unchecked(&self, other: impl AsRef<Self>) -> u32
Available on crate feature unsafe only.
pub unsafe fn compare_unequal_unchecked(&self, other: impl AsRef<Self>) -> u32
unsafe only.Compare two fuzzy hashes assuming both are different.
Safety
selfandothermust be different.
If the condition above is not satisfied, it will return meaningless score.
sourcepub fn compare_unequal(&self, other: impl AsRef<Self>) -> u32
pub fn compare_unequal(&self, other: impl AsRef<Self>) -> u32
SLOW: Compare two fuzzy hashes assuming both are different.
Usage Constraints
selfandothermust be different.
Performance Consideration
This method’s performance is not good enough (because of constraint checking).
Use those instead:
compare(safe Rust)compare_unequal_unchecked(unsafe Rust)
source§impl<const S1: usize, const S2: usize, const NORM: bool> FuzzyHashData<S1, S2, NORM>where
BlockHashSize<S1>: ConstrainedBlockHashSize,
BlockHashSize<S2>: ConstrainedBlockHashSize,
BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
impl<const S1: usize, const S2: usize, const NORM: bool> FuzzyHashData<S1, S2, NORM>where BlockHashSize<S1>: ConstrainedBlockHashSize, BlockHashSize<S2>: ConstrainedBlockHashSize, BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
Implementation for all variants of fuzzy hashes.
Constants and methods below are available on all variants of fuzzy hashes.
sourcepub const MAX_BLOCK_HASH_SIZE_1: usize = S1
pub const MAX_BLOCK_HASH_SIZE_1: usize = S1
The maximum size of the block hash 1 part.
This value should be always BlockHash::FULL_SIZE.
sourcepub const MAX_BLOCK_HASH_SIZE_2: usize = S2
pub const MAX_BLOCK_HASH_SIZE_2: usize = S2
The maximum size of the block hash 2 part.
This value should be either
BlockHash::HALF_SIZE or BlockHash::FULL_SIZE.
sourcepub const IS_NORMALIZED_FORM: bool = NORM
pub const IS_NORMALIZED_FORM: bool = NORM
Denotes whether the fuzzy type only contains a normalized form.
sourcepub const IS_LONG_FORM: bool = _
pub const IS_LONG_FORM: bool = _
Denotes whether the fuzzy type can contain a non-truncated fuzzy hash.
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new fuzzy hash object with the empty contents.
This is equivalent to the fuzzy hash string 3::.
sourcepub unsafe fn init_from_internals_raw_unchecked(
&mut self,
log_block_size: u8,
block_hash_1: &[u8; S1],
block_hash_2: &[u8; S2],
block_hash_1_len: u8,
block_hash_2_len: u8
)
Available on crate feature unsafe only.
pub unsafe fn init_from_internals_raw_unchecked( &mut self, log_block_size: u8, block_hash_1: &[u8; S1], block_hash_2: &[u8; S2], block_hash_1_len: u8, block_hash_2_len: u8 )
unsafe only.Initialize the fuzzy hash object with internal contents (raw).
Safety
- Valid range of
block_hash_1andblock_hash_2must consist of valid Base64 indices. - Invalid range of
block_hash_1andblock_hash_2must be zeroes. block_hash_1_lenandblock_hash_2_lenmust have valid length.log_block_sizemust hold the valid base 2 logarithm form of the block size.- On the normalized variant, contents of
block_hash_1andblock_hash_2must be normalized.
If they are not satisfied, the resulting object will be corrupted.
sourcepub fn init_from_internals_raw(
&mut self,
log_block_size: u8,
block_hash_1: &[u8; S1],
block_hash_2: &[u8; S2],
block_hash_1_len: u8,
block_hash_2_len: u8
)
pub fn init_from_internals_raw( &mut self, log_block_size: u8, block_hash_1: &[u8; S1], block_hash_2: &[u8; S2], block_hash_1_len: u8, block_hash_2_len: u8 )
Initialize the fuzzy hash object with internal contents (raw).
Because this function assumes that you know the fuzzy hash internals, it panics when you fail to satisfy fuzzy hash constraints.
Usage Constraints
- Valid range of
block_hash_1andblock_hash_2must consist of valid Base64 indices. - Invalid range of
block_hash_1andblock_hash_2must be zeroes. block_hash_1_lenandblock_hash_2_lenmust have valid length.log_block_sizemust hold the valid base 2 logarithm form of the block size.- On the normalized variant, contents of
block_hash_1andblock_hash_2must be normalized.
sourcepub unsafe fn new_from_internals_raw_unchecked(
log_block_size: u8,
block_hash_1: &[u8; S1],
block_hash_2: &[u8; S2],
block_hash_1_len: u8,
block_hash_2_len: u8
) -> Self
Available on crate feature unsafe only.
pub unsafe fn new_from_internals_raw_unchecked( log_block_size: u8, block_hash_1: &[u8; S1], block_hash_2: &[u8; S2], block_hash_1_len: u8, block_hash_2_len: u8 ) -> Self
unsafe only.Creates a new fuzzy hash object with internal contents (raw).
Safety
- Valid range of
block_hash_1andblock_hash_2must consist of valid Base64 indices. - Invalid range of
block_hash_1andblock_hash_2must be zeroes. block_hash_1_lenandblock_hash_2_lenmust have valid length.log_block_sizemust hold the valid base 2 logarithm form of the block size.- On the normalized variant, contents of
block_hash_1andblock_hash_2must be normalized.
If they are not satisfied, the resulting object will be corrupted.
sourcepub fn new_from_internals_raw(
log_block_size: u8,
block_hash_1: &[u8; S1],
block_hash_2: &[u8; S2],
block_hash_1_len: u8,
block_hash_2_len: u8
) -> Self
pub fn new_from_internals_raw( log_block_size: u8, block_hash_1: &[u8; S1], block_hash_2: &[u8; S2], block_hash_1_len: u8, block_hash_2_len: u8 ) -> Self
Creates a new fuzzy hash object with internal contents (raw).
Because this function assumes that you know the fuzzy hash internals, it panics when you fail to satisfy fuzzy hash constraints.
Usage Constraints
- Valid range of
block_hash_1andblock_hash_2must consist of valid Base64 indices. - Invalid range of
block_hash_1andblock_hash_2must be zeroes. block_hash_1_lenandblock_hash_2_lenmust have valid length.log_block_sizemust hold the valid base 2 logarithm form of the block size.- On the normalized variant, contents of
block_hash_1andblock_hash_2must be normalized.
sourcepub unsafe fn new_from_internals_unchecked(
block_size: u32,
block_hash_1: &[u8],
block_hash_2: &[u8]
) -> Self
Available on crate feature unsafe only.
pub unsafe fn new_from_internals_unchecked( block_size: u32, block_hash_1: &[u8], block_hash_2: &[u8] ) -> Self
unsafe only.Creates a new fuzzy hash object with internal contents.
Safety
block_hash_1andblock_hash_2must have valid length.block_hash_1andblock_hash_2must consist of valid Base64 indices.block_sizemust hold a valid block size.- On the normalized variant, contents of
block_hash_1andblock_hash_2must be normalized.
If they are not satisfied, the resulting object will be corrupted.
sourcepub fn new_from_internals(
block_size: u32,
block_hash_1: &[u8],
block_hash_2: &[u8]
) -> Self
pub fn new_from_internals( block_size: u32, block_hash_1: &[u8], block_hash_2: &[u8] ) -> Self
Creates a new fuzzy hash object with internal contents.
Because this function assumes that you know the fuzzy hash internals, it panics when you fail to satisfy fuzzy hash constraints.
Usage Constraints
block_hash_1andblock_hash_2must have valid length.block_hash_1andblock_hash_2must consist of valid Base64 indices.block_sizemust hold a valid block size.- On the normalized variant, contents of
block_hash_1andblock_hash_2must be normalized.
sourcepub fn log_block_size(&self) -> u8
pub fn log_block_size(&self) -> u8
The base 2 logarithm form of the fuzzy hash’s block size.
See also: “Block Size” section of FuzzyHashData
sourcepub fn block_size(&self) -> u32
pub fn block_size(&self) -> u32
The block size of the fuzzy hash.
sourcepub fn block_hash_1(&self) -> &[u8] ⓘ
pub fn block_hash_1(&self) -> &[u8] ⓘ
A reference to the block hash 1.
Safety Tips
You cannot modify a fuzzy hash while block hashes are borrowed through
block_hash_1 or
block_hash_2.
let mut hash = ssdeep::FuzzyHash::from_str("3:aaaa:bbbb").unwrap();
let bh1 = hash.block_hash_1();
hash.normalize_in_place(); // <- ERROR: because block hash 1 is borrowed.
// If normalize_in_place succeeds, bh1 will hold an invalid slice
// because block hash 1 is going to be length 3 after the normalization.
assert_eq!(bh1.len(), 4);sourcepub fn block_hash_1_as_array(&self) -> &[u8; S1]
pub fn block_hash_1_as_array(&self) -> &[u8; S1]
A reference to the block hash 1 (in fixed size array).
Elements that are not a part of the block hash are filled with zeroes.
See also: block_hash_1
sourcepub fn block_hash_1_len(&self) -> usize
pub fn block_hash_1_len(&self) -> usize
The length of the block hash 1.
sourcepub fn block_hash_2(&self) -> &[u8] ⓘ
pub fn block_hash_2(&self) -> &[u8] ⓘ
A reference to the block hash 2.
Safety Tips
You cannot modify a fuzzy hash while block hashes are borrowed through
block_hash_1 or
block_hash_2.
let mut hash = ssdeep::FuzzyHash::from_str("3:aaaa:bbbb").unwrap();
let bh2 = hash.block_hash_2();
hash.normalize_in_place(); // <- ERROR: because block hash 2 is borrowed.
// If normalize_in_place succeeds, bh2 will hold an invalid slice
// because block hash 2 is going to be length 3 after the normalization.
assert_eq!(bh2.len(), 4);sourcepub fn block_hash_2_as_array(&self) -> &[u8; S2]
pub fn block_hash_2_as_array(&self) -> &[u8; S2]
A reference to the block hash 2 (in fixed size array).
Elements that are not a part of the block hash are filled with zeroes.
See also: block_hash_2
sourcepub fn block_hash_2_len(&self) -> usize
pub fn block_hash_2_len(&self) -> usize
The length of the block hash 2.
sourcepub fn len_in_str(&self) -> usize
pub fn len_in_str(&self) -> usize
Length of this fuzzy hash in the string representation.
This is the exact size (bytes and characters) required to store the string representation corresponding this fuzzy hash object.
sourcepub const MAX_LEN_IN_STR: usize = _
pub const MAX_LEN_IN_STR: usize = _
The maximum length in the string representation.
sourcepub fn to_string(&self) -> String
Available on crate feature alloc only.
pub fn to_string(&self) -> String
alloc only.Converts the fuzzy hash to the string.
sourcepub fn store_into_bytes(
&self,
buffer: &mut [u8]
) -> Result<(), FuzzyHashOperationError>
pub fn store_into_bytes( &self, buffer: &mut [u8] ) -> Result<(), FuzzyHashOperationError>
Store string representation of the fuzzy hash into the bytes. Returns whether the operation has succeeded.
The only condition this function would fail (returns an Err) is,
when buffer does not have enough size to store string representation
of the fuzzy hash.
Required size of the buffer is
len_in_str()-bytes. This is exact.
sourcepub fn from_bytes(str: &[u8]) -> Result<Self, ParseError>
pub fn from_bytes(str: &[u8]) -> Result<Self, ParseError>
Parse a fuzzy hash from a bytes (slice of u8)
of a string representation.
sourcepub fn normalize_in_place(&mut self)
pub fn normalize_in_place(&mut self)
Normalize the fuzzy hash in place.
After calling this method, self will be normalized.
See also: “Normalization” section of FuzzyHashData
sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Performs full validity checking of the internal structure.
The primary purpose of this is debugging and it should always
return true unless…
- There is a bug in this crate, corrupting this structure or
- A memory corruption is occurred somewhere else.
Because of its purpose, this method is not designed to be fast.
Note that, despite that it is only relevant to users when the unsafe
feature is enabled but made public without any features because this
method is not unsafe.
sourcepub fn full_eq(&self, other: &Self) -> bool
pub fn full_eq(&self, other: &Self) -> bool
Performs full equality checking of the internal structure.
While PartialEq for this type is designed to be fast by ignoring
non-block hash bytes, this method performs full equality checking,
not ignoring “non-block hash” bytes.
The primary purpose of this is debugging and it should always
return the same value as PartialEq result unless…
- There is a bug in this crate, corrupting this structure or
- A memory corruption is occurred somewhere else.
Because of its purpose, this method is not designed to be fast.
Note that, despite that it is only relevant to users when the unsafe
feature is enabled but made public without any features because this
method is not unsafe.
sourcepub fn compare_block_sizes(
lhs: impl AsRef<Self>,
rhs: impl AsRef<Self>
) -> BlockSizeRelation
pub fn compare_block_sizes( lhs: impl AsRef<Self>, rhs: impl AsRef<Self> ) -> BlockSizeRelation
Compare two base 2 logarithm form of the block size values from given two fuzzy hashes to determine their block size relation.
sourcepub fn is_block_sizes_near(lhs: impl AsRef<Self>, rhs: impl AsRef<Self>) -> bool
pub fn is_block_sizes_near(lhs: impl AsRef<Self>, rhs: impl AsRef<Self>) -> bool
Checks whether two base 2 logarithm form of the block size values from given two fuzzy hashes form a near relation.
sourcepub fn is_block_sizes_near_eq(
lhs: impl AsRef<Self>,
rhs: impl AsRef<Self>
) -> bool
pub fn is_block_sizes_near_eq( lhs: impl AsRef<Self>, rhs: impl AsRef<Self> ) -> bool
Checks whether two base 2 logarithm form of the block size values
from given two fuzzy hashes form a BlockSizeRelation::NearEq
relation.
sourcepub fn is_block_sizes_near_lt(
lhs: impl AsRef<Self>,
rhs: impl AsRef<Self>
) -> bool
pub fn is_block_sizes_near_lt( lhs: impl AsRef<Self>, rhs: impl AsRef<Self> ) -> bool
Checks whether two base 2 logarithm form of the block size values
from given two fuzzy hashes form a BlockSizeRelation::NearLt
relation.
sourcepub fn is_block_sizes_near_gt(
lhs: impl AsRef<Self>,
rhs: impl AsRef<Self>
) -> bool
pub fn is_block_sizes_near_gt( lhs: impl AsRef<Self>, rhs: impl AsRef<Self> ) -> bool
Checks whether two base 2 logarithm form of the block size values
from given two fuzzy hashes form a BlockSizeRelation::NearGt
relation.
sourcepub fn cmp_by_block_size(&self, other: &Self) -> Ordering
pub fn cmp_by_block_size(&self, other: &Self) -> Ordering
Compare two fuzzy hashes only by block sizes.
source§impl<const S1: usize, const S2: usize> FuzzyHashData<S1, S2, { _ }>where
BlockHashSize<S1>: ConstrainedBlockHashSize,
BlockHashSize<S2>: ConstrainedBlockHashSize,
BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
impl<const S1: usize, const S2: usize> FuzzyHashData<S1, S2, { _ }>where BlockHashSize<S1>: ConstrainedBlockHashSize, BlockHashSize<S2>: ConstrainedBlockHashSize, BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
Implementation of Normalized fuzzy hashes.
Methods below are available on normalized fuzzy hashes
(FuzzyHash or LongFuzzyHash).
sourcepub fn from_raw_form(source: &FuzzyHashData<S1, S2, { _ }>) -> Self
pub fn from_raw_form(source: &FuzzyHashData<S1, S2, { _ }>) -> Self
Converts the fuzzy hash from a raw form, normalizing it.
sourcepub fn to_raw_form(&self) -> FuzzyHashData<S1, S2, { _ }>
pub fn to_raw_form(&self) -> FuzzyHashData<S1, S2, { _ }>
Converts the fuzzy hash to a raw form.
sourcepub fn into_mut_raw_form(&self, dest: &mut FuzzyHashData<S1, S2, { _ }>)
pub fn into_mut_raw_form(&self, dest: &mut FuzzyHashData<S1, S2, { _ }>)
Copy the fuzzy hash to another (output is a raw form).
sourcepub fn normalize(&self) -> FuzzyHashData<S1, S2, { _ }>
pub fn normalize(&self) -> FuzzyHashData<S1, S2, { _ }>
Converts the fuzzy hash to a normalized form (with normalization).
In this normalized variant, this normalization is just a clone.
See also: “Normalization” section of FuzzyHashData
sourcepub fn clone_normalized(&self) -> Self
pub fn clone_normalized(&self) -> Self
Clones the fuzzy hash with normalization but without changing a type.
For a normalized fuzzy hash type, it always clones itself.
sourcepub fn is_normalized(&self) -> bool
pub fn is_normalized(&self) -> bool
Returns whether the fuzzy hash is normalized.
For a normalized fuzzy hash type, it always returns true.
Note that this method is only for convenience purposes and checking whether a fuzzy hash is normalized does not usually improve the performance.
source§impl<const S1: usize, const S2: usize> FuzzyHashData<S1, S2, { _ }>where
BlockHashSize<S1>: ConstrainedBlockHashSize,
BlockHashSize<S2>: ConstrainedBlockHashSize,
BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
impl<const S1: usize, const S2: usize> FuzzyHashData<S1, S2, { _ }>where BlockHashSize<S1>: ConstrainedBlockHashSize, BlockHashSize<S2>: ConstrainedBlockHashSize, BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
Implementation of Non-normalized fuzzy hashes (in raw form).
Methods below are available on non-normalized fuzzy hashes
(RawFuzzyHash or LongRawFuzzyHash).
sourcepub fn from_normalized(source: &FuzzyHashData<S1, S2, { _ }>) -> Self
pub fn from_normalized(source: &FuzzyHashData<S1, S2, { _ }>) -> Self
Converts the fuzzy hash from a normalized form.
sourcepub fn normalize(&self) -> FuzzyHashData<S1, S2, { _ }>
pub fn normalize(&self) -> FuzzyHashData<S1, S2, { _ }>
Converts the fuzzy hash to a normalized form (with normalization).
In this raw form variant, it performs a normalization operation.
See also: “Normalization” section of FuzzyHashData
sourcepub fn clone_normalized(&self) -> Self
pub fn clone_normalized(&self) -> Self
Clones the fuzzy hash with normalization but without changing a type.
sourcepub fn is_normalized(&self) -> bool
pub fn is_normalized(&self) -> bool
Returns whether the fuzzy hash is normalized.
For a non normalized fuzzy hash type (in raw form), it checks whether the fuzzy hash is already normalized.
Note that this method is only for convenience purposes and checking whether a fuzzy hash is normalized does not usually improve the performance.
source§impl<const NORM: bool> FuzzyHashData<{ BlockHash::FULL_SIZE }, { BlockHash::HALF_SIZE }, NORM>
impl<const NORM: bool> FuzzyHashData<{ BlockHash::FULL_SIZE }, { BlockHash::HALF_SIZE }, NORM>
Implementation of Short fuzzy hashes.
Methods below are available on short (truncated) fuzzy hashes
(FuzzyHash or RawFuzzyHash).
sourcepub fn to_long_form(
&self
) -> FuzzyHashData<{ BlockHash::FULL_SIZE }, { BlockHash::FULL_SIZE }, NORM>
pub fn to_long_form( &self ) -> FuzzyHashData<{ BlockHash::FULL_SIZE }, { BlockHash::FULL_SIZE }, NORM>
Converts the fuzzy hash to a long form.
sourcepub fn into_mut_long_form(
&self,
dest: &mut FuzzyHashData<{ BlockHash::FULL_SIZE }, { BlockHash::FULL_SIZE }, NORM>
)
pub fn into_mut_long_form( &self, dest: &mut FuzzyHashData<{ BlockHash::FULL_SIZE }, { BlockHash::FULL_SIZE }, NORM> )
Copy the fuzzy hash to another (output is a long form).
source§impl<const NORM: bool> FuzzyHashData<{ BlockHash::FULL_SIZE }, { BlockHash::FULL_SIZE }, NORM>
impl<const NORM: bool> FuzzyHashData<{ BlockHash::FULL_SIZE }, { BlockHash::FULL_SIZE }, NORM>
Implementation of Long fuzzy hashes.
Methods below are available on long (non-truncated) fuzzy hashes
(LongFuzzyHash or LongRawFuzzyHash).
sourcepub fn from_short_form(
source: &FuzzyHashData<{ BlockHash::FULL_SIZE }, { BlockHash::HALF_SIZE }, NORM>
) -> Self
pub fn from_short_form( source: &FuzzyHashData<{ BlockHash::FULL_SIZE }, { BlockHash::HALF_SIZE }, NORM> ) -> Self
Converts the fuzzy hash from a short, truncated form.
sourcepub fn try_into_mut_short(
&self,
dest: &mut FuzzyHashData<{ BlockHash::FULL_SIZE }, { BlockHash::HALF_SIZE }, NORM>
) -> Result<(), FuzzyHashOperationError>
pub fn try_into_mut_short( &self, dest: &mut FuzzyHashData<{ BlockHash::FULL_SIZE }, { BlockHash::HALF_SIZE }, NORM> ) -> Result<(), FuzzyHashOperationError>
Tries to copy the fuzzy hash to another (output is a short form).
Trait Implementations§
source§impl<const S1: usize, const S2: usize, const NORM: bool> AsRef<FuzzyHashData<S1, S2, NORM>> for FuzzyHashData<S1, S2, NORM>where
BlockHashSize<S1>: ConstrainedBlockHashSize,
BlockHashSize<S2>: ConstrainedBlockHashSize,
BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
impl<const S1: usize, const S2: usize, const NORM: bool> AsRef<FuzzyHashData<S1, S2, NORM>> for FuzzyHashData<S1, S2, NORM>where BlockHashSize<S1>: ConstrainedBlockHashSize, BlockHashSize<S2>: ConstrainedBlockHashSize, BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
source§fn as_ref(&self) -> &FuzzyHashData<S1, S2, NORM>
fn as_ref(&self) -> &FuzzyHashData<S1, S2, NORM>
source§impl<const S1: usize, const S2: usize, const C1: usize, const C2: usize> AsRef<FuzzyHashData<S1, S2, true>> for FuzzyHashDualData<S1, S2, C1, C2>where
BlockHashSize<S1>: ConstrainedBlockHashSize,
BlockHashSize<S2>: ConstrainedBlockHashSize,
BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
RleBlockSizeForBlockHash<S1, C1>: ConstrainedRleBlockSizeForBlockHash,
RleBlockSizeForBlockHash<S2, C2>: ConstrainedRleBlockSizeForBlockHash,
impl<const S1: usize, const S2: usize, const C1: usize, const C2: usize> AsRef<FuzzyHashData<S1, S2, true>> for FuzzyHashDualData<S1, S2, C1, C2>where BlockHashSize<S1>: ConstrainedBlockHashSize, BlockHashSize<S2>: ConstrainedBlockHashSize, BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes, RleBlockSizeForBlockHash<S1, C1>: ConstrainedRleBlockSizeForBlockHash, RleBlockSizeForBlockHash<S2, C2>: ConstrainedRleBlockSizeForBlockHash,
source§fn as_ref(&self) -> &FuzzyHashData<S1, S2, true>
fn as_ref(&self) -> &FuzzyHashData<S1, S2, true>
source§impl<const S1: usize, const S2: usize, const NORM: bool> Clone for FuzzyHashData<S1, S2, NORM>where
BlockHashSize<S1>: ConstrainedBlockHashSize,
BlockHashSize<S2>: ConstrainedBlockHashSize,
BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
impl<const S1: usize, const S2: usize, const NORM: bool> Clone for FuzzyHashData<S1, S2, NORM>where BlockHashSize<S1>: ConstrainedBlockHashSize, BlockHashSize<S2>: ConstrainedBlockHashSize, BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
source§fn clone(&self) -> FuzzyHashData<S1, S2, NORM>
fn clone(&self) -> FuzzyHashData<S1, S2, NORM>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl<const S1: usize, const S2: usize, const NORM: bool> Debug for FuzzyHashData<S1, S2, NORM>where
BlockHashSize<S1>: ConstrainedBlockHashSize,
BlockHashSize<S2>: ConstrainedBlockHashSize,
BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
impl<const S1: usize, const S2: usize, const NORM: bool> Debug for FuzzyHashData<S1, S2, NORM>where BlockHashSize<S1>: ConstrainedBlockHashSize, BlockHashSize<S2>: ConstrainedBlockHashSize, BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
source§impl<const S1: usize, const S2: usize, const NORM: bool> Default for FuzzyHashData<S1, S2, NORM>where
BlockHashSize<S1>: ConstrainedBlockHashSize,
BlockHashSize<S2>: ConstrainedBlockHashSize,
BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
impl<const S1: usize, const S2: usize, const NORM: bool> Default for FuzzyHashData<S1, S2, NORM>where BlockHashSize<S1>: ConstrainedBlockHashSize, BlockHashSize<S2>: ConstrainedBlockHashSize, BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
source§impl<const S1: usize, const S2: usize, const NORM: bool> Display for FuzzyHashData<S1, S2, NORM>where
BlockHashSize<S1>: ConstrainedBlockHashSize,
BlockHashSize<S2>: ConstrainedBlockHashSize,
BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
impl<const S1: usize, const S2: usize, const NORM: bool> Display for FuzzyHashData<S1, S2, NORM>where BlockHashSize<S1>: ConstrainedBlockHashSize, BlockHashSize<S2>: ConstrainedBlockHashSize, BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
source§impl<const S1: usize, const S2: usize> From<&FuzzyHashData<S1, S2, true>> for FuzzyHashCompareTargetwhere
BlockHashSize<S1>: ConstrainedBlockHashSize,
BlockHashSize<S2>: ConstrainedBlockHashSize,
BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
impl<const S1: usize, const S2: usize> From<&FuzzyHashData<S1, S2, true>> for FuzzyHashCompareTargetwhere BlockHashSize<S1>: ConstrainedBlockHashSize, BlockHashSize<S2>: ConstrainedBlockHashSize, BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
source§fn from(value: &FuzzyHashData<S1, S2, true>) -> Self
fn from(value: &FuzzyHashData<S1, S2, true>) -> Self
source§impl<const NORM: bool> From<FuzzyHashData<{BlockHash::FULL_SIZE}, {BlockHash::HALF_SIZE}, NORM>> for FuzzyHashData<{ BlockHash::FULL_SIZE }, { BlockHash::FULL_SIZE }, NORM>
impl<const NORM: bool> From<FuzzyHashData<{BlockHash::FULL_SIZE}, {BlockHash::HALF_SIZE}, NORM>> for FuzzyHashData<{ BlockHash::FULL_SIZE }, { BlockHash::FULL_SIZE }, NORM>
source§fn from(
value: FuzzyHashData<{ BlockHash::FULL_SIZE }, { BlockHash::HALF_SIZE }, NORM>
) -> Self
fn from( value: FuzzyHashData<{ BlockHash::FULL_SIZE }, { BlockHash::HALF_SIZE }, NORM> ) -> Self
source§impl From<FuzzyHashData<{BlockHash::FULL_SIZE}, {BlockHash::HALF_SIZE}, true>> for FuzzyHashData<{ BlockHash::FULL_SIZE }, { BlockHash::FULL_SIZE }, false>
impl From<FuzzyHashData<{BlockHash::FULL_SIZE}, {BlockHash::HALF_SIZE}, true>> for FuzzyHashData<{ BlockHash::FULL_SIZE }, { BlockHash::FULL_SIZE }, false>
source§fn from(
value: FuzzyHashData<{ BlockHash::FULL_SIZE }, { BlockHash::HALF_SIZE }, true>
) -> Self
fn from( value: FuzzyHashData<{ BlockHash::FULL_SIZE }, { BlockHash::HALF_SIZE }, true> ) -> Self
source§impl<const S1: usize, const S2: usize, const NORM: bool> From<FuzzyHashData<S1, S2, NORM>> for Stringwhere
BlockHashSize<S1>: ConstrainedBlockHashSize,
BlockHashSize<S2>: ConstrainedBlockHashSize,
BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
Available on crate feature alloc only.
impl<const S1: usize, const S2: usize, const NORM: bool> From<FuzzyHashData<S1, S2, NORM>> for Stringwhere BlockHashSize<S1>: ConstrainedBlockHashSize, BlockHashSize<S2>: ConstrainedBlockHashSize, BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
alloc only.source§fn from(value: FuzzyHashData<S1, S2, NORM>) -> Self
fn from(value: FuzzyHashData<S1, S2, NORM>) -> Self
source§impl<const S1: usize, const S2: usize> From<FuzzyHashData<S1, S2, false>> for FuzzyHashData<S1, S2, { _ }>where
BlockHashSize<S1>: ConstrainedBlockHashSize,
BlockHashSize<S2>: ConstrainedBlockHashSize,
BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
impl<const S1: usize, const S2: usize> From<FuzzyHashData<S1, S2, false>> for FuzzyHashData<S1, S2, { _ }>where BlockHashSize<S1>: ConstrainedBlockHashSize, BlockHashSize<S2>: ConstrainedBlockHashSize, BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
source§fn from(value: FuzzyHashData<S1, S2, { _ }>) -> Self
fn from(value: FuzzyHashData<S1, S2, { _ }>) -> Self
source§impl<const S1: usize, const S2: usize, const C1: usize, const C2: usize> From<FuzzyHashData<S1, S2, false>> for FuzzyHashDualData<S1, S2, C1, C2>where
BlockHashSize<S1>: ConstrainedBlockHashSize,
BlockHashSize<S2>: ConstrainedBlockHashSize,
BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
RleBlockSizeForBlockHash<S1, C1>: ConstrainedRleBlockSizeForBlockHash,
RleBlockSizeForBlockHash<S2, C2>: ConstrainedRleBlockSizeForBlockHash,
impl<const S1: usize, const S2: usize, const C1: usize, const C2: usize> From<FuzzyHashData<S1, S2, false>> for FuzzyHashDualData<S1, S2, C1, C2>where BlockHashSize<S1>: ConstrainedBlockHashSize, BlockHashSize<S2>: ConstrainedBlockHashSize, BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes, RleBlockSizeForBlockHash<S1, C1>: ConstrainedRleBlockSizeForBlockHash, RleBlockSizeForBlockHash<S2, C2>: ConstrainedRleBlockSizeForBlockHash,
source§fn from(value: FuzzyHashData<S1, S2, false>) -> Self
fn from(value: FuzzyHashData<S1, S2, false>) -> Self
source§impl<const S1: usize, const S2: usize> From<FuzzyHashData<S1, S2, true>> for FuzzyHashCompareTargetwhere
BlockHashSize<S1>: ConstrainedBlockHashSize,
BlockHashSize<S2>: ConstrainedBlockHashSize,
BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
impl<const S1: usize, const S2: usize> From<FuzzyHashData<S1, S2, true>> for FuzzyHashCompareTargetwhere BlockHashSize<S1>: ConstrainedBlockHashSize, BlockHashSize<S2>: ConstrainedBlockHashSize, BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
source§fn from(value: FuzzyHashData<S1, S2, true>) -> Self
fn from(value: FuzzyHashData<S1, S2, true>) -> Self
source§impl<const S1: usize, const S2: usize> From<FuzzyHashData<S1, S2, true>> for FuzzyHashData<S1, S2, { _ }>where
BlockHashSize<S1>: ConstrainedBlockHashSize,
BlockHashSize<S2>: ConstrainedBlockHashSize,
BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
impl<const S1: usize, const S2: usize> From<FuzzyHashData<S1, S2, true>> for FuzzyHashData<S1, S2, { _ }>where BlockHashSize<S1>: ConstrainedBlockHashSize, BlockHashSize<S2>: ConstrainedBlockHashSize, BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
source§fn from(value: FuzzyHashData<S1, S2, { _ }>) -> Self
fn from(value: FuzzyHashData<S1, S2, { _ }>) -> Self
source§impl<const S1: usize, const S2: usize, const C1: usize, const C2: usize> From<FuzzyHashData<S1, S2, true>> for FuzzyHashDualData<S1, S2, C1, C2>where
BlockHashSize<S1>: ConstrainedBlockHashSize,
BlockHashSize<S2>: ConstrainedBlockHashSize,
BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
RleBlockSizeForBlockHash<S1, C1>: ConstrainedRleBlockSizeForBlockHash,
RleBlockSizeForBlockHash<S2, C2>: ConstrainedRleBlockSizeForBlockHash,
impl<const S1: usize, const S2: usize, const C1: usize, const C2: usize> From<FuzzyHashData<S1, S2, true>> for FuzzyHashDualData<S1, S2, C1, C2>where BlockHashSize<S1>: ConstrainedBlockHashSize, BlockHashSize<S2>: ConstrainedBlockHashSize, BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes, RleBlockSizeForBlockHash<S1, C1>: ConstrainedRleBlockSizeForBlockHash, RleBlockSizeForBlockHash<S2, C2>: ConstrainedRleBlockSizeForBlockHash,
source§fn from(value: FuzzyHashData<S1, S2, true>) -> Self
fn from(value: FuzzyHashData<S1, S2, true>) -> Self
source§impl<const S1: usize, const S2: usize, const NORM: bool> FromStr for FuzzyHashData<S1, S2, NORM>where
BlockHashSize<S1>: ConstrainedBlockHashSize,
BlockHashSize<S2>: ConstrainedBlockHashSize,
BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
impl<const S1: usize, const S2: usize, const NORM: bool> FromStr for FuzzyHashData<S1, S2, NORM>where BlockHashSize<S1>: ConstrainedBlockHashSize, BlockHashSize<S2>: ConstrainedBlockHashSize, BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
source§impl<const S1: usize, const S2: usize, const NORM: bool> Hash for FuzzyHashData<S1, S2, NORM>where
BlockHashSize<S1>: ConstrainedBlockHashSize,
BlockHashSize<S2>: ConstrainedBlockHashSize,
BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
impl<const S1: usize, const S2: usize, const NORM: bool> Hash for FuzzyHashData<S1, S2, NORM>where BlockHashSize<S1>: ConstrainedBlockHashSize, BlockHashSize<S2>: ConstrainedBlockHashSize, BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
source§impl<const S1: usize, const S2: usize, const NORM: bool> Ord for FuzzyHashData<S1, S2, NORM>where
BlockHashSize<S1>: ConstrainedBlockHashSize,
BlockHashSize<S2>: ConstrainedBlockHashSize,
BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
impl<const S1: usize, const S2: usize, const NORM: bool> Ord for FuzzyHashData<S1, S2, NORM>where BlockHashSize<S1>: ConstrainedBlockHashSize, BlockHashSize<S2>: ConstrainedBlockHashSize, BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
source§impl<const S1: usize, const S2: usize, const NORM: bool> PartialEq<FuzzyHashData<S1, S2, NORM>> for FuzzyHashData<S1, S2, NORM>where
BlockHashSize<S1>: ConstrainedBlockHashSize,
BlockHashSize<S2>: ConstrainedBlockHashSize,
BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
impl<const S1: usize, const S2: usize, const NORM: bool> PartialEq<FuzzyHashData<S1, S2, NORM>> for FuzzyHashData<S1, S2, NORM>where BlockHashSize<S1>: ConstrainedBlockHashSize, BlockHashSize<S2>: ConstrainedBlockHashSize, BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
source§impl<const S1: usize, const S2: usize, const NORM: bool> PartialOrd<FuzzyHashData<S1, S2, NORM>> for FuzzyHashData<S1, S2, NORM>where
BlockHashSize<S1>: ConstrainedBlockHashSize,
BlockHashSize<S2>: ConstrainedBlockHashSize,
BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
impl<const S1: usize, const S2: usize, const NORM: bool> PartialOrd<FuzzyHashData<S1, S2, NORM>> for FuzzyHashData<S1, S2, NORM>where BlockHashSize<S1>: ConstrainedBlockHashSize, BlockHashSize<S2>: ConstrainedBlockHashSize, BlockHashSizes<S1, S2>: ConstrainedBlockHashSizes,
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read more