Skip to content

Commit b47ec4e

Browse files
lqdnikomatsakis
authored andcommitted
Deduplicate gallop
1 parent 5224d8a commit b47ec4e

File tree

1 file changed

+4
-27
lines changed

1 file changed

+4
-27
lines changed

src/treefrog.rs

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ impl<Key: Ord, Val: Ord> RelationLeaper<Key, Val> for Relation<(Key, Val)> {
8989
}
9090

9191
mod extend_with {
92-
93-
use super::{Relation, Leaper, gallop, binary_search};
92+
use join::gallop;
93+
use super::{Relation, Leaper, binary_search};
9494

9595
/// Wraps a Relation<Tuple> as a leaper.
9696
pub struct ExtendWith<'a, Key: Ord+'a, Val: Ord+'a, Tuple: Ord, Func: Fn(&Tuple)->Key> {
@@ -139,8 +139,8 @@ mod extend_with {
139139
}
140140

141141
mod extend_anti {
142-
143-
use super::{Relation, Leaper, gallop, binary_search};
142+
use join::gallop;
143+
use super::{Relation, Leaper, binary_search};
144144

145145
/// Wraps a Relation<Tuple> as a leaper.
146146
pub struct ExtendAnti<'a, Key: Ord+'a, Val: Ord+'a, Tuple: Ord, Func: Fn(&Tuple)->Key> {
@@ -283,26 +283,3 @@ fn binary_search<T>(slice: &[T], mut cmp: impl FnMut(&T)->bool) -> usize {
283283
}
284284
lo
285285
}
286-
287-
fn gallop<T>(mut slice: &[T], mut cmp: impl FnMut(&T)->bool) -> &[T] {
288-
// if empty slice, or already >= element, return
289-
if slice.len() > 0 && cmp(&slice[0]) {
290-
let mut step = 1;
291-
while step < slice.len() && cmp(&slice[step]) {
292-
slice = &slice[step..];
293-
step = step << 1;
294-
}
295-
296-
step = step >> 1;
297-
while step > 0 {
298-
if step < slice.len() && cmp(&slice[step]) {
299-
slice = &slice[step..];
300-
}
301-
step = step >> 1;
302-
}
303-
304-
slice = &slice[1..]; // advance one, as we always stayed < value
305-
}
306-
307-
return slice;
308-
}

0 commit comments

Comments
 (0)