1313/// Open addressing with linear probing.
1414pub mod linear {
1515 use container:: { Container , Mutable , Map , Set } ;
16- use cmp:: Eq ;
16+ use cmp:: { Eq , Equiv } ;
1717 use hash:: Hash ;
1818 use to_bytes:: IterBytes ;
1919 use iter:: BaseIter ;
@@ -107,6 +107,15 @@ pub mod linear {
107107 self . bucket_for_key_with_hash ( hash, k)
108108 }
109109
110+ #[ inline( always) ]
111+ pure fn bucket_for_key_equiv < Q : Hash + IterBytes + Equiv < K > > (
112+ & self ,
113+ k : & Q )
114+ -> SearchResult {
115+ let hash = k. hash_keyed ( self . k0 , self . k1 ) as uint ;
116+ self . bucket_for_key_with_hash_equiv ( hash, k)
117+ }
118+
110119 #[ inline( always) ]
111120 pure fn bucket_for_key_with_hash ( & self ,
112121 hash : uint ,
@@ -122,6 +131,24 @@ pub mod linear {
122131 TableFull
123132 }
124133
134+ #[ inline( always) ]
135+ pure fn bucket_for_key_with_hash_equiv < Q : Equiv < K > > ( & self ,
136+ hash : uint ,
137+ k : & Q )
138+ -> SearchResult {
139+ let _ = for self . bucket_sequence( hash) |i| {
140+ match self . buckets [ i] {
141+ Some ( ref bkt) => {
142+ if bkt. hash == hash && k. equiv ( & bkt. key ) {
143+ return FoundEntry ( i) ;
144+ }
145+ } ,
146+ None => return FoundHole ( i)
147+ }
148+ } ;
149+ TableFull
150+ }
151+
125152 /// Expand the capacity of the array to the next power of two
126153 /// and re-insert each of the existing buckets.
127154 #[ inline( always) ]
@@ -450,6 +477,28 @@ pub mod linear {
450477 None => fail!(fmt!(" No entry found for key: %?" , k) ) ,
451478 }
452479 }
480+
481+ /// Return true if the map contains a value for the specified key,
482+ /// using equivalence
483+ pure fn contains_key_equiv < Q : Hash + IterBytes + Equiv < K > > (
484+ & self ,
485+ key : & Q )
486+ -> bool {
487+ match self . bucket_for_key_equiv ( key) {
488+ FoundEntry ( _) => { true }
489+ TableFull | FoundHole ( _) => { false }
490+ }
491+ }
492+
493+ /// Return the value corresponding to the key in the map, using
494+ /// equivalence
495+ pure fn find_equiv < Q : Hash + IterBytes + Equiv < K > > ( & self , k : & Q )
496+ -> Option < & self /V > {
497+ match self . bucket_for_key_equiv ( k) {
498+ FoundEntry ( idx) => Some ( self . value_for_bucket ( idx) ) ,
499+ TableFull | FoundHole ( _) => None ,
500+ }
501+ }
453502 }
454503
455504 impl < K : Hash + IterBytes + Eq , V : Eq > Eq for LinearMap < K , V > {
0 commit comments