From 64c0657f5f3bd4fa541bb1d44504d186ece7c766 Mon Sep 17 00:00:00 2001 From: Mingwei Samuel Date: Wed, 29 Jan 2025 10:40:45 -0800 Subject: [PATCH 1/2] chore(dfir_rs): remove unused cross_join, fix #1616 --- dfir_rs/src/compiled/pull/mod.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/dfir_rs/src/compiled/pull/mod.rs b/dfir_rs/src/compiled/pull/mod.rs index 2872fb8ab0c6..3f6e6e5ec0a9 100644 --- a/dfir_rs/src/compiled/pull/mod.rs +++ b/dfir_rs/src/compiled/pull/mod.rs @@ -1,9 +1,6 @@ //! Pull-based operator helpers, i.e. [`Iterator`] helpers. #![allow(missing_docs, reason = "// TODO(mingwei)")] -mod cross_join; -pub use cross_join::*; - mod symmetric_hash_join; pub use symmetric_hash_join::*; From d3191273f2a38bc19f2cb92a178e45a4e4d492cc Mon Sep 17 00:00:00 2001 From: Mingwei Samuel Date: Wed, 29 Jan 2025 10:41:18 -0800 Subject: [PATCH 2/2] fixup! chore(dfir_rs): remove unused cross_join, fix #1616 --- dfir_rs/src/compiled/pull/cross_join.rs | 128 ------------------------ 1 file changed, 128 deletions(-) delete mode 100644 dfir_rs/src/compiled/pull/cross_join.rs diff --git a/dfir_rs/src/compiled/pull/cross_join.rs b/dfir_rs/src/compiled/pull/cross_join.rs deleted file mode 100644 index 6b9629fa65f9..000000000000 --- a/dfir_rs/src/compiled/pull/cross_join.rs +++ /dev/null @@ -1,128 +0,0 @@ -use std::ops::Range; - -pub struct CrossJoinState { - ltab: Vec, - rtab: Vec, - draw_from_left: bool, - opposite_ix: Range, -} - -impl Default for CrossJoinState { - fn default() -> Self { - Self { - ltab: Vec::new(), - rtab: Vec::new(), - draw_from_left: true, - opposite_ix: 0..0, - } - } -} - -pub struct CrossJoin<'a, I1, V1, I2, V2> -where - V1: Eq + Clone, - V2: Eq + Clone, - I1: Iterator, - I2: Iterator, -{ - lhs: I1, - rhs: I2, - state: &'a mut CrossJoinState, -} - -impl Iterator for CrossJoin<'_, I1, V1, I2, V2> -where - V1: Eq + Clone, - V2: Eq + Clone, - I1: Iterator, - I2: Iterator, -{ - type Item = (V1, V2); - - fn next(&mut self) -> Option { - loop { - // see if there's a match from the opposite's iterator - if let Some(i) = self.state.opposite_ix.next() { - if self.state.draw_from_left { - let l = self.state.ltab.last().unwrap().clone(); - let r = self.state.rtab.get(i).unwrap().clone(); - return Some((l, r)); - } else { - let l = self.state.ltab.get(i).unwrap().clone(); - let r = self.state.rtab.last().unwrap().clone(); - return Some((l, r)); - } - } - // else fetch a new tuple, alternating the sides we fetch from, - // so we draw from each input at the same rate. - let mut found_new = false; - for _i in ["opposite", "same"] { - // toggle sides - self.state.draw_from_left = !self.state.draw_from_left; - - // try to fetch from the specified side - #[expect(clippy::collapsible_else_if, reason = "code symmetry")] - if self.state.draw_from_left { - if let Some(l) = self.lhs.next() { - self.state.draw_from_left = true; - self.state.ltab.push(l); - self.state.opposite_ix = 0..self.state.rtab.len(); - found_new = true; - break; - } - } else { - if let Some(r) = self.rhs.next() { - self.state.draw_from_left = false; - self.state.rtab.push(r); - self.state.opposite_ix = 0..self.state.ltab.len(); - found_new = true; - break; - } - } - } - if !found_new { - return None; - } - } - } -} -impl<'a, I1, V1, I2, V2> CrossJoin<'a, I1, V1, I2, V2> -where - V1: Eq + Clone, - V2: Eq + Clone, - I1: Iterator, - I2: Iterator, -{ - pub fn new(lhs: I1, rhs: I2, state: &'a mut CrossJoinState) -> Self { - Self { lhs, rhs, state } - } -} - -#[cfg(test)] -mod tests { - use super::{CrossJoin, CrossJoinState}; - - #[test] - fn cross_join() { - let lhs = (0..3).map(|x| (format!("left {}", x))); - let rhs = (10..13).map(|x| (format!("right {}", x))); - - let mut state = CrossJoinState::default(); - let join = CrossJoin::new(lhs, rhs, &mut state); - - assert_eq!( - join.collect::>(), - vec![ - ("left 0".into(), "right 10".into()), - ("left 0".into(), "right 11".into()), - ("left 1".into(), "right 10".into()), - ("left 1".into(), "right 11".into()), - ("left 0".into(), "right 12".into()), - ("left 1".into(), "right 12".into()), - ("left 2".into(), "right 10".into()), - ("left 2".into(), "right 11".into()), - ("left 2".into(), "right 12".into()) - ] - ); - } -}