Skip to content

Commit 5e99ce6

Browse files
committed
---
yaml --- r: 27986 b: refs/heads/try c: 8185ede h: refs/heads/master v: v3
1 parent 198dc79 commit 5e99ce6

File tree

2 files changed

+70
-73
lines changed

2 files changed

+70
-73
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: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
5-
refs/heads/try: c8ce32e7f45a020eebcd7329fbe33e8b53f832a3
5+
refs/heads/try: 8185ede1fad8312244e418b3c082f87386c40145
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df

branches/try/src/libcore/send_map.rs

Lines changed: 69 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ mod linear {
5959
buckets: vec::from_fn(initial_capacity, |_i| none)})
6060
}
6161

62-
priv impl<K, V> &const LinearMap<K,V> {
62+
priv impl<K, V> LinearMap<K,V> {
6363
#[inline(always)]
64-
pure fn to_bucket(h: uint) -> uint {
64+
pure fn to_bucket(&const self,
65+
h: uint) -> uint {
6566
// FIXME(#3041) borrow a more sophisticated technique here from
6667
// Gecko, for example borrowing from Knuth, as Eich so
6768
// colorfully argues for here:
@@ -70,7 +71,9 @@ mod linear {
7071
}
7172

7273
#[inline(always)]
73-
pure fn next_bucket(idx: uint, len_buckets: uint) -> uint {
74+
pure fn next_bucket(&const self,
75+
idx: uint,
76+
len_buckets: uint) -> uint {
7477
let n = (idx + 1) % len_buckets;
7578
unsafe{ // argh. log not considered pure.
7679
debug!{"next_bucket(%?, %?) = %?", idx, len_buckets, n};
@@ -79,7 +82,9 @@ mod linear {
7982
}
8083

8184
#[inline(always)]
82-
pure fn bucket_sequence(hash: uint, op: fn(uint) -> bool) -> uint {
85+
pure fn bucket_sequence(&const self,
86+
hash: uint,
87+
op: fn(uint) -> bool) -> uint {
8388
let start_idx = self.to_bucket(hash);
8489
let len_buckets = self.buckets.len();
8590
let mut idx = start_idx;
@@ -95,20 +100,18 @@ mod linear {
95100
}
96101

97102
#[inline(always)]
98-
pure fn bucket_for_key(
99-
buckets: &[option<Bucket<K,V>>],
100-
k: &K) -> SearchResult {
101-
103+
pure fn bucket_for_key(&const self,
104+
buckets: &[option<Bucket<K,V>>],
105+
k: &K) -> SearchResult {
102106
let hash = self.hashfn(k);
103107
self.bucket_for_key_with_hash(buckets, hash, k)
104108
}
105109

106110
#[inline(always)]
107-
pure fn bucket_for_key_with_hash(
108-
buckets: &[option<Bucket<K,V>>],
109-
hash: uint,
110-
k: &K) -> SearchResult {
111-
111+
pure fn bucket_for_key_with_hash(&const self,
112+
buckets: &[option<Bucket<K,V>>],
113+
hash: uint,
114+
k: &K) -> SearchResult {
112115
let _ = for self.bucket_sequence(hash) |i| {
113116
match buckets[i] {
114117
some(bkt) => if bkt.hash == hash && self.eqfn(k, &bkt.key) {
@@ -119,12 +122,10 @@ mod linear {
119122
};
120123
return TableFull;
121124
}
122-
}
123125

124-
priv impl<K,V> &mut LinearMap<K,V> {
125126
/// Expands the capacity of the array and re-inserts each
126127
/// of the existing buckets.
127-
fn expand() {
128+
fn expand(&mut self) {
128129
let old_capacity = self.buckets.len();
129130
let new_capacity = old_capacity * 2;
130131
self.resize_at = ((new_capacity as float) * 3.0 / 4.0) as uint;
@@ -141,15 +142,15 @@ mod linear {
141142
}
142143
}
143144

144-
fn insert_bucket(+bucket: option<Bucket<K,V>>) {
145+
fn insert_bucket(&mut self, +bucket: option<Bucket<K,V>>) {
145146
let {hash, key, value} <- option::unwrap(bucket);
146147
let _ = self.insert_internal(hash, key, value);
147148
}
148149

149150
/// Inserts the key value pair into the buckets.
150151
/// Assumes that there will be a bucket.
151152
/// True if there was no previous entry with that key
152-
fn insert_internal(hash: uint, +k: K, +v: V) -> bool {
153+
fn insert_internal(&mut self, hash: uint, +k: K, +v: V) -> bool {
153154
match self.bucket_for_key_with_hash(self.buckets, hash, &k) {
154155
TableFull => {fail ~"Internal logic error";}
155156
FoundHole(idx) => {
@@ -167,10 +168,16 @@ mod linear {
167168
}
168169
}
169170
}
171+
172+
fn search(&self,
173+
hash: uint,
174+
op: fn(x: &option<Bucket<K,V>>) -> bool) {
175+
let _ = self.bucket_sequence(hash, |i| op(&self.buckets[i]));
176+
}
170177
}
171178

172-
impl<K,V> &mut LinearMap<K,V> {
173-
fn insert(+k: K, +v: V) -> bool {
179+
impl<K,V> LinearMap<K,V> {
180+
fn insert(&mut self, +k: K, +v: V) -> bool {
174181
if self.size >= self.resize_at {
175182
// n.b.: We could also do this after searching, so
176183
// that we do not resize if this call to insert is
@@ -185,7 +192,7 @@ mod linear {
185192
self.insert_internal(hash, k, v)
186193
}
187194

188-
fn remove(k: &K) -> bool {
195+
fn remove(&mut self, k: &K) -> bool {
189196
// Removing from an open-addressed hashtable
190197
// is, well, painful. The problem is that
191198
// the entry may lie on the probe path for other
@@ -223,69 +230,33 @@ mod linear {
223230
return true;
224231
}
225232

226-
fn clear() {
233+
fn clear(&mut self) {
227234
for uint::range(0, self.buckets.len()) |idx| {
228235
self.buckets[idx] = none;
229236
}
230237
self.size = 0;
231238
}
232-
}
233-
234-
priv impl<K,V> &LinearMap<K,V> {
235-
fn search(hash: uint, op: fn(x: &option<Bucket<K,V>>) -> bool) {
236-
let _ = self.bucket_sequence(hash, |i| op(&self.buckets[i]));
237-
}
238-
}
239239

240-
impl<K,V> &const LinearMap<K,V> {
241-
pure fn len() -> uint {
240+
pure fn len(&const self) -> uint {
242241
self.size
243242
}
244243

245-
pure fn is_empty() -> bool {
244+
pure fn is_empty(&const self) -> bool {
246245
self.len() == 0
247246
}
248247

249-
fn contains_key(k: &K) -> bool {
248+
fn contains_key(&const self,
249+
k: &K) -> bool {
250250
match self.bucket_for_key(self.buckets, k) {
251251
FoundEntry(_) => {true}
252252
TableFull | FoundHole(_) => {false}
253253
}
254254
}
255-
}
256-
257-
impl<K,V: copy> &const LinearMap<K,V> {
258-
fn find(k: &K) -> option<V> {
259-
match self.bucket_for_key(self.buckets, k) {
260-
FoundEntry(idx) => {
261-
match self.buckets[idx] {
262-
some(bkt) => {some(copy bkt.value)}
263-
// FIXME (#3148): Will be able to get rid of this when we
264-
// redefine SearchResult
265-
none => fail ~"LinearMap::find: internal logic error"
266-
}
267-
}
268-
TableFull | FoundHole(_) => {
269-
none
270-
}
271-
}
272-
}
273255

274-
fn get(k: &K) -> V {
275-
let value = self.find(k);
276-
if value.is_none() {
277-
fail fmt!{"No entry found for key: %?", k};
278-
}
279-
option::unwrap(value)
280-
}
281-
282-
}
283-
284-
impl<K,V> &LinearMap<K,V> {
285256
/*
286257
FIXME(#3148)--region inference fails to capture needed deps
287258
288-
fn find_ref(k: &K) -> option<&self/V> {
259+
fn find_ref(&self, k: &K) -> option<&self/V> {
289260
match self.bucket_for_key(self.buckets, k) {
290261
FoundEntry(idx) => {
291262
match check self.buckets[idx] {
@@ -299,7 +270,7 @@ mod linear {
299270
}
300271
*/
301272

302-
fn each_ref(blk: fn(k: &K, v: &V) -> bool) {
273+
fn each_ref(&self, blk: fn(k: &K, v: &V) -> bool) {
303274
for vec::each(self.buckets) |slot| {
304275
let mut broke = false;
305276
do slot.iter |bucket| {
@@ -310,26 +281,52 @@ mod linear {
310281
if broke { break; }
311282
}
312283
}
313-
fn each_key_ref(blk: fn(k: &K) -> bool) {
284+
285+
fn each_key_ref(&self, blk: fn(k: &K) -> bool) {
314286
self.each_ref(|k, _v| blk(k))
315287
}
316-
fn each_value_ref(blk: fn(v: &V) -> bool) {
288+
289+
fn each_value_ref(&self, blk: fn(v: &V) -> bool) {
317290
self.each_ref(|_k, v| blk(v))
318291
}
319292
}
320293

321-
impl<K: copy, V: copy> &LinearMap<K,V> {
322-
fn each(blk: fn(+K,+V) -> bool) {
294+
impl<K,V: copy> LinearMap<K,V> {
295+
fn find(&const self, k: &K) -> option<V> {
296+
match self.bucket_for_key(self.buckets, k) {
297+
FoundEntry(idx) => {
298+
match check self.buckets[idx] {
299+
some(bkt) => {some(copy bkt.value)}
300+
}
301+
}
302+
TableFull | FoundHole(_) => {
303+
none
304+
}
305+
}
306+
}
307+
308+
fn get(&const self, k: &K) -> V {
309+
let value = self.find(k);
310+
if value.is_none() {
311+
fail fmt!{"No entry found for key: %?", k};
312+
}
313+
option::unwrap(value)
314+
}
315+
316+
}
317+
318+
impl<K: copy, V: copy> LinearMap<K,V> {
319+
fn each(&self, blk: fn(+K,+V) -> bool) {
323320
self.each_ref(|k,v| blk(copy *k, copy *v));
324321
}
325322
}
326-
impl<K: copy, V> &LinearMap<K,V> {
327-
fn each_key(blk: fn(+K) -> bool) {
323+
impl<K: copy, V> LinearMap<K,V> {
324+
fn each_key(&self, blk: fn(+K) -> bool) {
328325
self.each_key_ref(|k| blk(copy *k));
329326
}
330327
}
331-
impl<K, V: copy> &LinearMap<K,V> {
332-
fn each_value(blk: fn(+V) -> bool) {
328+
impl<K, V: copy> LinearMap<K,V> {
329+
fn each_value(&self, blk: fn(+V) -> bool) {
333330
self.each_value_ref(|v| blk(copy *v));
334331
}
335332
}

0 commit comments

Comments
 (0)