Struct IntMap

Source
pub struct IntMap<V> { /* private fields */ }

Implementations§

Source§

impl<V> IntMap<V>

Source

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());
Source

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);
Source

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%
Source

pub fn get_load_factor(&self) -> f32

Returns current load_factor

Source

pub fn reserve(&mut self, additional: usize)

Ensures that the IntMap has space for at least additional more elements

Source

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"));
Source

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"));
Source

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));
Source

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);
Source

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));
Source

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));
Source

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);
Source

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));
Source

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());
Source

pub fn iter(&self) -> Iter<'_, u64, V>

Source

pub fn iter_mut(&mut self) -> IterMut<'_, u64, V>

Source

pub fn keys(&self) -> Keys<'_, u64, V>

Source

pub fn values(&self) -> Values<'_, u64, V>

Source

pub fn values_mut(&mut self) -> ValuesMut<'_, u64, V>

Source

pub fn drain(&mut self) -> Drain<'_, u64, V>

Source

pub fn len(&self) -> usize

Number of elements in map.

Source

pub fn load(&self) -> u64

Force count number of slots filled.

Source

pub fn load_rate(&self) -> f64

Source

pub fn capacity(&self) -> usize

Total number of slots available.

Source

pub fn assert_count(&self) -> bool

Source

pub fn collisions(&self) -> IntMap<u64>

Source

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> Clone for IntMap<V>
where V: Clone,

Source§

fn clone(&self) -> IntMap<V>

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<V> Debug for IntMap<V>
where V: Debug,

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<V> Default for IntMap<V>

Source§

fn default() -> IntMap<V>

Returns the “default value” for a type. Read more
Source§

impl<V> Extend<(u64, V)> for IntMap<V>

Source§

fn extend<T>(&mut self, iter: T)
where T: IntoIterator<Item = (u64, V)>,

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<V> FromIterator<(u64, V)> for IntMap<V>

Source§

fn from_iter<T>(iter: T) -> IntMap<V>
where T: IntoIterator<Item = (u64, V)>,

Creates a value from an iterator. Read more
Source§

impl<V> IntoIterator for IntMap<V>

Source§

type Item = (u64, V)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<u64, V>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <IntMap<V> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl<V> PartialEq for IntMap<V>
where V: PartialEq,

Source§

fn eq(&self, other: &IntMap<V>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<V> Eq for IntMap<V>
where V: Eq,

Auto Trait Implementations§

§

impl<V> Freeze for IntMap<V>

§

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§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.