Skip to main content

SharedDbm

Struct SharedDbm 

Source
pub struct SharedDbm(/* private fields */);
Expand description

An immutable zone snapshot with cheap cloning and copy-on-write updates.

Cloning a SharedDbm takes O(1) time: it shares the underlying Dbm rather than copying the matrix. A consuming update reuses unique storage or copies a shared matrix (up to O(d²) entries for matrix dimension d). No update mutates an existing snapshot. Equality and hashing are semantic and independent of pointer identity.

SharedDbm uses Rc and is not Send. To transfer a zone between threads, first convert it into an owned Dbm with SharedDbm::into_dbm.

§Example

use clock_dbm::{Clock, Constraint, SharedDbm};
let x = Clock::new(1).unwrap();
let original = SharedDbm::universe(1)?;
let branch = original.clone().try_constrain(Constraint::lt(x, Clock::ZERO, 5)?)?;
assert!(branch.is_subset_of(&original)?);
assert!(!original.entails(&Constraint::lt(x, Clock::ZERO, 5)?)?);

Implementations§

Source§

impl SharedDbm

Source

pub fn zero(variables: usize) -> Result<SharedDbm, Error>

Creates a shared zone in which all actual clocks equal zero.

§Errors

Error::TooManyVariables if the requested clock count is too large.

§Complexity

O(d²) time and space for d = variables + 1.

Source

pub fn universe(variables: usize) -> Result<SharedDbm, Error>

Creates a shared zone containing all nonnegative-real clock valuations.

§Errors

Error::TooManyVariables if the requested clock count is too large.

§Complexity

O(d²) time and space for d = variables + 1.

Source

pub fn empty(variables: usize) -> Result<SharedDbm, Error>

Creates a shared empty zone with the requested number of actual clocks. The empty zone contains no valuations but retains its clock count.

§Errors

Error::TooManyVariables if the clock count is too large.

§Complexity

O(1) time, without allocating a matrix.

Source

pub fn try_from_constraints( variables: usize, cs: &[Constraint], ws: &mut Workspace, ) -> Result<SharedDbm, Error>

Creates a shared zone containing exactly the nonnegative-real valuations satisfying all constraints in cs. An inconsistent set returns an empty zone. ws does not affect the mathematical result.

§Errors

Error::TooManyVariables, Error::ClockOutOfRange, or Error::Range for an invalid clock count, invalid constraint index, or unrepresentable finite intermediate bound, respectively.

§Complexity

For d = variables + 1 and k = cs.len(), constructing the universe takes O(d²). Applying the constraints takes at most O(k d²) for k <= 4d, or O(k + d³) for larger batches.

Source

pub fn into_dbm(self) -> Dbm

Converts this zone into an owned Dbm, copying the matrix only if another shared handle still references it.

§Complexity

O(1) for a unique handle; O(d²) if another handle shares its matrix, where d = self.dimension().

Source

pub fn as_dbm(&self) -> &Dbm

Borrows the underlying canonical or empty Dbm without copying.

§Complexity

O(1) time.

Source

pub fn variables(&self) -> usize

Returns the number of actual clocks, excluding the reference clock.

§Complexity

O(1) time.

Source

pub fn dimension(&self) -> usize

Returns the number of actual clocks plus the reference clock.

§Complexity

O(1) time.

Source

pub fn is_empty(&self) -> bool

Returns whether this zone contains no clock valuations.

§Complexity

O(1) time.

Source

pub fn is_subset_of(&self, other: &SharedDbm) -> Result<bool, Error>

Tests whether every valuation in this zone also belongs to other. An empty zone is a subset of every zone of the same dimension.

§Errors

Error::DimensionMismatch for differing clock counts, including empty zones.

§Complexity

O(d²) in the worst case for matrix dimension d = self.dimension(); empty-zone cases take O(1).

Source

pub fn entails(&self, c: &Constraint) -> Result<bool, Error>

Tests whether every valuation in this zone satisfies c. This returns true for an empty zone (vacuously), unlike SharedDbm::intersects_constraint.

§Errors

Error::ClockOutOfRange if c references a clock outside this zone.

§Complexity

O(1) time.

Source

pub fn intersects_constraint(&self, c: &Constraint) -> Result<bool, Error>

Tests whether some valuation in this zone satisfies c. This returns false for an empty zone, unlike SharedDbm::entails.

§Errors

Error::ClockOutOfRange if c references a clock outside this zone.

§Complexity

O(1) time.

Source

pub fn difference_bound( &self, i: Clock, j: Clock, ) -> Result<Option<Bound>, Error>

Returns the tightest bound on the difference clock i - clock j satisfied by all valuations in this zone. Returns None for an empty zone or Bound::INFINITY for an unbounded difference.

§Errors

Error::ClockOutOfRange if either clock index is outside this zone.

§Complexity

O(1) time.

Source

pub fn try_constrain(self, c: Constraint) -> Result<SharedDbm, Error>

Returns the zone of valuations that satisfy this zone and c. An inconsistent constraint returns an empty zone. Other snapshots remain unchanged.

§Errors

Error::ClockOutOfRange for an invalid clock index, or Error::Range if exact closure needs an unrepresentable finite bound.

§Complexity

O(1) for an implied or directly contradictory constraint; otherwise O(d²) in the worst case, including any copy of a shared matrix, where d = self.dimension().

Source

pub fn try_constrain_all( self, cs: &[Constraint], ws: &mut Workspace, ) -> Result<SharedDbm, Error>

