Skip to content

Commit

Permalink
feat: Some helper methods (#482)
Browse files Browse the repository at this point in the history
Adds a couple of helper methods that'd be useful downstream.

- `OpType::is_container`
- `CircuitUnit::is_linear` and `is_wire`
  • Loading branch information
aborgna-q committed Sep 1, 2023
1 parent 1b83640 commit 7a43175
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/hugr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,18 @@ pub enum CircuitUnit {
Linear(usize),
}

impl CircuitUnit {
/// Check if this is a wire.
pub fn is_wire(&self) -> bool {
matches!(self, CircuitUnit::Wire(_))
}

/// Check if this is a linear unit.
pub fn is_linear(&self) -> bool {
matches!(self, CircuitUnit::Linear(_))
}
}

impl From<usize> for CircuitUnit {
fn from(value: usize) -> Self {
CircuitUnit::Linear(value)
Expand Down
5 changes: 5 additions & 0 deletions src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ impl OpType {
pub fn output_count(&self) -> usize {
self.port_count(Direction::Outgoing)
}

/// Checks whether the operation can contain children nodes.
pub fn is_container(&self) -> bool {
self.validity_flags().allowed_children != OpTag::None
}
}

/// Macro used by operations that want their
Expand Down

0 comments on commit 7a43175

Please sign in to comment.