Skip to content

Commit

Permalink
interner: add is zero and is one functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ekiwi committed May 30, 2024
1 parent b1396ac commit a36b83e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/value/indexed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,14 @@ impl BitVecValueInterner {
}
}

pub fn is_zero<I: AsRef<BitVecValueIndex>>(index: I) -> bool {
index.as_ref().index == 0
}

pub fn is_one<I: AsRef<BitVecValueIndex>>(index: I) -> bool {
index.as_ref().index == 1
}

pub fn get_index<I: BitVecOps>(&mut self, value: I) -> BitVecValueIndex {
let (words, width) = (value.words(), value.width());
if let &[word] = words {
Expand Down Expand Up @@ -324,6 +332,16 @@ mod tests {
let mut i = BitVecValueInterner::new();
assert_eq!(i.get_index(BitVecValue::tru()).index, 1);
assert_eq!(i.get_index(BitVecValue::fals()).index, 0);
assert_eq!(i.get_index(BitVecValue::from_u64(0, 4)).index, 0);
assert!(BitVecValueInterner::is_zero(
i.get_index(BitVecValue::from_u64(0, 4))
));
assert!(!BitVecValueInterner::is_one(
i.get_index(BitVecValue::from_u64(0, 4))
));
assert!(BitVecValueInterner::is_one(
i.get_index(BitVecValue::from_u64(1, 4))
));
}

use num_bigint::*;
Expand Down

0 comments on commit a36b83e

Please sign in to comment.