From 0127828b5bc5363e30f6f672e0465b7fa79c9907 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Fri, 8 Feb 2013 19:20:36 -0500 Subject: [PATCH] oldmap: separate out the methods that need Copy --- src/libstd/oldmap.rs | 66 +++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/src/libstd/oldmap.rs b/src/libstd/oldmap.rs index fb594af49429..62ca25ed69d0 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 {