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§
Sourcepub fn zero(variables: usize) -> Result<SharedDbm, Error>
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.
Sourcepub fn universe(variables: usize) -> Result<SharedDbm, Error>
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.
Sourcepub fn empty(variables: usize) -> Result<SharedDbm, Error>
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.
Sourcepub fn try_from_constraints(
variables: usize,
cs: &[Constraint],
ws: &mut Workspace,
) -> Result<SharedDbm, Error>
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.
Sourcepub fn is_subset_of(&self, other: &SharedDbm) -> Result<bool, Error>
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).
Sourcepub fn entails(&self, c: &Constraint) -> Result<bool, Error>
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.
Sourcepub fn intersects_constraint(&self, c: &Constraint) -> Result<bool, Error>
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.
Sourcepub fn difference_bound(
&self,
i: Clock,
j: Clock,
) -> Result<Option<Bound>, Error>
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.
Sourcepub fn try_constrain(self, c: Constraint) -> Result<SharedDbm, Error>
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().
Sourcepub fn try_constrain_all(
self,
cs: &[Constraint],
ws: &mut Workspace,
) -> Result<SharedDbm, Error>
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.
Sourcepub fn try_intersect(
self,
other: &SharedDbm,
ws: &mut Workspace,
) -> Result<SharedDbm, Error>
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.
Sourcepub fn future(self) -> SharedDbm
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().
Sourcepub fn past(self) -> SharedDbm
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);Sourcepub fn try_reset_zero(self, x: Variable) -> Result<SharedDbm, Error>
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().
Sourcepub fn try_reset(self, x: Variable, value: i32) -> Result<SharedDbm, Error>
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().
Sourcepub fn try_free(self, x: Variable) -> Result<SharedDbm, Error>
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().
Sourcepub fn try_extrapolate_max(
self,
bounds: &MaxBounds,
ws: &mut Workspace,
) -> Result<SharedDbm, Error>
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.