Skip to content

Commit 0474a12

Browse files
committed
---
yaml --- r: 4059 b: refs/heads/master c: 4b59ae0 h: refs/heads/master i: 4057: 04310e2 4055: 9ebe43f v: v3
1 parent c73a418 commit 0474a12

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: cb024253765c9537d1fa1f789caa4d3f9afe03e8
2+
refs/heads/master: 4b59ae0aa9051e6a5fbec43d0c9bb8a12c0711e0

trunk/src/comp/middle/ast_map.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ fn new_smallintmap_adapter[K, V](fn(&K) -> uint key_idx,
105105
idx += 1u;
106106
}
107107
}
108+
iter keys() -> K {
109+
for each (@tup(K, V) p in self.items()) {
110+
put p._0;
111+
}
112+
}
108113
}
109114

110115
auto map = smallintmap::mk[V]();

trunk/src/lib/map.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/**
2-
* At the moment, this is a partial hashmap implementation, not yet fit for
3-
* use, but useful as a stress test for rustboot.
2+
* Hashmap implementation.
43
*/
54
type hashfn[K] = fn(&K) -> uint ;
65

@@ -16,7 +15,13 @@ type hashmap[K, V] =
1615
fn remove(&K) -> option::t[V] ;
1716
fn rehash() ;
1817
iter items() -> @tup(K, V) ;
18+
iter keys() -> K ;
1919
};
20+
type hashset[K] = hashmap[K, ()];
21+
22+
fn set_add[K](hashset[K] set, &K key) -> bool {
23+
ret set.insert(key, ());
24+
}
2025

2126
fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
2227
let uint initial_capacity = 32u; // 2^5
@@ -188,6 +193,14 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
188193
}
189194
}
190195
}
196+
iter keys() -> K {
197+
for (bucket[K, V] b in bkts) {
198+
alt (b) {
199+
case (some(?k, _)) { put k; }
200+
case (_) { }
201+
}
202+
}
203+
}
191204
}
192205
auto bkts = make_buckets[K, V](initial_capacity);
193206
ret hashmap[K, V](hasher, eqer, bkts, initial_capacity, 0u, load_factor);

0 commit comments

Comments
 (0)