@@ -135,12 +135,12 @@ impl OrderingEquivalenceClass {
135
135
let mut ordering_idx = idx + 1 ;
136
136
let mut removal = self . orderings [ idx] . is_empty ( ) ;
137
137
while ordering_idx < self . orderings . len ( ) {
138
- work |= resolve_overlap ( & mut self . orderings , idx, ordering_idx) ;
138
+ work |= self . resolve_overlap ( idx, ordering_idx) ;
139
139
if self . orderings [ idx] . is_empty ( ) {
140
140
removal = true ;
141
141
break ;
142
142
}
143
- work |= resolve_overlap ( & mut self . orderings , ordering_idx, idx) ;
143
+ work |= self . resolve_overlap ( ordering_idx, idx) ;
144
144
if self . orderings [ ordering_idx] . is_empty ( ) {
145
145
self . orderings . swap_remove ( ordering_idx) ;
146
146
} else {
@@ -156,6 +156,26 @@ impl OrderingEquivalenceClass {
156
156
}
157
157
}
158
158
159
+ /// Trims `orderings[idx]` if some suffix of it overlaps with a prefix of
160
+ /// `orderings[pre_idx]`. Returns `true` if there is any overlap, `false` otherwise.
161
+ ///
162
+ /// For example, if `orderings[idx]` is `[a ASC, b ASC, c DESC]` and
163
+ /// `orderings[pre_idx]` is `[b ASC, c DESC]`, then the function will trim
164
+ /// `orderings[idx]` to `[a ASC]`.
165
+ fn resolve_overlap ( & mut self , idx : usize , pre_idx : usize ) -> bool {
166
+ let length = self . orderings [ idx] . len ( ) ;
167
+ let other_length = self . orderings [ pre_idx] . len ( ) ;
168
+ for overlap in 1 ..=length. min ( other_length) {
169
+ if self . orderings [ idx] [ length - overlap..]
170
+ == self . orderings [ pre_idx] [ ..overlap]
171
+ {
172
+ self . orderings [ idx] . truncate ( length - overlap) ;
173
+ return true ;
174
+ }
175
+ }
176
+ false
177
+ }
178
+
159
179
/// Returns the concatenation of all the orderings. This enables merge
160
180
/// operations to preserve all equivalent orderings simultaneously.
161
181
pub fn output_ordering ( & self ) -> Option < LexOrdering > {
@@ -226,20 +246,6 @@ impl IntoIterator for OrderingEquivalenceClass {
226
246
}
227
247
}
228
248
229
- /// Trims `orderings[idx]` if some suffix of it overlaps with a prefix of
230
- /// `orderings[pre_idx]`. Returns `true` if there is any overlap, `false` otherwise.
231
- fn resolve_overlap ( orderings : & mut [ LexOrdering ] , idx : usize , pre_idx : usize ) -> bool {
232
- let length = orderings[ idx] . len ( ) ;
233
- let other_length = orderings[ pre_idx] . len ( ) ;
234
- for overlap in 1 ..=length. min ( other_length) {
235
- if orderings[ idx] [ length - overlap..] == orderings[ pre_idx] [ ..overlap] {
236
- orderings[ idx] . truncate ( length - overlap) ;
237
- return true ;
238
- }
239
- }
240
- false
241
- }
242
-
243
249
impl Display for OrderingEquivalenceClass {
244
250
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
245
251
write ! ( f, "[" ) ?;
0 commit comments