dfir_rs/compiled/pull/half_join_state/
mod.rs

1use std::borrow::Cow;
2
3/// State semantics for each half of a join.
4use smallvec::SmallVec;
5
6mod multiset;
7pub use multiset::HalfMultisetJoinState;
8
9mod set;
10pub use set::HalfSetJoinState;
11
12/// State semantics for each half of a join.
13pub trait HalfJoinState<Key, ValBuild, ValProbe>
14where
15    ValBuild: Clone,
16{
17    /// Insert a key value pair into the join state, currently this is always inserting into a hash table
18    /// If the key-value pair exists then it is implementation defined what happens, usually either two copies are stored or only one copy is stored.
19    fn build(&mut self, k: Key, v: Cow<'_, ValBuild>) -> bool;
20
21    /// This function does the actual joining part of the join. It looks up a key in the local join state and creates matches
22    /// The first match is return directly to the caller, and any additional matches are stored internally to be retrieved later with `pop_match`
23    fn probe(&mut self, k: &Key, v: &ValProbe) -> Option<(Key, ValProbe, ValBuild)>;
24
25    /// If there are any stored matches from previous calls to probe then this function will remove them one at a time and return it.
26    fn pop_match(&mut self) -> Option<(Key, ValProbe, ValBuild)>;
27
28    /// Len of the join state in terms of number of keys.
29    fn len(&self) -> usize;
30    /// If the state is empty (`len() == 0`).
31    fn is_empty(&self) -> bool {
32        0 == self.len()
33    }
34
35    /// An iter over all entries of the state.
36    fn iter(&self) -> std::collections::hash_map::Iter<'_, Key, SmallVec<[ValBuild; 1]>>;
37
38    /// An iter over all the matches for a given key.
39    fn full_probe(&self, k: &Key) -> std::slice::Iter<'_, ValBuild>;
40}