Skip to content

Commit

Permalink
Merge pull request #386 from Chia-Network/hashable-atom
Browse files Browse the repository at this point in the history
enable Atom to be the key in a HashTable
  • Loading branch information
arvidn authored Feb 22, 2024
2 parents 935e251 + 86d7b06 commit fbe52f2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<H: Hasher>(&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())
Expand Down

0 comments on commit fbe52f2

Please sign in to comment.