File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -338,10 +338,24 @@ impl <T: Ord> TreeSet<T> {
338
338
339
339
/// Visit the values (in-order) representing the intersection
340
340
pure fn intersection( & self , other: & TreeSet <T >, f: fn ( & T ) -> bool ) {
341
- // FIXME: this is a naive O(n*log(m)) implementation, could be O(n + m)
342
- for self . each |x| {
343
- if other. contains( x) {
344
- if !f ( x) { break }
341
+ let mut x = self . iter( ) ;
342
+ let mut y = other. iter( ) ;
343
+
344
+ unsafe { // purity workaround
345
+ let mut a = x. next( ) ;
346
+ let mut b = y. next( ) ;
347
+
348
+ while a. is_some( ) && b. is_some( ) {
349
+ let a1 = a. unwrap( ) ;
350
+ let b1 = b. unwrap( ) ;
351
+ if a1 < b1 {
352
+ a = x. next( ) ;
353
+ } else {
354
+ if !( b1 < a1) {
355
+ if !f( a1) { return }
356
+ }
357
+ b = y. next( ) ;
358
+ }
345
359
}
346
360
}
347
361
}
You can’t perform that action at this time.
0 commit comments