Skip to content

Commit 9a95972

Browse files
committed
---
yaml --- r: 32217 b: refs/heads/dist-snap c: e9b7ce6 h: refs/heads/master i: 32215: 83b9998 v: v3
1 parent 8f2172d commit 9a95972

File tree

2 files changed

+48
-20
lines changed

2 files changed

+48
-20
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
10-
refs/heads/dist-snap: 0031617f30f159df2cef301c9d574cd219e16b16
10+
refs/heads/dist-snap: e9b7ce6f57e8ca74dfdb16ba91fcae38d2c44798
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/dist-snap/src/libcore/send_map.rs

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,38 @@ Sendable hash maps. Very much a work in progress.
1313
type HashFn<K> = pure fn~(K) -> uint;
1414
type EqFn<K> = pure fn~(K, K) -> bool;
1515

16+
trait send_map<K, V: copy> {
17+
// FIXME(#3148) ^^^^ once find_ref() works, we can drop V:copy
18+
19+
fn insert(&mut self, +k: K, +v: V) -> bool;
20+
fn remove(&mut self, k: &K) -> bool;
21+
fn clear(&mut self);
22+
pure fn len(&const self) -> uint;
23+
pure fn is_empty(&const self) -> bool;
24+
fn contains_key(&const self, k: &K) -> bool;
25+
fn each_ref(&self, blk: fn(k: &K, v: &V) -> bool);
26+
fn each_key_ref(&self, blk: fn(k: &K) -> bool);
27+
fn each_value_ref(&self, blk: fn(v: &V) -> bool);
28+
fn find(&const self, k: &K) -> Option<V>;
29+
fn get(&const self, k: &K) -> V;
30+
}
31+
1632
/// Open addressing with linear probing.
1733
mod linear {
1834
export LinearMap, linear_map, linear_map_with_capacity, public_methods;
1935

2036
const initial_capacity: uint = 32u; // 2^5
21-
type Bucket<K,V> = {hash: uint, key: K, value: V};
22-
enum LinearMap<K,V> {
23-
LinearMap_({
24-
hashfn: pure fn~(x: &K) -> uint,
25-
eqfn: pure fn~(x: &K, y: &K) -> bool,
26-
resize_at: uint,
27-
size: uint,
28-
buckets: ~[Option<Bucket<K,V>>]})
37+
struct Bucket<K,V> {
38+
hash: uint;
39+
key: K;
40+
value: V;
41+
}
42+
struct LinearMap<K,V> {
43+
hashfn: pure fn~(x: &K) -> uint;
44+
eqfn: pure fn~(x: &K, y: &K) -> bool;
45+
resize_at: uint;
46+
size: uint;
47+
buckets: ~[Option<Bucket<K,V>>];
2948
}
3049

3150
// FIXME(#3148) -- we could rewrite found_entry
@@ -51,12 +70,13 @@ mod linear {
5170
+eqfn: pure fn~(x: &K, y: &K) -> bool,
5271
initial_capacity: uint) -> LinearMap<K,V> {
5372

54-
LinearMap_({
73+
LinearMap {
5574
hashfn: hashfn,
5675
eqfn: eqfn,
5776
resize_at: resize_at(initial_capacity),
5877
size: 0,
59-
buckets: vec::from_fn(initial_capacity, |_i| None)})
78+
buckets: vec::from_fn(initial_capacity, |_i| None)
79+
}
6080
}
6181

6282
priv impl<K, V> LinearMap<K,V> {
@@ -136,15 +156,19 @@ mod linear {
136156
for uint::range(0, old_capacity) |i| {
137157
let mut bucket = None;
138158
bucket <-> old_buckets[i];
139-
if bucket.is_some() {
140-
self.insert_bucket(bucket);
141-
}
159+
self.insert_opt_bucket(bucket);
142160
}
143161
}
144162

145-
fn insert_bucket(&mut self, +bucket: Option<Bucket<K,V>>) {
146-
let {hash, key, value} <- option::unwrap(bucket);
147-
let _ = self.insert_internal(hash, key, value);
163+
fn insert_opt_bucket(&mut self, +bucket: Option<Bucket<K,V>>) {
164+
match move bucket {
165+
Some(Bucket {hash: move hash,
166+
key: move key,
167+
value: move value}) => {
168+
self.insert_internal(hash, key, value);
169+
}
170+
None => {}
171+
}
148172
}
149173

150174
/// Inserts the key value pair into the buckets.
@@ -156,14 +180,18 @@ mod linear {
156180
FoundHole(idx) => {
157181
debug!("insert fresh (%?->%?) at idx %?, hash %?",
158182
k, v, idx, hash);
159-
self.buckets[idx] = Some({hash: hash, key: k, value: v});
183+
self.buckets[idx] = Some(Bucket {hash: hash,
184+
key: k,
185+
value: v});
160186
self.size += 1;
161187
return true;
162188
}
163189
FoundEntry(idx) => {
164190
debug!("insert overwrite (%?->%?) at idx %?, hash %?",
165191
k, v, idx, hash);
166-
self.buckets[idx] = Some({hash: hash, key: k, value: v});
192+
self.buckets[idx] = Some(Bucket {hash: hash,
193+
key: k,
194+
value: v});
167195
return false;
168196
}
169197
}
@@ -223,7 +251,7 @@ mod linear {
223251
while self.buckets[idx].is_some() {
224252
let mut bucket = None;
225253
bucket <-> self.buckets[idx];
226-
self.insert_bucket(bucket);
254+
self.insert_opt_bucket(bucket);
227255
idx = self.next_bucket(idx, len_buckets);
228256
}
229257
self.size -= 1;

0 commit comments

Comments
 (0)