Implement Collection and Mutable traits

These just proxy the calls to the underlying hashmap.
This commit is contained in:
Tomas Sedovic 2014-06-23 11:23:54 +02:00
parent da3b57feb8
commit a9b1e31b70

View file

@ -13,7 +13,7 @@ extern crate test;
use std::any::Any; use std::any::Any;
use std::intrinsics::TypeId; use std::intrinsics::TypeId;
use std::collections::HashMap; use std::collections::{Collection, HashMap, Mutable};
use std::hash::{Hash, Hasher, Writer}; use std::hash::{Hash, Hasher, Writer};
use std::mem::{transmute, transmute_copy}; use std::mem::{transmute, transmute_copy};
use std::raw::TraitObject; use std::raw::TraitObject;
@ -144,6 +144,22 @@ impl AnyMap {
} }
} }
impl Collection for AnyMap {
fn len(&self) -> uint {
self.data.len()
}
fn is_empty(&self) -> bool {
self.data.is_empty()
}
}
impl Mutable for AnyMap {
fn clear(&mut self) {
self.data.clear();
}
}
#[bench] #[bench]
fn bench_insertion(b: &mut ::test::Bencher) { fn bench_insertion(b: &mut ::test::Bencher) {
b.iter(|| { b.iter(|| {