Skip to content

Commit 68c852a

Browse files
jesse99brson
authored andcommitted
Made Map.contains_key, contains_key_ref, and get pure.
1 parent 1a1e99c commit 68c852a

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

src/libcore/mutable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl<T> Data<T> {
4848
}
4949
}
5050

51-
fn borrow_const<R>(op: &fn(t: &const T) -> R) -> R {
51+
pure fn borrow_const<R>(op: &fn(t: &const T) -> R) -> R {
5252
op(&const self.value)
5353
}
5454

src/libstd/map.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ pub trait Map<K:Eq IterBytes Hash Copy, V: Copy> {
3030
fn insert(v: K, v: V) -> bool;
3131

3232
/// Returns true if the map contains a value for the specified key
33-
fn contains_key(key: K) -> bool;
33+
pure fn contains_key(key: K) -> bool;
3434

3535
/// Returns true if the map contains a value for the specified
3636
/// key, taking the key by reference.
37-
fn contains_key_ref(key: &K) -> bool;
37+
pure fn contains_key_ref(key: &K) -> bool;
3838

3939
/**
4040
* Get the value for the specified key. Fails if the key does not exist in
4141
* the map.
4242
*/
43-
fn get(key: K) -> V;
43+
pure fn get(key: K) -> V;
4444

4545
/**
4646
* Get the value for the specified key. If the key does not exist in
@@ -200,11 +200,11 @@ pub mod chained {
200200
impl<K:Eq IterBytes Hash Copy, V: Copy> T<K, V>: Map<K, V> {
201201
pure fn size() -> uint { self.count }
202202

203-
fn contains_key(k: K) -> bool {
203+
pure fn contains_key(k: K) -> bool {
204204
self.contains_key_ref(&k)
205205
}
206206

207-
fn contains_key_ref(k: &K) -> bool {
207+
pure fn contains_key_ref(k: &K) -> bool {
208208
let hash = k.hash_keyed(0,0) as uint;
209209
match self.search_tbl(k, hash) {
210210
NotFound => false,
@@ -264,7 +264,7 @@ pub mod chained {
264264
}
265265
}
266266

267-
fn get(k: K) -> V {
267+
pure fn get(k: K) -> V {
268268
let opt_v = self.find(k);
269269
if opt_v.is_none() {
270270
fail fmt!("Key not found in table: %?", k);
@@ -421,19 +421,19 @@ impl<K: Eq IterBytes Hash Copy, V: Copy> @Mut<LinearMap<K, V>>:
421421
}
422422
}
423423

424-
fn contains_key(key: K) -> bool {
424+
pure fn contains_key(key: K) -> bool {
425425
do self.borrow_const |p| {
426426
p.contains_key(&key)
427427
}
428428
}
429429

430-
fn contains_key_ref(key: &K) -> bool {
430+
pure fn contains_key_ref(key: &K) -> bool {
431431
do self.borrow_const |p| {
432432
p.contains_key(key)
433433
}
434434
}
435435

436-
fn get(key: K) -> V {
436+
pure fn get(key: K) -> V {
437437
do self.borrow_const |p| {
438438
p.get(&key)
439439
}

src/libstd/smallintmap.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub pure fn get<T: Copy>(self: SmallIntMap<T>, key: uint) -> T {
6060
}
6161

6262
/// Returns true if the map contains a value for the specified key
63-
pub fn contains_key<T: Copy>(self: SmallIntMap<T>, key: uint) -> bool {
63+
pub pure fn contains_key<T: Copy>(self: SmallIntMap<T>, key: uint) -> bool {
6464
return !find(self, key).is_none();
6565
}
6666

@@ -93,13 +93,13 @@ impl<V: Copy> SmallIntMap<V>: map::Map<uint, V> {
9393
fn clear() {
9494
self.v.set(~[]);
9595
}
96-
fn contains_key(key: uint) -> bool {
96+
pure fn contains_key(key: uint) -> bool {
9797
contains_key(self, key)
9898
}
99-
fn contains_key_ref(key: &uint) -> bool {
99+
pure fn contains_key_ref(key: &uint) -> bool {
100100
contains_key(self, *key)
101101
}
102-
fn get(key: uint) -> V { get(self, key) }
102+
pure fn get(key: uint) -> V { get(self, key) }
103103
pure fn find(key: uint) -> Option<V> { find(self, key) }
104104
fn rehash() { fail }
105105

src/test/run-pass/class-impl-very-parameterized-trait.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ impl<T: Copy> cat<T> : Map<int, T> {
4747
self.meows += k;
4848
true
4949
}
50-
fn contains_key(+k: int) -> bool { k <= self.meows }
51-
fn contains_key_ref(k: &int) -> bool { self.contains_key(*k) }
50+
pure fn contains_key(+k: int) -> bool { k <= self.meows }
51+
pure fn contains_key_ref(k: &int) -> bool { self.contains_key(*k) }
5252

53-
fn get(+k:int) -> T { match self.find(k) {
53+
pure fn get(+k:int) -> T { match self.find(k) {
5454
Some(v) => { v }
5555
None => { fail ~"epic fail"; }
5656
}

0 commit comments

Comments
 (0)