Skip to content

Commit 1dc0ec9

Browse files
thestingergraydon
authored andcommitted
---
yaml --- r: 42455 b: refs/heads/try c: 1e5c553 h: refs/heads/master i: 42453: b81c75b 42451: 8b23fd4 42447: 1ac1260 v: v3
1 parent a95145c commit 1dc0ec9

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 19dfec2aaf746535de1521f68421f9980dbf25de
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 2f46b763da2c098913884f101b6d71d69af41b49
5-
refs/heads/try: 9cc9a7582c11201c76745f4d190aaa21f4073e32
5+
refs/heads/try: 1e5c553b7c98185adecf3564e618e70fcd136ce6
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278

branches/try/src/libstd/treemap.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,26 @@ pub struct TreeMap<K: Ord, V> {
3939
priv length: uint
4040
}
4141

42-
// FIXME: this is a naive O(n*log(m)) implementation, could be O(n)
43-
impl <K: Ord, V: Eq> TreeMap<K, V>: Eq {
42+
impl <K: Eq Ord, V: Eq> TreeMap<K, V>: Eq {
4443
pure fn eq(&self, other: &TreeMap<K, V>) -> bool {
4544
if self.len() != other.len() {
4645
return false
4746
}
48-
for self.each |x, y| {
49-
match other.find(x) {
50-
Some(z) => if z != y { return false },
51-
None => return false
47+
unsafe { // purity workaround
48+
let mut x = self.iter();
49+
let mut y = other.iter();
50+
for self.len().times {
51+
// ICE: x.next() != y.next()
52+
53+
let (x1, x2) = x.next().unwrap();
54+
let (y1, y2) = y.next().unwrap();
55+
56+
if x1 != y1 || x2 != y2 {
57+
return false
58+
}
5259
}
60+
true
5361
}
54-
true
5562
}
5663
pure fn ne(&self, other: &TreeMap<K, V>) -> bool {
5764
!self.eq(other)
@@ -137,8 +144,8 @@ impl <K: Ord, V> TreeMap<K, V> {
137144
ret
138145
}
139146

140-
/// Get a lazy iterator over the nodes in the map. Requires that it
141-
/// be frozen (immutable).
147+
/// Get a lazy iterator over the key-value pairs in the map.
148+
/// Requires that it be frozen (immutable).
142149
fn iter(&self) -> TreeMapIterator/&self<K, V> {
143150
TreeMapIterator{stack: ~[], node: &self.root}
144151
}
@@ -183,7 +190,7 @@ impl <T: Ord> TreeSet<T>: iter::BaseIter<T> {
183190
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
184191
}
185192

186-
impl <T: Ord> TreeSet<T>: Eq {
193+
impl <T: Eq Ord> TreeSet<T>: Eq {
187194
pure fn eq(&self, other: &TreeSet<T>) -> bool { self.map == other.map }
188195
pure fn ne(&self, other: &TreeSet<T>) -> bool { self.map != other.map }
189196
}

0 commit comments

Comments
 (0)