Skip to content

Commit 0127828

Browse files
committed
oldmap: separate out the methods that need Copy
1 parent a32c5c7 commit 0127828

File tree

1 file changed

+34
-32
lines changed

1 file changed

+34
-32
lines changed

src/libstd/oldmap.rs

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub mod chained {
7676
FoundAfter(@Entry<K,V>, @Entry<K,V>)
7777
}
7878

79-
priv impl<K:Eq IterBytes Hash, V: Copy> T<K, V> {
79+
priv impl<K:Eq IterBytes Hash, V> T<K, V> {
8080
pure fn search_rem(k: &K, h: uint, idx: uint,
8181
e_root: @Entry<K,V>) -> SearchResult<K,V> {
8282
let mut e0 = e_root;
@@ -172,7 +172,7 @@ pub mod chained {
172172
}
173173
}
174174

175-
impl<K:Eq IterBytes Hash Copy, V: Copy> T<K, V> {
175+
impl<K: Eq IterBytes Hash, V> T<K, V> {
176176
pure fn contains_key(&self, k: &K) -> bool {
177177
let hash = k.hash_keyed(0,0) as uint;
178178
match self.search_tbl(k, hash) {
@@ -225,6 +225,38 @@ pub mod chained {
225225
}
226226
}
227227

228+
fn remove(k: &K) -> bool {
229+
match self.search_tbl(k, k.hash_keyed(0,0) as uint) {
230+
NotFound => false,
231+
FoundFirst(idx, entry) => {
232+
self.count -= 1u;
233+
self.chains[idx] = entry.next;
234+
true
235+
}
236+
FoundAfter(eprev, entry) => {
237+
self.count -= 1u;
238+
eprev.next = entry.next;
239+
true
240+
}
241+
}
242+
}
243+
244+
pure fn each(&self, blk: fn(key: &K, value: &V) -> bool) {
245+
for self.each_entry |entry| {
246+
if !blk(&entry.key, &entry.value) { break; }
247+
}
248+
}
249+
250+
pure fn each_key(&self, blk: fn(key: &K) -> bool) {
251+
self.each(|k, _v| blk(k))
252+
}
253+
254+
pure fn each_value(&self, blk: fn(value: &V) -> bool) {
255+
self.each(|_k, v| blk(v))
256+
}
257+
}
258+
259+
impl<K: Eq IterBytes Hash Copy, V: Copy> T<K, V> {
228260
pure fn find(&self, k: &K) -> Option<V> {
229261
unsafe {
230262
match self.search_tbl(k, k.hash_keyed(0,0) as uint) {
@@ -297,36 +329,6 @@ pub mod chained {
297329
}
298330
option::unwrap(move opt_v)
299331
}
300-
301-
fn remove(k: &K) -> bool {
302-
match self.search_tbl(k, k.hash_keyed(0,0) as uint) {
303-
NotFound => false,
304-
FoundFirst(idx, entry) => {
305-
self.count -= 1u;
306-
self.chains[idx] = entry.next;
307-
true
308-
}
309-
FoundAfter(eprev, entry) => {
310-
self.count -= 1u;
311-
eprev.next = entry.next;
312-
true
313-
}
314-
}
315-
}
316-
317-
pure fn each(&self, blk: fn(key: &K, value: &V) -> bool) {
318-
for self.each_entry |entry| {
319-
if !blk(&entry.key, &entry.value) { break; }
320-
}
321-
}
322-
323-
pure fn each_key(&self, blk: fn(key: &K) -> bool) {
324-
self.each(|k, _v| blk(k))
325-
}
326-
327-
pure fn each_value(&self, blk: fn(value: &V) -> bool) {
328-
self.each(|_k, v| blk(v))
329-
}
330332
}
331333

332334
impl<K:Eq IterBytes Hash Copy ToStr, V: ToStr Copy> T<K, V> {

0 commit comments

Comments
 (0)