pub trait HashableChar {
    // Required method
    fn hash_char(&self) -> Hash;
}
Expand description

trait used to map between element types and unique hash values

RapidFuzz already implements this trait for most primitive types. For custom types this trat can be used to support the internal hashmaps. There are a couple of things to keep in mind when implementing this trait:

  • hashes have to be a unique value in the range i64::MIN - u64::MAX. If two distinct objects produce the same hash, they will be assumed to be similar by the hashmap.
  • the hash function should be very fast. For primitive types it can just be the identity function
  • the hashmaps are optimized for extended ASCII, so values in the range 0-255 generally provide a better performance.

Example

use rapidfuzz::distance;
use rapidfuzz::{Hash, HashableChar};

#[derive(PartialEq)]
struct MyType {
    val: u64,
}

impl HashableChar for &MyType {
    fn hash_char(&self) -> Hash {
        Hash::UNSIGNED(self.val)
    }
}

assert_eq!(
    1,
    distance::levenshtein::distance(
        &[MyType { val: 1 }, MyType { val: 1 }],
        &[MyType { val: 2 }, MyType { val: 1 }],
    )
);

Required Methods§

source

fn hash_char(&self) -> Hash

Implementations on Foreign Types§

source§

impl HashableChar for &char

source§

fn hash_char(&self) -> Hash

source§

impl HashableChar for &i8

source§

fn hash_char(&self) -> Hash

source§

impl HashableChar for &i16

source§

fn hash_char(&self) -> Hash

source§

impl HashableChar for &i32

source§

fn hash_char(&self) -> Hash

source§

impl HashableChar for &i64

source§

fn hash_char(&self) -> Hash

source§

impl HashableChar for &u8

source§

fn hash_char(&self) -> Hash

source§

impl HashableChar for &u16

source§

fn hash_char(&self) -> Hash

source§

impl HashableChar for &u32

source§

fn hash_char(&self) -> Hash

source§

impl HashableChar for &u64

source§

fn hash_char(&self) -> Hash

source§

impl HashableChar for char

source§

fn hash_char(&self) -> Hash

source§

impl HashableChar for i8

source§

fn hash_char(&self) -> Hash

source§

impl HashableChar for i16

source§

fn hash_char(&self) -> Hash

source§

impl HashableChar for i32

source§

fn hash_char(&self) -> Hash

source§

impl HashableChar for i64

source§

fn hash_char(&self) -> Hash

source§

impl HashableChar for u8

source§

fn hash_char(&self) -> Hash

source§

impl HashableChar for u16

source§

fn hash_char(&self) -> Hash

source§

impl HashableChar for u32

source§

fn hash_char(&self) -> Hash

source§

impl HashableChar for u64

source§

fn hash_char(&self) -> Hash

Implementors§