dfir_pipes/pull/half_join_state/mod.rs
1//! State management for symmetric hash joins.
2//!
3//! This module provides the [`HalfJoinState`] trait and implementations for
4//! managing the state of each half of a symmetric hash join operation.
5
6use std::borrow::Cow;
7
8use smallvec::SmallVec;
9
10mod multiset;
11pub use multiset::HalfMultisetJoinState;
12
13mod set;
14pub use set::HalfSetJoinState;
15
16/// State semantics for each half of a join.
17///
18/// This trait defines the interface for storing and probing join state.
19/// Different implementations provide different semantics (set vs multiset).
20pub trait HalfJoinState<Key, ValBuild, ValProbe>
21where
22 ValBuild: Clone,
23{
24 /// Insert a key-value pair into the join state.
25 ///
26 /// Returns `true` if the pair was inserted (implementation-defined for duplicates).
27 fn build(&mut self, k: Key, v: Cow<'_, ValBuild>) -> bool;
28
29 /// Probe the join state for matches with the given key and value.
30 ///
31 /// Returns the first match directly. Additional matches are stored internally
32 /// and can be retrieved with [`pop_match`](Self::pop_match).
33 fn probe(&mut self, k: &Key, v: &ValProbe) -> Option<(Key, ValProbe, ValBuild)>;
34
35 /// Pop a stored match from previous [`probe`](Self::probe) calls.
36 fn pop_match(&mut self) -> Option<(Key, ValProbe, ValBuild)>;
37
38 /// Returns the number of keys in the join state.
39 fn len(&self) -> usize;
40
41 /// Returns `true` if the state is empty.
42 fn is_empty(&self) -> bool {
43 0 == self.len()
44 }
45
46 /// Returns an iterator over all entries in the state.
47 fn iter(&self) -> std::collections::hash_map::Iter<'_, Key, SmallVec<[ValBuild; 1]>>;
48
49 /// Returns an iterator over all values for a given key.
50 fn full_probe(&self, k: &Key) -> std::slice::Iter<'_, ValBuild>;
51
52 /// Clear the state without de-allocating.
53 fn clear(&mut self);
54}