Skip to content

Commit fed5df8

Browse files
committed
libcore: LinearMap doesn't need to pass around the bucket vec
1 parent 0f04df8 commit fed5df8

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/libcore/hashmap.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,17 @@ pub mod linear {
108108
}
109109

110110
#[inline(always)]
111-
pure fn bucket_for_key(&self, buckets: &[Option<Bucket<K, V>>],
112-
k: &K) -> SearchResult {
111+
pure fn bucket_for_key(&self, k: &K) -> SearchResult {
113112
let hash = k.hash_keyed(self.k0, self.k1) as uint;
114-
self.bucket_for_key_with_hash(buckets, hash, k)
113+
self.bucket_for_key_with_hash(hash, k)
115114
}
116115

117116
#[inline(always)]
118117
pure fn bucket_for_key_with_hash(&self,
119-
buckets: &[Option<Bucket<K, V>>],
120118
hash: uint,
121119
k: &K) -> SearchResult {
122120
let _ = for self.bucket_sequence(hash) |i| {
123-
match buckets[i] {
121+
match self.buckets[i] {
124122
Some(ref bkt) => if bkt.hash == hash && *k == bkt.key {
125123
return FoundEntry(i);
126124
},
@@ -161,7 +159,7 @@ pub mod linear {
161159
/// Assumes that there will be a bucket.
162160
/// True if there was no previous entry with that key
163161
fn insert_internal(&mut self, hash: uint, k: K, v: V) -> bool {
164-
match self.bucket_for_key_with_hash(self.buckets, hash, &k) {
162+
match self.bucket_for_key_with_hash(hash, &k) {
165163
TableFull => { die!(~"Internal logic error"); }
166164
FoundHole(idx) => {
167165
debug!("insert fresh (%?->%?) at idx %?, hash %?",
@@ -196,8 +194,7 @@ pub mod linear {
196194
//
197195
// I found this explanation elucidating:
198196
// http://www.maths.lse.ac.uk/Courses/MA407/del-hash.pdf
199-
let mut idx = match self.bucket_for_key_with_hash(self.buckets,
200-
hash, k) {
197+
let mut idx = match self.bucket_for_key_with_hash(hash, k) {
201198
TableFull | FoundHole(_) => return None,
202199
FoundEntry(idx) => idx
203200
};
@@ -273,7 +270,7 @@ pub mod linear {
273270
impl <K: Hash IterBytes Eq, V> LinearMap<K, V>: Map<K, V> {
274271
/// Return true if the map contains a value for the specified key
275272
pure fn contains_key(&self, k: &K) -> bool {
276-
match self.bucket_for_key(self.buckets, k) {
273+
match self.bucket_for_key(k) {
277274
FoundEntry(_) => {true}
278275
TableFull | FoundHole(_) => {false}
279276
}
@@ -291,7 +288,7 @@ pub mod linear {
291288
292289
/// Return the value corresponding to the key in the map
293290
pure fn find(&self, k: &K) -> Option<&self/V> {
294-
match self.bucket_for_key(self.buckets, k) {
291+
match self.bucket_for_key(k) {
295292
FoundEntry(idx) => {
296293
match self.buckets[idx] {
297294
Some(ref bkt) => {

0 commit comments

Comments
 (0)