Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional helper methods for VarRange #46

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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