@@ -96,7 +96,8 @@ fn test_resize_policy() {
96
96
}
97
97
98
98
// The main performance trick in this hashmap is called Robin Hood linear
99
- // probing. It gains its excellent performance from one essential operation:
99
+ // probing hashing. It gains its excellent performance from one essential
100
+ // operation:
100
101
//
101
102
// If an insertion collides with an existing element, and that element's
102
103
// "displacement" (how far away the element is from its ideal location)
@@ -226,11 +227,12 @@ fn test_resize_policy() {
226
227
///
227
228
/// Relevant papers/articles:
228
229
///
229
- /// 1. Emmanuel Goossaert. ["Robin Hood
230
+ /// 1. Pedro Celis. ["Robin Hood Hashing"](https://cs.uwaterloo.ca/research/tr/1986/CS-86-14.pdf)
231
+ /// 2. Emmanuel Goossaert. ["Robin Hood
230
232
/// hashing"](http://codecapsule.com/2013/11/11/robin-hood-hashing/)
231
- /// 2 . Emmanuel Goossaert. ["Robin Hood hashing: backward shift
233
+ /// 3 . Emmanuel Goossaert. ["Robin Hood hashing: backward shift
232
234
/// deletion"](http://codecapsule.com/2013/11/17/robin-hood-hashing-backward-shift-deletion/)
233
- /// 3 . Alfredo Viola (2005). Distributional analysis of Robin Hood linear probing
235
+ /// 4 . Alfredo Viola (2005). Distributional analysis of Robin Hood linear probing
234
236
/// hashing with buckets.
235
237
///
236
238
/// # Example
@@ -324,10 +326,9 @@ fn search_hashed<K, V, M, F>(table: M,
324
326
{
325
327
// Worst case, we'll find one empty bucket among `size + 1` buckets.
326
328
let size = table. size ( ) ;
327
- let mut probe = if let Some ( probe) = Bucket :: new ( table, hash) {
328
- probe
329
- } else {
330
- return InternalEntry :: TableIsEmpty ;
329
+ let mut probe = match Bucket :: new ( table, hash) {
330
+ Some ( probe) => probe,
331
+ None => return InternalEntry :: TableIsEmpty ,
331
332
} ;
332
333
let ib = probe. index ( ) ;
333
334
@@ -1468,7 +1469,7 @@ impl<'a, K, V> ExactSizeIterator for Values<'a, K, V> {
1468
1469
#[ inline] fn len ( & self ) -> usize { self . inner . len ( ) }
1469
1470
}
1470
1471
1471
-
1472
+ # [ stable ( feature = "rust1" , since = "1.0.0" ) ]
1472
1473
impl < ' a , K , V > Iterator for Drain < ' a , K , V > {
1473
1474
type Item = ( K , V ) ;
1474
1475
@@ -1490,6 +1491,7 @@ impl<'a, K, V> Iterator for Drain<'a, K, V> {
1490
1491
}
1491
1492
}
1492
1493
1494
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1493
1495
impl < ' a , K , V > ExactSizeIterator for Drain < ' a , K , V > {
1494
1496
fn len ( & self ) -> usize { self . inner . table ( ) . size ( ) }
1495
1497
}
@@ -1874,11 +1876,32 @@ mod test_map {
1874
1876
}
1875
1877
1876
1878
#[ test]
1877
- fn test_empty_pop ( ) {
1879
+ fn test_empty_remove ( ) {
1878
1880
let mut m: HashMap < int , bool > = HashMap :: new ( ) ;
1879
1881
assert_eq ! ( m. remove( & 0 ) , None ) ;
1880
1882
}
1881
1883
1884
+ #[ test]
1885
+ fn test_empty_entry ( ) {
1886
+ let mut m: HashMap < int , bool > = HashMap :: new ( ) ;
1887
+ assert ! ( m. entry( & 0 ) . is_err( ) ) ;
1888
+ assert ! ( * m. entry( & 0 ) . get( ) . unwrap_or_else( |e| e. insert( true ) ) ) ;
1889
+ assert_eq ! ( m. len( ) , 1 ) ;
1890
+ }
1891
+
1892
+ #[ test]
1893
+ fn test_empty_iter ( ) {
1894
+ let m: HashMap < int , bool > = HashMap :: new ( ) ;
1895
+ assert_eq ! ( m. drain( ) . next( ) , None ) ;
1896
+ assert_eq ! ( m. keys( ) . next( ) , None ) ;
1897
+ assert_eq ! ( m. values( ) . next( ) , None ) ;
1898
+ assert_eq ! ( m. iter( ) . next( ) , None ) ;
1899
+ assert_eq ! ( m. iter_mut( ) . next( ) , None ) ;
1900
+ assert_eq ! ( m. len( ) , 0 ) ;
1901
+ assert ! ( m. is_empty( ) ) ;
1902
+ assert_eq ! ( m. into_iter( ) . next( ) , None ) ;
1903
+ }
1904
+
1882
1905
#[ test]
1883
1906
fn test_lots_of_insertions ( ) {
1884
1907
let mut m = HashMap :: new ( ) ;
0 commit comments