From a32c5c73ee6aad9cb4b2e06867eafa09bc1ece3a Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Fri, 8 Feb 2013 17:08:02 -0500 Subject: oldmap: get rid of legacy _ref suffixes --- src/libstd/oldmap.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/oldmap.rs b/src/libstd/oldmap.rs index ad7e8e50e38..fb594af4942 100644 --- a/src/libstd/oldmap.rs +++ b/src/libstd/oldmap.rs @@ -173,7 +173,7 @@ pub mod chained { } impl T { - pure fn contains_key_ref(&self, k: &K) -> bool { + pure fn contains_key(&self, k: &K) -> bool { let hash = k.hash_keyed(0,0) as uint; match self.search_tbl(k, hash) { NotFound => false, @@ -314,18 +314,18 @@ pub mod chained { } } - pure fn each_ref(&self, blk: fn(key: &K, value: &V) -> bool) { + pure fn each(&self, blk: fn(key: &K, value: &V) -> bool) { for self.each_entry |entry| { if !blk(&entry.key, &entry.value) { break; } } } - pure fn each_key_ref(&self, blk: fn(key: &K) -> bool) { - self.each_ref(|k, _v| blk(k)) + pure fn each_key(&self, blk: fn(key: &K) -> bool) { + self.each(|k, _v| blk(k)) } - pure fn each_value_ref(&self, blk: fn(value: &V) -> bool) { - self.each_ref(|_k, v| blk(v)) + pure fn each_value(&self, blk: fn(value: &V) -> bool) { + self.each(|_k, v| blk(v)) } } @@ -397,7 +397,7 @@ pub fn set_add(set: Set, key: K) -> bool { /// Convert a set into a vector. pub pure fn vec_from_set(s: Set) -> ~[T] { do vec::build_sized(s.len()) |push| { - for s.each_key_ref() |&k| { + for s.each_key() |&k| { push(k); } } @@ -628,9 +628,9 @@ mod tests { fn test_contains_key() { let key = ~"k"; let map = HashMap::<~str, ~str>(); - assert (!map.contains_key_ref(&key)); + assert (!map.contains_key(&key)); map.insert(key, ~"val"); - assert (map.contains_key_ref(&key)); + assert (map.contains_key(&key)); } #[test] @@ -648,10 +648,10 @@ mod tests { let mut map = HashMap::<~str, ~str>(); map.insert(key, ~"val"); assert (map.len() == 1); - assert (map.contains_key_ref(&key)); + assert (map.contains_key(&key)); map.clear(); assert (map.len() == 0); - assert (!map.contains_key_ref(&key)); + assert (!map.contains_key(&key)); } #[test] -- cgit 1.4.1-3-g733a5 From 0127828b5bc5363e30f6f672e0465b7fa79c9907 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Fri, 8 Feb 2013 19:20:36 -0500 Subject: oldmap: separate out the methods that need Copy --- src/libstd/oldmap.rs | 66 +++++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 32 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/oldmap.rs b/src/libstd/oldmap.rs index fb594af4942..62ca25ed69d 100644 --- a/src/libstd/oldmap.rs +++ b/src/libstd/oldmap.rs @@ -76,7 +76,7 @@ pub mod chained { FoundAfter(@Entry, @Entry) } - priv impl T { + priv impl T { pure fn search_rem(k: &K, h: uint, idx: uint, e_root: @Entry) -> SearchResult { let mut e0 = e_root; @@ -172,7 +172,7 @@ pub mod chained { } } - impl T { + impl T { pure fn contains_key(&self, k: &K) -> bool { let hash = k.hash_keyed(0,0) as uint; match self.search_tbl(k, hash) { @@ -225,6 +225,38 @@ pub mod chained { } } + fn remove(k: &K) -> bool { + match self.search_tbl(k, k.hash_keyed(0,0) as uint) { + NotFound => false, + FoundFirst(idx, entry) => { + self.count -= 1u; + self.chains[idx] = entry.next; + true + } + FoundAfter(eprev, entry) => { + self.count -= 1u; + eprev.next = entry.next; + true + } + } + } + + pure fn each(&self, blk: fn(key: &K, value: &V) -> bool) { + for self.each_entry |entry| { + if !blk(&entry.key, &entry.value) { break; } + } + } + + pure fn each_key(&self, blk: fn(key: &K) -> bool) { + self.each(|k, _v| blk(k)) + } + + pure fn each_value(&self, blk: fn(value: &V) -> bool) { + self.each(|_k, v| blk(v)) + } + } + + impl T { pure fn find(&self, k: &K) -> Option { unsafe { match self.search_tbl(k, k.hash_keyed(0,0) as uint) { @@ -297,36 +329,6 @@ pub mod chained { } option::unwrap(move opt_v) } - - fn remove(k: &K) -> bool { - match self.search_tbl(k, k.hash_keyed(0,0) as uint) { - NotFound => false, - FoundFirst(idx, entry) => { - self.count -= 1u; - self.chains[idx] = entry.next; - true - } - FoundAfter(eprev, entry) => { - self.count -= 1u; - eprev.next = entry.next; - true - } - } - } - - pure fn each(&self, blk: fn(key: &K, value: &V) -> bool) { - for self.each_entry |entry| { - if !blk(&entry.key, &entry.value) { break; } - } - } - - pure fn each_key(&self, blk: fn(key: &K) -> bool) { - self.each(|k, _v| blk(k)) - } - - pure fn each_value(&self, blk: fn(value: &V) -> bool) { - self.each(|_k, v| blk(v)) - } } impl T { -- cgit 1.4.1-3-g733a5 From 94fd95a4f1ed5a55e559bcfacc65aaa637a71cb7 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Fri, 8 Feb 2013 19:28:37 -0500 Subject: oldmap: rm unneeded unsafe --- src/libstd/oldmap.rs | 44 ++++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 26 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/oldmap.rs b/src/libstd/oldmap.rs index 62ca25ed69d..cea6d17e35d 100644 --- a/src/libstd/oldmap.rs +++ b/src/libstd/oldmap.rs @@ -90,15 +90,13 @@ pub mod chained { } Some(e1) => { comp += 1u; - unsafe { - if e1.hash == h && e1.key == *k { - debug!("search_tbl: present, comp %u, \ - hash %u, idx %u", - comp, h, idx); - return FoundAfter(e0, e1); - } else { - e0 = e1; - } + if e1.hash == h && e1.key == *k { + debug!( + "search_tbl: present, comp %u, hash %u, idx %u", + comp, h, idx); + return FoundAfter(e0, e1); + } else { + e0 = e1; } } } @@ -114,14 +112,12 @@ pub mod chained { return NotFound; } Some(e) => { - unsafe { - if e.hash == h && e.key == *k { - debug!("search_tbl: present, comp %u, hash %u, \ - idx %u", 1u, h, idx); - return FoundFirst(idx, e); - } else { - return self.search_rem(k, h, idx, e); - } + if e.hash == h && e.key == *k { + debug!("search_tbl: present, comp %u, hash %u, \ + idx %u", 1u, h, idx); + return FoundFirst(idx, e); + } else { + return self.search_rem(k, h, idx, e); } } } @@ -258,12 +254,10 @@ pub mod chained { impl T { pure fn find(&self, k: &K) -> Option { - unsafe { - match self.search_tbl(k, k.hash_keyed(0,0) as uint) { - NotFound => None, - FoundFirst(_, entry) => Some(entry.value), - FoundAfter(_, entry) => Some(entry.value) - } + match self.search_tbl(k, k.hash_keyed(0,0) as uint) { + NotFound => None, + FoundFirst(_, entry) => Some(entry.value), + FoundAfter(_, entry) => Some(entry.value) } } @@ -364,9 +358,7 @@ pub mod chained { impl T: ops::Index { pure fn index(&self, k: K) -> V { - unsafe { - self.get(&k) - } + self.get(&k) } } -- cgit 1.4.1-3-g733a5