Skip to content

Commit 70cfaba

Browse files
thestingergraydon
authored andcommitted
---
yaml --- r: 41806 b: refs/heads/master c: 3fe6faa h: refs/heads/master v: v3
1 parent 684da86 commit 70cfaba

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 4f92d8fb52ba335abae39bdd38e72ff42cd37bb2
2+
refs/heads/master: 3fe6faace83c3f07c11b92f463ab93aad8f5dd41
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 2f46b763da2c098913884f101b6d71d69af41b49
55
refs/heads/try: 3d5418789064fdb463e872a4e651af1c628a3650

trunk/src/libstd/treemap.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,13 +259,35 @@ impl <T: Ord> TreeSet<T> {
259259

260260
/// Check of the set is a subset of another
261261
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)
264263
}
265264

266265
/// Check of the set is a superset of another
267266
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
269291
}
270292

271293
/// Visit the values (in-order) representing the difference

0 commit comments

Comments
 (0)