Skip to content

Commit

Permalink
Add additional helper methods for VarRange
Browse files Browse the repository at this point in the history
  • Loading branch information
Dekker1 committed Apr 16, 2024
1 parent bf2d672 commit 9ee5ae6
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions crates/pindakaas/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,42 @@ impl VarRange {
Self { start, end }
}

/// Returns the lower bound of the variable range (inclusive).
///
/// Note: the value returned by this method is unspecified after the range
/// has been iterated to exhaustion.
pub fn start(&self) -> Var {
self.start
}

/// Returns the upper bound of the variable range (inclusive).
///
/// Note: the value returned by this method is unspecified after the range
/// has been iterated to exhaustion.
pub fn end(&self) -> Var {
self.end
}

/// Create an empty variable range
pub fn empty() -> Self {
Self {
start: Var(NonZeroI32::new(2).unwrap()),
end: Var(NonZeroI32::new(1).unwrap()),
}
}

/// Returns `true` if the range contains no items.
///
/// # Examples
///
/// ```
/// # use pindakaas::solver::VarRange;
/// assert!(VarRange::empty().is_empty());
/// ```
pub fn is_empty(&self) -> bool {
self.start > self.end
}

/// Performs the indexing operation into the variable range
pub fn index(&self, index: usize) -> Var {
if index >= self.len() {
Expand Down

0 comments on commit 9ee5ae6

Please sign in to comment.