From 14026bc8506f2c3864f34bcf9ac259c26c876628 Mon Sep 17 00:00:00 2001 From: JakkuSakura Date: Wed, 22 May 2024 23:46:46 +0800 Subject: [PATCH] feat: retain & clear --- src/worktable.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/worktable.rs b/src/worktable.rs index d2781a6..896fae9 100644 --- a/src/worktable.rs +++ b/src/worktable.rs @@ -245,10 +245,17 @@ impl WorkTable { } } pub fn retain(&mut self, f: impl Fn(&RowViewMut) -> bool) { - self.iter_mut().filter(f).for_each(|row| { + // remove from reverse order is generally faster + self.iter_mut().rev().filter(|x| !f(x)).for_each(|row| { row.remove(); }); } + pub fn clear(&mut self) { + self.column_values.iter_mut().for_each(|x| x.clear()); + if let Some(primary_map) = &mut self.primary_map { + primary_map.clear(); + } + } } pub type SyncWorkTable = Arc>;