File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -237,8 +237,24 @@ impl <T: Ord> TreeSet<T> {
237
237
/// Return true if the set has no elements in common with `other`.
238
238
/// This is equivalent to checking for an empty intersection.
239
239
pure fn is_disjoint( & self , other: & TreeSet <T >) -> bool {
240
- // FIXME: this is a naive O(n*log(m)) implementation, could be O(n + m)
241
- !iter:: any( self , |x| other. contains( x) )
240
+ let mut x = self . iter( ) ;
241
+ let mut y = other. iter( ) ;
242
+ unsafe { // purity workaround
243
+ let mut a = x. next( ) ;
244
+ let mut b = y. next( ) ;
245
+ while a. is_some( ) && b. is_some( ) {
246
+ let a1 = a. unwrap( ) ;
247
+ let b1 = b. unwrap( ) ;
248
+ if a1 < b1 {
249
+ a = x. next( ) ;
250
+ } else if b1 < a1 {
251
+ b = y. next( ) ;
252
+ } else {
253
+ return false;
254
+ }
255
+ }
256
+ }
257
+ true
242
258
}
243
259
244
260
/// Check of the set is a subset of another
You can’t perform that action at this time.
0 commit comments