diff options
| author | Jesse Jones <jesse9jones@gmail.com> | 2012-11-17 08:41:47 -0800 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-11-18 13:25:24 -0800 |
| commit | 68c852ad3aa4b27b5295a8e7da288798afeea2c4 (patch) | |
| tree | d2d31be01e1d11a2d77d104d60693814ced75fa4 /src | |
| parent | 1a1e99c27d0d701f315926f400aa325ddfc8a9e7 (diff) | |
Made Map.contains_key, contains_key_ref, and get pure.
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcore/mutable.rs | 2 | ||||
| -rw-r--r-- | src/libstd/map.rs | 18 | ||||
| -rw-r--r-- | src/libstd/smallintmap.rs | 8 | ||||
| -rw-r--r-- | src/test/run-pass/class-impl-very-parameterized-trait.rs | 6 |
4 files changed, 17 insertions, 17 deletions
diff --git a/src/libcore/mutable.rs b/src/libcore/mutable.rs index 56a6df2c4dd..eafdf58e67e 100644 --- a/src/libcore/mutable.rs +++ b/src/libcore/mutable.rs @@ -48,7 +48,7 @@ impl<T> Data<T> { } } - fn borrow_const<R>(op: &fn(t: &const T) -> R) -> R { + pure fn borrow_const<R>(op: &fn(t: &const T) -> R) -> R { op(&const self.value) } diff --git a/src/libstd/map.rs b/src/libstd/map.rs index 0ee7cb6fcf9..915202143a1 100644 --- a/src/libstd/map.rs +++ b/src/libstd/map.rs @@ -30,17 +30,17 @@ pub trait Map<K:Eq IterBytes Hash Copy, V: Copy> { fn insert(v: K, v: V) -> bool; /// Returns true if the map contains a value for the specified key - fn contains_key(key: K) -> bool; + pure fn contains_key(key: K) -> bool; /// Returns true if the map contains a value for the specified /// key, taking the key by reference. - fn contains_key_ref(key: &K) -> bool; + pure fn contains_key_ref(key: &K) -> bool; /** * Get the value for the specified key. Fails if the key does not exist in * the map. */ - fn get(key: K) -> V; + pure fn get(key: K) -> V; /** * Get the value for the specified key. If the key does not exist in @@ -200,11 +200,11 @@ pub mod chained { impl<K:Eq IterBytes Hash Copy, V: Copy> T<K, V>: Map<K, V> { pure fn size() -> uint { self.count } - fn contains_key(k: K) -> bool { + pure fn contains_key(k: K) -> bool { self.contains_key_ref(&k) } - fn contains_key_ref(k: &K) -> bool { + pure fn contains_key_ref(k: &K) -> bool { let hash = k.hash_keyed(0,0) as uint; match self.search_tbl(k, hash) { NotFound => false, @@ -264,7 +264,7 @@ pub mod chained { } } - fn get(k: K) -> V { + pure fn get(k: K) -> V { let opt_v = self.find(k); if opt_v.is_none() { fail fmt!("Key not found in table: %?", k); @@ -421,19 +421,19 @@ impl<K: Eq IterBytes Hash Copy, V: Copy> @Mut<LinearMap<K, V>>: } } - fn contains_key(key: K) -> bool { + pure fn contains_key(key: K) -> bool { do self.borrow_const |p| { p.contains_key(&key) } } - fn contains_key_ref(key: &K) -> bool { + pure fn contains_key_ref(key: &K) -> bool { do self.borrow_const |p| { p.contains_key(key) } } - fn get(key: K) -> V { + pure fn get(key: K) -> V { do self.borrow_const |p| { p.get(&key) } diff --git a/src/libstd/smallintmap.rs b/src/libstd/smallintmap.rs index 1582d90ce2d..9dc216a2155 100644 --- a/src/libstd/smallintmap.rs +++ b/src/libstd/smallintmap.rs @@ -60,7 +60,7 @@ pub pure fn get<T: Copy>(self: SmallIntMap<T>, key: uint) -> T { } /// Returns true if the map contains a value for the specified key -pub fn contains_key<T: Copy>(self: SmallIntMap<T>, key: uint) -> bool { +pub pure fn contains_key<T: Copy>(self: SmallIntMap<T>, key: uint) -> bool { return !find(self, key).is_none(); } @@ -93,13 +93,13 @@ impl<V: Copy> SmallIntMap<V>: map::Map<uint, V> { fn clear() { self.v.set(~[]); } - fn contains_key(key: uint) -> bool { + pure fn contains_key(key: uint) -> bool { contains_key(self, key) } - fn contains_key_ref(key: &uint) -> bool { + pure fn contains_key_ref(key: &uint) -> bool { contains_key(self, *key) } - fn get(key: uint) -> V { get(self, key) } + pure fn get(key: uint) -> V { get(self, key) } pure fn find(key: uint) -> Option<V> { find(self, key) } fn rehash() { fail } diff --git a/src/test/run-pass/class-impl-very-parameterized-trait.rs b/src/test/run-pass/class-impl-very-parameterized-trait.rs index 8c25d94db3b..4cfcbf67cc9 100644 --- a/src/test/run-pass/class-impl-very-parameterized-trait.rs +++ b/src/test/run-pass/class-impl-very-parameterized-trait.rs @@ -47,10 +47,10 @@ impl<T: Copy> cat<T> : Map<int, T> { self.meows += k; true } - fn contains_key(+k: int) -> bool { k <= self.meows } - fn contains_key_ref(k: &int) -> bool { self.contains_key(*k) } + pure fn contains_key(+k: int) -> bool { k <= self.meows } + pure fn contains_key_ref(k: &int) -> bool { self.contains_key(*k) } - fn get(+k:int) -> T { match self.find(k) { + pure fn get(+k:int) -> T { match self.find(k) { Some(v) => { v } None => { fail ~"epic fail"; } } |
