diff --git a/src/comp/middle/ast_map.rs b/src/comp/middle/ast_map.rs index aa71242f9c8..78f99f75f18 100644 --- a/src/comp/middle/ast_map.rs +++ b/src/comp/middle/ast_map.rs @@ -105,6 +105,11 @@ fn new_smallintmap_adapter[K, V](fn(&K) -> uint key_idx, idx += 1u; } } + iter keys() -> K { + for each (@tup(K, V) p in self.items()) { + put p._0; + } + } } auto map = smallintmap::mk[V](); diff --git a/src/lib/map.rs b/src/lib/map.rs index 75b4899b3e1..61572308427 100644 --- a/src/lib/map.rs +++ b/src/lib/map.rs @@ -1,6 +1,5 @@ /** - * At the moment, this is a partial hashmap implementation, not yet fit for - * use, but useful as a stress test for rustboot. + * Hashmap implementation. */ type hashfn[K] = fn(&K) -> uint ; @@ -16,7 +15,13 @@ type hashmap[K, V] = fn remove(&K) -> option::t[V] ; fn rehash() ; iter items() -> @tup(K, V) ; + iter keys() -> K ; }; +type hashset[K] = hashmap[K, ()]; + +fn set_add[K](hashset[K] set, &K key) -> bool { + ret set.insert(key, ()); +} fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] { 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] { } } } + iter keys() -> K { + for (bucket[K, V] b in bkts) { + alt (b) { + case (some(?k, _)) { put k; } + case (_) { } + } + } + } } auto bkts = make_buckets[K, V](initial_capacity); ret hashmap[K, V](hasher, eqer, bkts, initial_capacity, 0u, load_factor);