pub struct IntMap<V> { /* private fields */ }
Implementations
sourceimpl<V> IntMap<V>
impl<V> IntMap<V>
sourcepub fn new() -> Self
pub fn new() -> Self
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) -> Self
pub fn with_capacity(capacity: usize) -> Self
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) where
F: FnMut(u64, &V) -> bool,
pub fn retain<F>(&mut self, f: F) where
F: FnMut(u64, &V) -> bool,
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
sourceimpl<'de, T: Deserialize<'de>> Deserialize<'de> for IntMap<T>
impl<'de, T: Deserialize<'de>> Deserialize<'de> for IntMap<T>
sourcefn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl<V> Extend<(u64, V)> for IntMap<V>
impl<V> Extend<(u64, V)> for IntMap<V>
sourcefn extend<T: IntoIterator<Item = (u64, V)>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = (u64, V)>>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl<V> FromIterator<(u64, V)> for IntMap<V>
impl<V> FromIterator<(u64, V)> for IntMap<V>
sourcefn from_iter<T: IntoIterator<Item = (u64, V)>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = (u64, V)>>(iter: T) -> Self
Creates a value from an iterator. Read more
sourceimpl<V> IntoIterator for IntMap<V>
impl<V> IntoIterator for IntMap<V>
impl<V> Eq for IntMap<V> where
V: Eq,
Auto Trait Implementations
impl<V> RefUnwindSafe for IntMap<V> where
V: RefUnwindSafe,
impl<V> Send for IntMap<V> where
V: Send,
impl<V> Sync for IntMap<V> where
V: Sync,
impl<V> Unpin for IntMap<V> where
V: Unpin,
impl<V> UnwindSafe for IntMap<V> where
V: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more