Skip to content

Commit

Permalink
Cleanup and update names (#2)
Browse files Browse the repository at this point in the history
* Cleanup and update names

* Add deprecation notice

* remove deprecated functions

* fix clippy warning

---------

Co-authored-by: Kevin Läufer <[email protected]>
  • Loading branch information
ethanuppal and ekiwi authored Dec 19, 2024
1 parent de1d5d9 commit 0932b0e
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 34 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "baa"
version = "0.14.7"
version = "0.15.0"
edition = "2021"
authors = ["Kevin Laeufer <[email protected]>"]
description = "BitVector and Array Arithmetic"
Expand All @@ -14,8 +14,8 @@ rust-version = "1.73.0"

[dependencies]
# optional dependencies for crate interop
fraction = { version = "0.11", optional = true }
num-bigint = { version = "0.4", optional = true}
fraction = { version = "0.15", optional = true }
num-bigint = { version = "0.4", optional = true }
serde = { version = "1.0", features = ["derive"], optional = true }


Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions src/array/owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,10 @@ impl DenseArrayValue {

let elements = 1usize << index_width;
let data = if data_width == 1 {
if default.is_tru() {
if default.is_true() {
DenseArrayImpl::Bit(BitVecValue::ones(elements as WidthInt))
} else {
debug_assert!(default.is_fals());
debug_assert!(default.is_false());
DenseArrayImpl::Bit(BitVecValue::zero(elements as WidthInt))
}
} else if data_width <= u8::BITS {
Expand Down Expand Up @@ -388,7 +388,7 @@ impl ArrayMutOps for DenseArrayValue {
let words_per_element = self.words_per_element();
match &mut self.data {
DenseArrayImpl::Bit(value) => {
if data.is_tru() {
if data.is_true() {
value.set_bit(index as WidthInt);
} else {
value.clear_bit(index as WidthInt);
Expand Down
File renamed without changes.
5 changes: 1 addition & 4 deletions src/bv/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,7 @@ pub(crate) fn shift_right(
clear(dst);

// check to see if we are shifting for more than our width
let shift_amount = match get_shift_amount(b, width) {
None => return None,
Some(value) => value,
};
let shift_amount = get_shift_amount(b, width)?;

// otherwise we actually perform the shift by converting it to a slice
let hi = width - 1;
Expand Down
4 changes: 2 additions & 2 deletions src/bv/borrowed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl BitVecOps for BitVecValueRef<'_> {
match &self.0 {
BitVecValueRefImpl::Word(_, value) => std::slice::from_ref(value),
BitVecValueRefImpl::Double(_, value) => value.as_slice(),
BitVecValueRefImpl::Big(_, value) => value.as_ref(),
BitVecValueRefImpl::Big(_, value) => value,
}
}
}
Expand Down Expand Up @@ -130,7 +130,7 @@ mod tests {
use std::hash::{DefaultHasher, Hash, Hasher};

/// Signature is copied from HashTable::get
fn get_hash<Q: ?Sized>(key: &Q) -> u64
fn get_hash<Q>(key: &Q) -> u64
where
BitVecValue: Borrow<Q>,
Q: Hash + Eq,
Expand Down
4 changes: 2 additions & 2 deletions src/bv/indexed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ mod tests {
#[test]
fn test_interner() {
let mut i = ValueInterner::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::new_true()).index, 1);
assert_eq!(i.get_index(&BitVecValue::new_false()).index, 0);
assert_eq!(i.get_index(&BitVecValue::from_u64(0, 4)).index, 0);
assert!(ValueInterner::is_zero(
i.get_index(&BitVecValue::from_u64(0, 4))
Expand Down
File renamed without changes.
18 changes: 9 additions & 9 deletions src/bv/io/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ mod tests {
fn test_to_bit_str_with_extra_words() {
let value = BitVecValue::zero(7);
let input = value.words();
assert_eq!(to_bit_str(&input, 7), "0000000");
assert_eq!(to_bit_str(&input, 33), "0".repeat(33));
assert_eq!(to_bit_str(input, 7), "0000000");
assert_eq!(to_bit_str(input, 33), "0".repeat(33));
}

#[test]
Expand All @@ -410,27 +410,27 @@ mod tests {
fn test_to_hex_str() {
let mut value = BitVecValue::zero(64);
let input = value.words_mut();
assert_eq!(to_hex_str(&input, 7), "00");
assert_eq!(to_hex_str(&input, 33), "0".repeat(9));
assert_eq!(to_hex_str(input, 7), "00");
assert_eq!(to_hex_str(input, 33), "0".repeat(9));
input[0] = 0xa4aa78;
assert_eq!(to_hex_str(&input, 6 * 4), "a4aa78");
assert_eq!(to_hex_str(input, 6 * 4), "a4aa78");
let mut value = BitVecValue::zero(128);
let input = value.words_mut();
input[0] = 0xaaaaaaaaaaaaaaaa;
assert_eq!(to_hex_str(&input, 7 + Word::BITS), "00aaaaaaaaaaaaaaaa");
assert_eq!(to_hex_str(input, 7 + Word::BITS), "00aaaaaaaaaaaaaaaa");
assert_eq!(
to_hex_str(&input, 33 + Word::BITS),
to_hex_str(input, 33 + Word::BITS),
format!("{}aaaaaaaaaaaaaaaa", "0".repeat(9))
);
input[1] = 0xa4aa78;
assert_eq!(
to_hex_str(&input, 6 * 4 + Word::BITS),
to_hex_str(input, 6 * 4 + Word::BITS),
"a4aa78aaaaaaaaaaaaaaaa"
);
// regressions test
let mut value = BitVecValue::zero(64);
let input = value.words_mut();
input[0] = 768603298337958570;
assert_eq!(to_hex_str(&input, 64), "0aaaa0a0aaa0aaaa");
assert_eq!(to_hex_str(input, 64), "0aaaa0a0aaa0aaaa");
}
}
4 changes: 2 additions & 2 deletions src/bv/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ pub trait BitVecOps {
}
}

fn is_tru(&self) -> bool {
fn is_true(&self) -> bool {
self.width() == 1 && self.words()[0] == 1
}

fn is_fals(&self) -> bool {
fn is_false(&self) -> bool {
self.width() == 1 && self.words()[0] == 0
}

Expand Down
28 changes: 19 additions & 9 deletions src/bv/owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ impl From<WidthInt> for W {
}
}

const FALS_VALUE: BitVecValueImpl = BitVecValueImpl::new_word(0, 1);
const TRU_VALUE: BitVecValueImpl = BitVecValueImpl::new_word(1, 1);
const FALSE_VALUE: BitVecValueImpl = BitVecValueImpl::new_word(0, 1);
const TRUE_VALUE: BitVecValueImpl = BitVecValueImpl::new_word(1, 1);

impl BitVecValue {
/// Parse a string of 1s and 0s. The width of the resulting value is the number of digits.
Expand Down Expand Up @@ -155,9 +155,9 @@ impl BitVecValue {

pub fn from_bool(value: bool) -> Self {
if value {
Self::tru()
Self::new_true()
} else {
Self::fals()
Self::new_false()
}
}

Expand Down Expand Up @@ -200,11 +200,21 @@ impl BitVecValue {
}

#[inline]
pub fn new_true() -> Self {
Self(TRUE_VALUE.clone())
}
#[inline]
pub fn new_false() -> Self {
Self(FALSE_VALUE.clone())
}

#[deprecated(since = "0.15.0", note = "please use `new_true` instead")]
pub fn tru() -> Self {
Self(TRU_VALUE.clone())
Self::new_true()
}
#[deprecated(since = "0.15.0", note = "please use `new_false` instead")]
pub fn fals() -> Self {
Self(FALS_VALUE.clone())
Self::new_false()
}

#[cfg(feature = "bigint")]
Expand Down Expand Up @@ -334,9 +344,9 @@ mod tests {
}

#[test]
fn test_tru_fals() {
assert!(BitVecValue::tru().to_bool().unwrap());
assert!(!BitVecValue::fals().to_bool().unwrap());
fn test_true_false() {
assert!(BitVecValue::new_true().to_bool().unwrap());
assert!(!BitVecValue::new_false().to_bool().unwrap());
}

#[test]
Expand Down

0 comments on commit 0932b0e

Please sign in to comment.