Skip to content

Commit

Permalink
fix: watch map incorrectly reported size
Browse files Browse the repository at this point in the history
  • Loading branch information
baszalmstra committed Nov 28, 2024
1 parent 33e0686 commit 63b9d0a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/internal/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ impl<TId: ArenaId, TValue> Mapping<TId, TValue> {
Self::with_capacity(1)
}

/// Returns the total number of values that can be stored in the mapping without reallocating.
pub fn capacity(&self) -> usize {
self.chunks.len() * VALUES_PER_CHUNK
}

/// Returns the total number of bytes allocated by this instance.
pub fn size_in_bytes(&self) -> usize {
self.capacity() * std::mem::size_of::<Option<TValue>>()
}

/// Constructs a new arena with a capacity for `n` values pre-allocated.
pub fn with_capacity(n: usize) -> Self {
let n = cmp::max(1, n);
Expand Down
5 changes: 2 additions & 3 deletions src/solver/watch_map.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::solver::clause::Literal;
use crate::{
internal::{id::ClauseId, mapping::Mapping},
solver::clause::ClauseState,
solver::clause::{ClauseState, Literal},
};

/// A map from solvables to the clauses that are watching them
Expand All @@ -25,7 +24,7 @@ impl WatchMap {

#[cfg(feature = "diagnostics")]
pub fn size_in_bytes(&self) -> usize {
self.len() * std::mem::size_of::<(Literal, ClauseId)>()
self.map.size_in_bytes()
}

pub(crate) fn start_watching(&mut self, clause: &mut ClauseState, clause_id: ClauseId) {
Expand Down

0 comments on commit 63b9d0a

Please sign in to comment.