This is an automated email from the ASF dual-hosted git repository. tisonkun pushed a commit to branch flatten-collect_retained_entries in repository https://gitbox.apache.org/repos/asf/datasketches-rust.git
commit aa6b9e174c4eefdb161dd9ced3e1ee60539e5837 Author: tison <[email protected]> AuthorDate: Thu Nov 12 15:26:11 2026 +0800 refactor: flatten collect_retained_entries Signed-off-by: tison <[email protected]> --- datasketches/src/thetafamily/common/union.rs | 31 +++++++++++++++------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/datasketches/src/thetafamily/common/union.rs b/datasketches/src/thetafamily/common/union.rs index 5d53862..caed199 100644 --- a/datasketches/src/thetafamily/common/union.rs +++ b/datasketches/src/thetafamily/common/union.rs @@ -115,7 +115,17 @@ where let Some(theta) = self.result_theta else { return CompactSketchState::empty(self.table.seed_hash()); }; - let entries = self.collect_retained_entries(theta, Clone::clone); + + let entries = if theta >= self.table.retention_theta() { + self.table.iter_entries().cloned().collect() + } else { + self.table + .iter_entries() + .filter(|&ent| ent.hash() < theta) + .cloned() + .collect() + }; + self.finish_compaction(entries, theta, ordered) } @@ -143,24 +153,17 @@ where let Some(theta) = self.result_theta else { return CompactSketchState::empty(self.table.seed_hash()); }; - let entries = self.collect_retained_entries(theta, |entry| entry); - self.finish_compaction(entries, theta, ordered) - } - fn collect_retained_entries<'a, T>( - &'a self, - theta: u64, - map: impl FnMut(&'a E) -> T, - ) -> Vec<T> { - if theta >= self.table.retention_theta() { - self.table.iter_entries().map(map).collect() + let entries = if theta >= self.table.retention_theta() { + self.table.iter_entries().collect() } else { self.table .iter_entries() - .filter(|entry| entry.hash() < theta) - .map(map) + .filter(|ent| ent.hash() < theta) .collect() - } + }; + + self.finish_compaction(entries, theta, ordered) } fn finish_compaction<T: SketchEntry>( --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
