pub struct IntMap<V> { /* private fields */ }
Implementations§
Source§impl<V> IntMap<V>
impl<V> IntMap<V>
Sourcepub fn new() -> IntMap<V>
pub fn new() -> IntMap<V>
Creates a new IntMap.
§Examples
use intmap::IntMap;
let mut map: IntMap<u64> = IntMap::new();
assert_eq!(map, IntMap::default());
Sourcepub fn with_capacity(capacity: usize) -> IntMap<V>
pub fn with_capacity(capacity: usize) -> IntMap<V>
Creates a new IntMap with at least the given capacity, rounded to the next power of two.
§Examples
use intmap::IntMap;
let mut map: IntMap<u64> = IntMap::with_capacity(20);
Sourcepub fn set_load_factor(&mut self, load_factor: f32)
pub fn set_load_factor(&mut self, load_factor: f32)
Sets load rate of IntMap rounded to the first decimal point.
Values above 1.0 is allowed.
§Examples
use intmap::IntMap;
let mut map: IntMap<u64> = IntMap::with_capacity(20);
map.set_load_factor(0.909); // Sets load factor to 90.9%
Sourcepub fn get_load_factor(&self) -> f32
pub fn get_load_factor(&self) -> f32
Returns current load_factor
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Ensures that the IntMap has space for at least additional
more elements
Sourcepub fn insert(&mut self, key: u64, value: V) -> Option<V>
pub fn insert(&mut self, key: u64, value: V) -> Option<V>
Insert key/value into the IntMap.
This function returns the previous value if any otherwise None
.
§Examples
use intmap::IntMap;
let mut map = IntMap::new();
assert_eq!(map.insert(21, "Eat my shorts"), None);
assert_eq!(map.insert(21, "Ay, caramba"), Some("Eat my shorts"));
assert_eq!(map.get(21), Some(&"Ay, caramba"));
Sourcepub fn insert_checked(&mut self, key: u64, value: V) -> bool
pub fn insert_checked(&mut self, key: u64, value: V) -> bool
Insert key/value into the IntMap if the key is not yet inserted.
This function returns true if key/value were inserted and false otherwise.
§Examples
use intmap::IntMap;
let mut map = IntMap::new();
assert!(map.insert_checked(21, "Eat my shorts"));
assert!(!map.insert_checked(21, "Ay, caramba"));
assert_eq!(map.get(21), Some(&"Eat my shorts"));
Sourcepub fn get(&self, key: u64) -> Option<&V>
pub fn get(&self, key: u64) -> Option<&V>
Get value from the IntMap.
§Examples
use intmap::IntMap;
let mut map: IntMap<u64> = IntMap::new();
map.insert(21, 42);
let val = map.get(21);
assert!(val.is_some());
assert_eq!(*val.unwrap(), 42);
assert!(map.contains_key(21));
Sourcepub fn get_mut(&mut self, key: u64) -> Option<&mut V>
pub fn get_mut(&mut self, key: u64) -> Option<&mut V>
Get mutable value from the IntMap.
§Examples
use intmap::IntMap;
let mut map: IntMap<u64> = IntMap::new();
map.insert(21, 42);
assert_eq!(*map.get(21).unwrap(), 42);
assert!(map.contains_key(21));
{
let mut val = map.get_mut(21).unwrap();
*val+=1;
}
assert_eq!(*map.get(21).unwrap(), 43);
Sourcepub fn remove(&mut self, key: u64) -> Option<V>
pub fn remove(&mut self, key: u64) -> Option<V>
Remove value from the IntMap.
§Examples
use intmap::IntMap;
let mut map: IntMap<u64> = IntMap::new();
map.insert(21, 42);
let val = map.remove(21);
assert!(val.is_some());
assert_eq!(val.unwrap(), 42);
assert!(!map.contains_key(21));
Sourcepub fn contains_key(&self, key: u64) -> bool
pub fn contains_key(&self, key: u64) -> bool
Returns true if key is in map.
§Examples
use intmap::IntMap;
let mut map: IntMap<u64> = IntMap::new();
map.insert(21, 42);
assert!(map.contains_key(21));
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Removes all elements from map.
§Examples
use intmap::IntMap;
let mut map: IntMap<u64> = IntMap::new();
map.insert(21, 42);
map.clear();
assert_eq!(map.len(), 0);
Sourcepub fn retain<F>(&mut self, f: F)
pub fn retain<F>(&mut self, f: F)
Retains only the elements specified by the predicate.
In other words, remove all elements such that f(key, &value)
returns false.
§Examples
use intmap::IntMap;
let mut map: IntMap<u64> = IntMap::new();
map.insert(1, 11);
map.insert(2, 12);
map.insert(4, 13);
// retain only the odd values
map.retain(|k, v| *v % 2 == 1);
assert_eq!(map.len(), 2);
assert!(map.contains_key(1));
assert!(map.contains_key(4));
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if map is empty
§Examples
use intmap::IntMap;
let mut map: IntMap<u64> = IntMap::new();
map.insert(21, 42);
assert!(!map.is_empty());
map.remove(21);
assert!(map.is_empty());
pub fn iter(&self) -> Iter<'_, u64, V>
pub fn iter_mut(&mut self) -> IterMut<'_, u64, V>
pub fn keys(&self) -> Keys<'_, u64, V>
pub fn values(&self) -> Values<'_, u64, V>
pub fn values_mut(&mut self) -> ValuesMut<'_, u64, V>
pub fn drain(&mut self) -> Drain<'_, u64, V>
pub fn load_rate(&self) -> f64
pub fn assert_count(&self) -> bool
pub fn collisions(&self) -> IntMap<u64>
Sourcepub fn entry(&mut self, key: u64) -> Entry<'_, V>
pub fn entry(&mut self, key: u64) -> Entry<'_, V>
Gets the Entry
that corresponds to the given key.
§Examples
use intmap::{IntMap, Entry};
let mut counters = IntMap::new();
for number in [10, 30, 10, 40, 50, 50, 60, 50] {
let counter = match counters.entry(number) {
Entry::Occupied(entry) => entry.into_mut(),
Entry::Vacant(entry) => entry.insert(0),
};
*counter += 1;
}
assert_eq!(counters.get(10), Some(&2));
assert_eq!(counters.get(20), None);
assert_eq!(counters.get(30), Some(&1));
assert_eq!(counters.get(40), Some(&1));
assert_eq!(counters.get(50), Some(&3));
assert_eq!(counters.get(60), Some(&1));
Trait Implementations§
Source§impl<V> Extend<(u64, V)> for IntMap<V>
impl<V> Extend<(u64, V)> for IntMap<V>
Source§fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = (u64, V)>,
fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = (u64, V)>,
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)