1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
use crate::{IndexTreeMap, Key, Value};
impl<K: Key, V: Value> IndexTreeMap<K, V> {
/// Returns true if the map contains a value for the specified key.
///
/// The key may be any borrowed form of the map’s key type, but the
/// ordering on the borrowed form must match the ordering on the key type.
///
/// # Example
///
/// Basic usage:
/// ```rust
/// use indextreemap::IndexTreeMap;
///
/// let mut tree = IndexTreeMap::new();
/// tree.insert(1, "a".to_string());
/// assert_eq!(tree.contains_key(&1), true);
/// assert_eq!(tree.contains_key(&2), false);
/// ```
pub fn contains_key(&self, key: &K) -> bool {
self.root.get_item(key).is_some()
}
/// Returns true if the map contains an item in the index position.
///
/// # Example
///
/// Basic usage:
/// ```rust
/// use indextreemap::IndexTreeMap;
///
/// let mut tree = IndexTreeMap::new();
/// tree.insert(1, "a".to_string());
/// assert_eq!(tree.contains_index(0), true);
/// assert_eq!(tree.contains_index(1), false);
/// ```
pub fn contains_index(&self, index: usize) -> bool {
index < self.size
}
}