solverforge_scoring/stream/joiner/
plan.rs1use super::match_condition::AndJoiner;
10use super::{EqualJoiner, FilteringJoiner};
11use super::{GreaterThanJoiner, GreaterThanOrEqualJoiner, LessThanJoiner, LessThanOrEqualJoiner};
12use super::{Joiner, OverlappingJoiner};
13mod composite;
14mod conjunction;
15pub use composite::{
16 ComposePlans, CompositeEquality, EqualityKeys, EqualityKind, EqualityPlan, ResidualKind,
17};
18mod executable;
19mod hash_scan;
20mod mixed_equality;
21pub use mixed_equality::EqualityWithResidual;
22mod ordered_interval;
23pub use executable::{CompileCondition, ExecutablePlan, IndexedPlan};
24
25#[derive(Clone, Copy, Debug, PartialEq, Eq)]
27pub enum Strategy {
28 EquiHash,
30 OrderedScan,
32 IntervalNarrow,
34 Scan,
36}
37
38impl Strategy {
39 #[inline]
42 pub const fn combine(self, other: Strategy) -> Strategy {
43 match (self, other) {
44 (Strategy::EquiHash, _) | (_, Strategy::EquiHash) => Strategy::EquiHash,
45 (Strategy::OrderedScan, _) | (_, Strategy::OrderedScan) => Strategy::OrderedScan,
46 (Strategy::IntervalNarrow, _) | (_, Strategy::IntervalNarrow) => {
47 Strategy::IntervalNarrow
48 }
49 (Strategy::Scan, Strategy::Scan) => Strategy::Scan,
50 }
51 }
52}
53
54pub trait PlannedCondition<Row, C>: Send + Sync {
60 const STRATEGY: Strategy;
62
63 fn check(&self, row: &Row, c: &C) -> bool;
65}
66
67#[inline]
69pub fn plan_strategy<Row, C, P>(condition: &P) -> Strategy
70where
71 P: PlannedCondition<Row, C>,
72{
73 let _ = condition;
74 P::STRATEGY
75}
76
77impl<Row, C, Fa, Fb, T, Mode> PlannedCondition<Row, C> for EqualJoiner<Fa, Fb, T, Mode>
78where
79 T: PartialEq,
80 Fa: Fn(&Row) -> T + Send + Sync,
81 Fb: Fn(&C) -> T + Send + Sync,
82{
83 const STRATEGY: Strategy = Strategy::EquiHash;
84
85 #[inline]
86 fn check(&self, row: &Row, c: &C) -> bool {
87 self.matches(row, c)
88 }
89}
90
91impl<Row, C, Fa, Fb, T> PlannedCondition<Row, C> for LessThanJoiner<Fa, Fb, T>
92where
93 T: Ord,
94 Fa: Fn(&Row) -> T + Send + Sync,
95 Fb: Fn(&C) -> T + Send + Sync,
96{
97 const STRATEGY: Strategy = Strategy::OrderedScan;
98
99 #[inline]
100 fn check(&self, row: &Row, c: &C) -> bool {
101 self.matches(row, c)
102 }
103}
104
105impl<Row, C, Fa, Fb, T> PlannedCondition<Row, C> for LessThanOrEqualJoiner<Fa, Fb, T>
106where
107 T: Ord,
108 Fa: Fn(&Row) -> T + Send + Sync,
109 Fb: Fn(&C) -> T + Send + Sync,
110{
111 const STRATEGY: Strategy = Strategy::OrderedScan;
112
113 #[inline]
114 fn check(&self, row: &Row, c: &C) -> bool {
115 self.matches(row, c)
116 }
117}
118
119impl<Row, C, Fa, Fb, T> PlannedCondition<Row, C> for GreaterThanJoiner<Fa, Fb, T>
120where
121 T: Ord,
122 Fa: Fn(&Row) -> T + Send + Sync,
123 Fb: Fn(&C) -> T + Send + Sync,
124{
125 const STRATEGY: Strategy = Strategy::OrderedScan;
126
127 #[inline]
128 fn check(&self, row: &Row, c: &C) -> bool {
129 self.matches(row, c)
130 }
131}
132
133impl<Row, C, Fa, Fb, T> PlannedCondition<Row, C> for GreaterThanOrEqualJoiner<Fa, Fb, T>
134where
135 T: Ord,
136 Fa: Fn(&Row) -> T + Send + Sync,
137 Fb: Fn(&C) -> T + Send + Sync,
138{
139 const STRATEGY: Strategy = Strategy::OrderedScan;
140
141 #[inline]
142 fn check(&self, row: &Row, c: &C) -> bool {
143 self.matches(row, c)
144 }
145}
146
147impl<Row, C, Fsa, Fea, Fsb, Feb, T> PlannedCondition<Row, C>
148 for OverlappingJoiner<Fsa, Fea, Fsb, Feb, T>
149where
150 T: Ord,
151 Fsa: Fn(&Row) -> T + Send + Sync,
152 Fea: Fn(&Row) -> T + Send + Sync,
153 Fsb: Fn(&C) -> T + Send + Sync,
154 Feb: Fn(&C) -> T + Send + Sync,
155{
156 const STRATEGY: Strategy = Strategy::IntervalNarrow;
157
158 #[inline]
159 fn check(&self, row: &Row, c: &C) -> bool {
160 self.matches(row, c)
161 }
162}
163
164impl<Row, C, F> PlannedCondition<Row, C> for FilteringJoiner<F>
165where
166 F: Fn(&Row, &C) -> bool + Send + Sync,
167{
168 const STRATEGY: Strategy = Strategy::Scan;
169
170 #[inline]
171 fn check(&self, row: &Row, c: &C) -> bool {
172 self.matches(row, c)
173 }
174}
175
176impl<Row, C, J1, J2> PlannedCondition<Row, C> for AndJoiner<J1, J2>
177where
178 J1: PlannedCondition<Row, C> + Joiner<Row, C>,
179 J2: PlannedCondition<Row, C> + Joiner<Row, C>,
180{
181 const STRATEGY: Strategy = J1::STRATEGY.combine(J2::STRATEGY);
182
183 #[inline]
184 fn check(&self, row: &Row, c: &C) -> bool {
185 self.matches(row, c)
186 }
187}