Skip to content

Commit

Permalink
Merge pull request #520 from Chia-Network/debug-print
Browse files Browse the repository at this point in the history
improve debug printing of NodePtr
  • Loading branch information
arvidn authored Dec 27, 2024
2 parents 110d69c + 07a769a commit 9a0ed3a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 1 addition & 3 deletions fuzz/fuzz_targets/deserialize_br.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,5 @@ fuzz_target!(|data: &[u8]| {
let program = node_from_bytes_backrefs(&mut allocator, &b1).unwrap();

let b2 = node_to_bytes_backrefs(&allocator, program).unwrap();
if b1 != b2 {
panic!("b1 and b2 do not match");
}
assert_eq!(b1, b2);
});
12 changes: 11 additions & 1 deletion src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::number::{number_from_u8, Number};
use crate::reduction::EvalErr;
use chia_bls::{G1Element, G2Element};
use std::borrow::Borrow;
use std::fmt;
use std::hash::Hash;
use std::hash::Hasher;
use std::ops::Deref;
Expand All @@ -12,9 +13,18 @@ const MAX_NUM_PAIRS: usize = 62500000;
const NODE_PTR_IDX_BITS: u32 = 26;
const NODE_PTR_IDX_MASK: u32 = (1 << NODE_PTR_IDX_BITS) - 1;

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct NodePtr(u32);

impl fmt::Debug for NodePtr {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("NodePtr")
.field(&self.object_type())
.field(&self.index())
.finish()
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
enum ObjectType {
// The low bits form an index into the pair_vec
Expand Down

0 comments on commit 9a0ed3a

Please sign in to comment.