Skip to content

Commit edd36fa

Browse files
authored
Add mutable access to NodeTable flag and time arrays. (#125)
Closes #121
1 parent 634df56 commit edd36fa

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/node_table.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ impl<'a> NodeTable<'a> {
104104
unsafe_tsk_column_access!(row, 0, self.num_rows(), self.table_.flags)
105105
}
106106

107+
/// Mutable access to node flags.
108+
pub fn flags_array_mut(&mut self) -> &mut [tsk_flags_t] {
109+
unsafe { std::slice::from_raw_parts_mut(self.table_.flags, self.table_.num_rows as usize) }
110+
}
111+
112+
/// Mutable access to node times.
113+
pub fn time_array_mut(&mut self) -> &mut [f64] {
114+
unsafe { std::slice::from_raw_parts_mut(self.table_.time, self.table_.num_rows as usize) }
115+
}
116+
107117
/// Return the ``population`` value from row ``row`` of the table.
108118
///
109119
/// # Errors

src/table_collection.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,25 @@ mod test {
696696
}
697697
}
698698

699+
#[test]
700+
fn test_mutable_node_access() {
701+
let tables = TableCollection::new(1000.).unwrap();
702+
let mut nodes = tables.nodes();
703+
let f = nodes.flags_array_mut();
704+
for i in f {
705+
*i = 11;
706+
}
707+
708+
for t in nodes.time_array_mut() {
709+
*t = -33.0;
710+
}
711+
712+
for i in tables.nodes_iter(true) {
713+
assert_eq!(i.flags, 11);
714+
assert_eq!(i.time as i64, -33);
715+
}
716+
}
717+
699718
#[test]
700719
fn test_node_iteration() {
701720
let tables = make_small_table_collection();

0 commit comments

Comments
 (0)