From 86d7b06809339ab7e3f5fd37b481b609f229aefe Mon Sep 17 00:00:00 2001 From: arvidn Date: Thu, 22 Feb 2024 11:57:02 +0100 Subject: [PATCH] enable Atom to be the key in a HashTable --- src/allocator.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/allocator.rs b/src/allocator.rs index 75fe65c4..f0526db5 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -2,6 +2,8 @@ use crate::err_utils::err; use crate::number::{node_from_number, number_from_u8, Number}; use crate::reduction::EvalErr; use chia_bls::{G1Element, G2Element}; +use std::hash::Hash; +use std::hash::Hasher; const MAX_NUM_ATOMS: usize = 62500000; const MAX_NUM_PAIRS: usize = 62500000; @@ -101,12 +103,18 @@ pub enum NodeVisitor<'a> { Pair(NodePtr, NodePtr), } -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, Eq)] pub enum Atom<'a> { Borrowed(&'a [u8]), U32([u8; 4], usize), } +impl Hash for Atom<'_> { + fn hash(&self, state: &mut H) { + self.as_ref().hash(state) + } +} + impl PartialEq for Atom<'_> { fn eq(&self, other: &Atom) -> bool { self.as_ref().eq(other.as_ref())