Skip to content

Commit

Permalink
Add stomp() method to CoordinateSet
Browse files Browse the repository at this point in the history
  • Loading branch information
busstoptaktik committed Mar 19, 2024
1 parent 65f4e14 commit 5ed8773
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
10 changes: 10 additions & 0 deletions src/coordinate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,20 @@ impl<T> CoordinateMetadata for T where T: ?Sized {}
/// access any user provided data model by iterating over its elements,
/// represented as a `Coor4D`
pub trait CoordinateSet: CoordinateMetadata {
/// Number of coordinate tuples in the set
fn len(&self) -> usize;
/// Access the `index`th coordinate tuple
fn get_coord(&self, index: usize) -> Coor4D;
/// Overwrite the `index`th coordinate tuple
fn set_coord(&mut self, index: usize, value: &Coor4D);
fn is_empty(&self) -> bool {
self.len() == 0
}
/// Set all coordinate tuples in the set to NaN
fn stomp(&mut self) {
let nanny = Coor4D::nan();
for i in 0..self.len() {
self.set_coord(i, &nanny);
}
}
}
15 changes: 3 additions & 12 deletions src/inner_op/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,7 @@ fn stack_flip(stack: &mut [Vec<f64>], operands: &mut dyn CoordinateSet, args: &[
// In case of underflow, we stomp on all input coordinates
if stack_depth < number_of_flips {
warn!("Stack flip underflow in pipeline");
let nanny = Coor4D::nan();
for i in 0..number_of_operands {
operands.set_coord(i, &nanny);
}
operands.stomp();
return 0;
}

Expand Down Expand Up @@ -311,10 +308,7 @@ fn stack_roll(stack: &mut Vec<Vec<f64>>, operands: &mut dyn CoordinateSet, args:

if m > depth {
warn!("Roll too deep");
let nanny = Coor4D::nan();
for i in 0..operands.len() {
operands.set_coord(i, &nanny);
}
operands.stomp();
return 0;
}

Expand All @@ -335,10 +329,7 @@ fn stack_pop(stack: &mut Vec<Vec<f64>>, operands: &mut dyn CoordinateSet, args:
// In case of underflow, we stomp on all input coordinates
if stack_depth < number_of_pops {
warn!("Stack underflow in pipeline");
let nanny = Coor4D::nan();
for i in 0..number_of_operands {
operands.set_coord(i, &nanny);
}
operands.stomp();
return 0;
}

Expand Down

0 comments on commit 5ed8773

Please sign in to comment.