File tree Expand file tree Collapse file tree 2 files changed +26
-4
lines changed Expand file tree Collapse file tree 2 files changed +26
-4
lines changed Original file line number Diff line number Diff line change 1
1
---
2
- refs/heads/master: 4f92d8fb52ba335abae39bdd38e72ff42cd37bb2
2
+ refs/heads/master: 3fe6faace83c3f07c11b92f463ab93aad8f5dd41
3
3
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4
4
refs/heads/snap-stage3: 2f46b763da2c098913884f101b6d71d69af41b49
5
5
refs/heads/try: 3d5418789064fdb463e872a4e651af1c628a3650
Original file line number Diff line number Diff line change @@ -259,13 +259,35 @@ impl <T: Ord> TreeSet<T> {
259
259
260
260
/// Check of the set is a subset of another
261
261
pure fn is_subset( & self , other: & TreeSet <T >) -> bool {
262
- // FIXME: this is a naive O(n*log(m)) implementation, could be O(n + m)
263
- !iter:: any( self , |x| !other. contains( x) )
262
+ other. is_superset( self )
264
263
}
265
264
266
265
/// Check of the set is a superset of another
267
266
pure fn is_superset( & self , other: & TreeSet <T >) -> bool {
268
- other. is_subset( self )
267
+ let mut x = self . iter( ) ;
268
+ let mut y = other. iter( ) ;
269
+ unsafe { // purity workaround
270
+ let mut a = x. next ( ) ;
271
+ let mut b = y. next ( ) ;
272
+ while b. is_some ( ) {
273
+ if a. is_none ( ) {
274
+ return false
275
+ }
276
+
277
+ let a1 = a. unwrap ( ) ;
278
+ let b1 = b. unwrap ( ) ;
279
+
280
+ if b1 < a1 {
281
+ return false
282
+ }
283
+
284
+ if !( a1 < b1) {
285
+ b = y. next ( ) ;
286
+ }
287
+ a = x. next ( ) ;
288
+ }
289
+ }
290
+ true
269
291
}
270
292
271
293
/// Visit the values (in-order) representing the difference
You can’t perform that action at this time.
0 commit comments