Skip to content

Commit

Permalink
combine HashIntoType with IdentityHash
Browse files Browse the repository at this point in the history
  • Loading branch information
ctb committed Nov 2, 2024
1 parent 446aaed commit 3d1bb4f
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const VERSION: &str = env!("CARGO_PKG_VERSION");
const DEFAULT_HASHMAP_CAPACITY: usize = 100_000;

/// Hash value type, for custom hashing.
#[derive(Eq, PartialEq, Debug, Serialize, Deserialize, Clone, Ord, PartialOrd, Copy)]
#[derive(Eq, PartialEq, Debug, Serialize, Deserialize, Clone, Ord, PartialOrd, Copy, Default)]
pub struct HashIntoType(u64);

impl HashIntoType {
Expand Down Expand Up @@ -73,10 +73,7 @@ impl Hash for HashIntoType {
}
}

#[derive(Default, Clone, Copy)]
pub struct IdentityHash(u64);

impl Hasher for IdentityHash {
impl Hasher for HashIntoType {
fn finish(&self) -> u64 {
self.0
}
Expand All @@ -90,15 +87,15 @@ impl Hasher for IdentityHash {
}
}

impl BuildHasher for IdentityHash {
impl BuildHasher for HashIntoType {
type Hasher = Self;

fn build_hasher(&self) -> Self::Hasher {
*self
}
}

type IdentityBuildHasher = BuildHasherDefault<IdentityHash>;
type IdentityBuildHasher = BuildHasherDefault<HashIntoType>;

#[pyclass]
#[derive(Serialize, Deserialize, Debug)]
Expand Down

0 comments on commit 3d1bb4f

Please sign in to comment.