Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable Atom to be the key in a HashTable #386

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading