Skip to content

Commit

Permalink
fix checkpointing for ghost_pair counting
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-o-how committed Feb 6, 2025
1 parent da02ba0 commit 1fb0a47
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ pub struct Checkpoint {
pairs: usize,
atoms: usize,
small_atoms: usize,
max_num_atoms: usize,
ghost_pairs: usize,
}

pub enum NodeVisitor<'a> {
Expand Down Expand Up @@ -264,6 +266,8 @@ impl Allocator {
pairs: self.pair_vec.len(),
atoms: self.atom_vec.len(),
small_atoms: self.small_atoms,
max_num_atoms: self.max_num_atoms,
ghost_pairs: self.num_ghost_pairs,
}
}

Expand All @@ -279,6 +283,8 @@ impl Allocator {
self.pair_vec.truncate(cp.pairs);
self.atom_vec.truncate(cp.atoms);
self.small_atoms = cp.small_atoms;
self.max_num_atoms = cp.max_num_atoms;
self.num_ghost_pairs = cp.ghost_pairs;
}

pub fn new_atom(&mut self, v: &[u8]) -> Result<NodePtr, EvalErr> {
Expand Down Expand Up @@ -701,6 +707,11 @@ impl Allocator {
self.pair_vec.len() + self.num_ghost_pairs
}

#[cfg(feature = "counters")]
pub fn pair_count_no_ghosts(&self) -> usize {
self.pair_vec.len()
}

#[cfg(feature = "counters")]
pub fn heap_size(&self) -> usize {
self.u8_vec.len()
Expand Down
4 changes: 4 additions & 0 deletions src/serde/de_br.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,13 @@ mod tests {
let buf = Vec::from_hex("0a").unwrap();
let _node = node_from_bytes_backrefs(&mut a, &buf).unwrap();
let pair_count = a.pair_count();
let pair_count_no_ghosts = a.pair_count_no_ghosts();
a.restore_checkpoint(&cp);
let _old_node = node_from_bytes_backrefs_old(&mut a, &buf).unwrap();
let old_pair_count = a.pair_count();
let old_pair_count_no_ghosts = a.pair_count_no_ghosts();
assert_eq!(pair_count_no_ghosts, 0);
assert_eq!(old_pair_count_no_ghosts, 1);
assert_eq!(pair_count, old_pair_count);
}

Expand Down

0 comments on commit 1fb0a47

Please sign in to comment.