use iter::{self, Iterator, ExactSizeIterator, IntoIterator, IteratorExt, FromIterator, Extend, Map};
use marker::Sized;
use mem::{self, replace};
-use num::{Int, UnsignedInt};
-use ops::{Deref, FnMut, Index, IndexMut};
+use ops::{Deref, FnMut, Index};
use option::Option::{self, Some, None};
use rand::{self, Rng};
use result::Result::{self, Ok, Err};
/// It is required that the keys implement the `Eq` and `Hash` traits, although
/// this can frequently be achieved by using `#[derive(Eq, Hash)]`.
///
+/// It is a logic error for a key to be modified in such a way that the key's
+/// hash, as determined by the `Hash` trait, or its equality, as determined by
+/// the `Eq` trait, changes while it is in the map. This is normally only
+/// possible through `Cell`, `RefCell`, global state, I/O, or unsafe code.
+///
/// Relevant papers/articles:
///
/// 1. Pedro Celis. ["Robin Hood Hashing"](https://cs.uwaterloo.ca/research/tr/1986/CS-86-14.pdf)
/// 3. Emmanuel Goossaert. ["Robin Hood hashing: backward shift
/// deletion"](http://codecapsule.com/2013/11/17/robin-hood-hashing-backward-shift-deletion/)
///
-/// # Example
+/// # Examples
///
/// ```
/// use std::collections::HashMap;
impl<K: Hash + Eq, V> HashMap<K, V, RandomState> {
/// Create an empty HashMap.
///
- /// # Example
+ /// # Examples
///
/// ```
/// use std::collections::HashMap;
/// Creates an empty hash map with the given initial capacity.
///
- /// # Example
+ /// # Examples
///
/// ```
/// use std::collections::HashMap;
///
/// The creates map has the default initial capacity.
///
- /// # Example
+ /// # Examples
///
/// ```
/// use std::collections::HashMap;
/// cause many collisions and very poor performance. Setting it
/// manually using this function can expose a DoS attack vector.
///
- /// # Example
+ /// # Examples
///
/// ```
/// use std::collections::HashMap;
/// Returns the number of elements the map can hold without reallocating.
///
- /// # Example
+ /// # Examples
///
/// ```
/// use std::collections::HashMap;
///
/// Panics if the new allocation size overflows `usize`.
///
- /// # Example
+ /// # Examples
///
/// ```
/// use std::collections::HashMap;
/// down as much as possible while maintaining the internal rules
/// and possibly leaving some space in accordance with the resize policy.
///
- /// # Example
+ /// # Examples
///
/// ```
/// use std::collections::HashMap;
/// An iterator visiting all keys in arbitrary order.
/// Iterator element type is `&'a K`.
///
- /// # Example
+ /// # Examples
///
/// ```
/// use std::collections::HashMap;
/// An iterator visiting all values in arbitrary order.
/// Iterator element type is `&'a V`.
///
- /// # Example
+ /// # Examples
///
/// ```
/// use std::collections::HashMap;
/// An iterator visiting all key-value pairs in arbitrary order.
/// Iterator element type is `(&'a K, &'a V)`.
///
- /// # Example
+ /// # Examples
///
/// ```
/// use std::collections::HashMap;
/// with mutable references to the values.
/// Iterator element type is `(&'a K, &'a mut V)`.
///
- /// # Example
+ /// # Examples
///
/// ```
/// use std::collections::HashMap;
/// pair out of the map in arbitrary order. The map cannot be used after
/// calling this.
///
- /// # Example
+ /// # Examples
///
/// ```
/// use std::collections::HashMap;
/// Returns the number of elements in the map.
///
- /// # Example
+ /// # Examples
///
/// ```
/// use std::collections::HashMap;
/// Returns true if the map contains no elements.
///
- /// # Example
+ /// # Examples
///
/// ```
/// use std::collections::HashMap;
/// Clears the map, returning all key-value pairs as an iterator. Keeps the
/// allocated memory for reuse.
///
- /// # Example
+ /// # Examples
///
/// ```
/// use std::collections::HashMap;
/// Clears the map, removing all key-value pairs. Keeps the allocated memory
/// for reuse.
///
- /// # Example
+ /// # Examples
///
/// ```
/// use std::collections::HashMap;
/// `Hash` and `Eq` on the borrowed form *must* match those for
/// the key type.
///
- /// # Example
+ /// # Examples
///
/// ```
/// use std::collections::HashMap;
/// `Hash` and `Eq` on the borrowed form *must* match those for
/// the key type.
///
- /// # Example
+ /// # Examples
///
/// ```
/// use std::collections::HashMap;
/// `Hash` and `Eq` on the borrowed form *must* match those for
/// the key type.
///
- /// # Example
+ /// # Examples
///
/// ```
/// use std::collections::HashMap;
/// Inserts a key-value pair from the map. If the key already had a value
/// present in the map, that value is returned. Otherwise, `None` is returned.
///
- /// # Example
+ /// # Examples
///
/// ```
/// use std::collections::HashMap;
/// `Hash` and `Eq` on the borrowed form *must* match those for
/// the key type.
///
- /// # Example
+ /// # Examples
///
/// ```
/// use std::collections::HashMap;
}
}
-#[stable(feature = "rust1", since = "1.0.0")]
-impl<K, V, S, Q: ?Sized> IndexMut<Q> for HashMap<K, V, S>
- where K: Eq + Hash + Borrow<Q>,
- Q: Eq + Hash,
- S: HashState,
-{
- #[inline]
- fn index_mut<'a>(&'a mut self, index: &Q) -> &'a mut V {
- self.get_mut(index).expect("no entry found for key")
- }
-}
-
/// HashMap iterator.
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Iter<'a, K: 'a, V: 'a> {
}
#[test]
- #[should_fail]
+ #[should_panic]
fn test_index_nonexistent() {
let mut map = HashMap::new();