Skip to content

Commit 5ed8773

Browse files
committed
Add stomp() method to CoordinateSet
1 parent 65f4e14 commit 5ed8773

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/coordinate/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,20 @@ impl<T> CoordinateMetadata for T where T: ?Sized {}
8787
/// access any user provided data model by iterating over its elements,
8888
/// represented as a `Coor4D`
8989
pub trait CoordinateSet: CoordinateMetadata {
90+
/// Number of coordinate tuples in the set
9091
fn len(&self) -> usize;
92+
/// Access the `index`th coordinate tuple
9193
fn get_coord(&self, index: usize) -> Coor4D;
94+
/// Overwrite the `index`th coordinate tuple
9295
fn set_coord(&mut self, index: usize, value: &Coor4D);
9396
fn is_empty(&self) -> bool {
9497
self.len() == 0
9598
}
99+
/// Set all coordinate tuples in the set to NaN
100+
fn stomp(&mut self) {
101+
let nanny = Coor4D::nan();
102+
for i in 0..self.len() {
103+
self.set_coord(i, &nanny);
104+
}
105+
}
96106
}

src/inner_op/stack.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,7 @@ fn stack_flip(stack: &mut [Vec<f64>], operands: &mut dyn CoordinateSet, args: &[
269269
// In case of underflow, we stomp on all input coordinates
270270
if stack_depth < number_of_flips {
271271
warn!("Stack flip underflow in pipeline");
272-
let nanny = Coor4D::nan();
273-
for i in 0..number_of_operands {
274-
operands.set_coord(i, &nanny);
275-
}
272+
operands.stomp();
276273
return 0;
277274
}
278275

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

312309
if m > depth {
313310
warn!("Roll too deep");
314-
let nanny = Coor4D::nan();
315-
for i in 0..operands.len() {
316-
operands.set_coord(i, &nanny);
317-
}
311+
operands.stomp();
318312
return 0;
319313
}
320314

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

0 commit comments

Comments
 (0)