pub struct Array<R: Borrow<Btor> + Clone> { /* private fields */ }
Expand description

An Array in Boolector is really just a map from BVs to BVs.

Like BV, Array is generic in the Btor reference type. For instance, you could use Array<Rc<Btor>> for single-threaded applications, or Array<Arc<Btor>> for multi-threaded applications.

Implementations

Create a new Array which maps BVs of width index_width to BVs of width element_width. All values in the Array will be unconstrained.

The symbol, if present, will be used to identify the Array when printing a model or dumping to file. It must be unique if it is present.

Both index_width and element_width must not be 0.

Example
let btor = Rc::new(Btor::new());

// `arr` is an `Array` which maps 8-bit values to 8-bit values
let arr = Array::new(btor.clone(), 8, 8, Some("arr"));

// Write the value `3` to array index `7`
let three = BV::from_u32(btor.clone(), 3, 8);
let seven = BV::from_u32(btor.clone(), 7, 8);
let arr2 = arr.write(&seven, &three);

// Read back out the resulting value
let read_bv = arr2.read(&seven);

// should be the value `3`
assert_eq!(read_bv.as_u64().unwrap(), 3);

Create a new Array which maps BVs of width index_width to BVs of width element_width. The Array will be initialized so that all indices map to the same constant value val.

Both index_width and element_width must not be 0.

Example
let btor = Rc::new(Btor::new());
btor.set_opt(BtorOption::ModelGen(ModelGen::All));
btor.set_opt(BtorOption::Incremental(true));

// `arr` is an `Array` which maps 8-bit values to 8-bit values.
// It is initialized such that all entries are the constant `42`.
let fortytwo = BV::from_u32(btor.clone(), 42, 8);
let arr = Array::new_initialized(btor.clone(), 8, 8, &fortytwo);

// Reading the value at any index should produce `42`.
let read_bv = arr.read(&BV::from_u32(btor.clone(), 61, 8));
assert_eq!(btor.sat(), SolverResult::Sat);
assert_eq!(read_bv.get_a_solution().as_u64().unwrap(), 42);

// Write the value `3` to array index `7`
let three = BV::from_u32(btor.clone(), 3, 8);
let seven = BV::from_u32(btor.clone(), 7, 8);
let arr2 = arr.write(&seven, &three);

// Read back out the value at index `7`. It should be `3`.
let read_bv = arr2.read(&seven);
assert_eq!(read_bv.as_u64().unwrap(), 3);

// Reading the value at any other index should still produce `42`.
let read_bv = arr2.read(&BV::from_u32(btor.clone(), 99, 8));
assert_eq!(btor.sat(), SolverResult::Sat);
//assert_eq!(read_bv.get_a_solution().as_u64().unwrap(), 42);

Get the bitwidth of the index type of the Array

Get the bitwidth of the element type of the Array

Get the symbol of the Array, if one was assigned

Does the Array have a constant value?

Does self have the same index and element widths as other?

Array equality. self and other must have the same index and element widths.

Array inequality. self and other must have the same index and element widths.

Array read: get the value in the Array at the given index

Array write: return a new Array which has value at position index, and all other elements unchanged.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Executes the destructor for this type. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.