Restricts the zone to valuations satisfying every constraint in cs. An inconsistent conjunction returns an empty zone. Other snapshots remain unchanged; ws cannot affect the result.

§Errors

Error::ClockOutOfRange for an invalid clock index, or Error::Range for an unrepresentable finite intermediate bound.

§Complexity

Let d = self.dimension() and k = cs.len(). After O(k) argument and contradiction checks, the selected strategy takes at most O(k d²) for k <= 4d or O(k + d³) for larger batches. Updating a shared matrix may also require an O(d²) copy.

Source

pub fn try_intersect( self, other: &SharedDbm, ws: &mut Workspace, ) -> Result<SharedDbm, Error>

Returns the zone of valuations present in both input zones. An empty intersection is a successful empty result. Other snapshots remain unchanged.

§Errors

Error::DimensionMismatch for differing clock counts, or Error::Range if exact closure needs an unrepresentable finite bound. ws only reuses temporary storage.

§Complexity

O(d³) in the worst case for matrix dimension d = self.dimension(). Updating a shared matrix may add an O(d²) copy; certain no-change cases avoid copying.

Source

pub fn future(self) -> SharedDbm

Computes all valuations obtained by advancing every actual clock by the same nonnegative real delay. The reference clock remains zero and an empty zone remains empty. This operation cannot fail.

§Complexity

O(d) when uniquely owned; O(d²) when a shared matrix must first be copied, where d = self.dimension().

Source

pub fn past(self) -> SharedDbm

Computes all valuations from which this zone can be reached by advancing every actual clock by the same nonnegative real delay: { v ≥ 0 | v + t lies in this zone for some real t ≥ 0 }. Upper bounds and differences between actual clocks are kept; lower bounds are relaxed only as far as nonnegativity and the differences allow. The reference clock remains zero, the clock count is unchanged, an empty zone remains empty, and other handles to the same zone are not affected. This operation cannot fail.

§Complexity

O(d²) whether uniquely owned or shared (a shared matrix is first copied in O(d²)), where d = self.dimension().

§Examples
use clock_dbm::{Clock, Constraint, SharedDbm};

let x = Clock::new(1).unwrap();
let z = SharedDbm::universe(1)?.try_constrain(Constraint::le(Clock::ZERO, x, -3)?)?;
let snapshot = z.clone();
let p = z.past(); // x ≥ 3 becomes x ≥ 0
assert_eq!(p, SharedDbm::universe(1)?);
assert!(snapshot.is_subset_of(&p)?);
assert_ne!(snapshot, p);
Source

pub fn try_reset_zero(self, x: Variable) -> Result<SharedDbm, Error>

Sets clock x to zero in every valuation, preserving all other clock values. An empty zone remains empty.

§Errors

Error::ClockOutOfRange if x is not an actual clock of this zone.

§Complexity

O(d) when uniquely owned, or O(d²) if the matrix must be copied because it is shared, where d = self.dimension().

Source

pub fn try_reset(self, x: Variable, value: i32) -> Result<SharedDbm, Error>

Sets clock x to value in every valuation, keeping all other clock values unchanged. An empty zone remains empty.

§Errors

In order: Error::ClockOutOfRange if x is invalid, Error::NegativeConstant if value is negative, and Error::Range if the zone is nonempty and value exceeds crate::MAX_CONSTANT.

§Complexity

O(d) when uniquely owned, or O(d²) if the matrix must be copied because it is shared, where d = self.dimension().

Source

pub fn try_free(self, x: Variable) -> Result<SharedDbm, Error>

Allows clock x to take any nonnegative real value while keeping the values of all other clocks unchanged. The clock remains part of the zone; an empty zone remains empty.

§Errors

Error::ClockOutOfRange if x is not an actual clock of this zone.

§Complexity

O(d) when uniquely owned, or O(d²) if the matrix must be copied because it is shared, where d = self.dimension().

Source

pub fn try_extrapolate_max( self, bounds: &MaxBounds, ws: &mut Workspace, ) -> Result<SharedDbm, Error>

Returns a canonical maximal-constant overapproximation using the ceilings in bounds. Every original valuation remains possible, but additional valuations may appear. Reachability preservation requires the usual automaton-level restrictions on guards, invariants, resets and ceilings. An empty zone remains empty.

§Errors

Error::DimensionMismatch if the ceilings cover a different clock count, or Error::Range if closure needs an unrepresentable finite bound. ws only reuses temporary storage.

§Complexity

For d = self.dimension(), normalization takes O(d²); closure can take O(d³) if an entry changes. A shared matrix may also require an O(d²) copy before updating.

Trait Implementations§

Source§

impl AsRef<Dbm> for SharedDbm

Source§

fn as_ref(&self) -> &Dbm

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for SharedDbm

Source§

fn clone(&self) -> SharedDbm

Copies the pointer, not the matrix.

1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SharedDbm

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl DeepModel for SharedDbm

Source§

impl Eq for SharedDbm

Source§

impl From<Dbm> for SharedDbm

Source§

fn from(z: Dbm) -> SharedDbm

Wraps z without copying its matrix.

Source§

impl Hash for SharedDbm

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Invariant for SharedDbm

Every handle denotes a valid Dbm: canonical or empty.

Source§

impl PartialEq for SharedDbm

Source§

fn eq(&self, other: &SharedDbm) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl View for SharedDbm

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<F> FnGhost for F

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.