PageRecords

Struct PageRecords 

Source
pub struct PageRecords(pub IdHashMap<PageRecord>);

Tuple Fields§

§0: IdHashMap<PageRecord>

Implementations§

Source§

impl PageRecords

Source

pub fn insert_view<C>(&mut self, s: &SimulationState<C>, v: &mut View)

Source

pub fn push_sim_end(&mut self, pageid: &PageId, e: SimEnd)

Source

pub fn depth(&self) -> usize

Source§

impl PageRecords

Source

pub fn new() -> Self

Methods from Deref<Target = IdHashMap<PageRecord>>§

Source

pub fn allocator(&self) -> &A

Returns the allocator.

Requires the allocator-api2 feature to be enabled.

§Examples

Using the bumpalo allocator:

use iddqd::{IdHashMap, IdHashItem, id_upcast};

#[derive(Debug, PartialEq, Eq, Hash)]
struct Item {
    id: String,
    value: u32,
}

impl IdHashItem for Item {
    type Key<'a> = &'a str;
    fn key(&self) -> Self::Key<'_> { &self.id }
    id_upcast!();
}

// Define a new allocator.
let bump = bumpalo::Bump::new();
// Create a new IdHashMap using the allocator.
let map: IdHashMap<Item, _, &bumpalo::Bump> = IdHashMap::new_in(&bump);
let _allocator = map.allocator();
Source

pub fn capacity(&self) -> usize

Returns the currently allocated capacity of the map.

§Examples
use iddqd::{IdHashItem, IdHashMap, id_upcast};

#[derive(Debug, PartialEq, Eq, Hash)]
struct Item {
    id: String,
    value: u32,
}

impl IdHashItem for Item {
    type Key<'a> = &'a str;
    fn key(&self) -> Self::Key<'_> {
        &self.id
    }
    id_upcast!();
}

let map: IdHashMap<Item> = IdHashMap::with_capacity(10);
assert!(map.capacity() >= 10);
Source

pub fn is_empty(&self) -> bool

Returns true if the map is empty.

§Examples
use iddqd::{IdHashItem, IdHashMap, id_upcast};

#[derive(Debug, PartialEq, Eq, Hash)]
struct Item {
    id: String,
    value: u32,
}

impl IdHashItem for Item {
    type Key<'a> = &'a str;
    fn key(&self) -> Self::Key<'_> {
        &self.id
    }
    id_upcast!();
}

let mut map = IdHashMap::new();
assert!(map.is_empty());

map.insert_unique(Item { id: "foo".to_string(), value: 42 }).unwrap();
assert!(!map.is_empty());
Source

pub fn len(&self) -> usize

Returns the number of items in the map.

§Examples
use iddqd::{IdHashItem, IdHashMap, id_upcast};

#[derive(Debug, PartialEq, Eq, Hash)]
struct Item {
    id: String,
    value: u32,
}

impl IdHashItem for Item {
    type Key<'a> = &'a str;
    fn key(&self) -> Self::Key<'_> {
        &self.id
    }
    id_upcast!();
}

let mut map = IdHashMap::new();
assert_eq!(map.len(), 0);

map.insert_unique(Item { id: "foo".to_string(), value: 42 }).unwrap();
assert_eq!(map.len(), 1);

map.insert_unique(Item { id: "bar".to_string(), value: 20 }).unwrap();
assert_eq!(map.len(), 2);
Source

pub fn clear(&mut self)

Clears the map, removing all items.

§Examples
use iddqd::{IdHashItem, IdHashMap, id_upcast};

#[derive(Debug, PartialEq, Eq, Hash)]
struct Item {
    id: String,
    value: u32,
}

impl IdHashItem for Item {
    type Key<'a> = &'a str;
    fn key(&self) -> Self::Key<'_> {
        &self.id
    }
    id_upcast!();
}

let mut map = IdHashMap::new();
map.insert_unique(Item { id: "foo".to_string(), value: 42 }).unwrap();
map.insert_unique(Item { id: "bar".to_string(), value: 20 }).unwrap();
assert_eq!(map.len(), 2);

map.clear();
assert!(map.is_empty());
assert_eq!(map.len(), 0);
Source

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

Reserves capacity for at least additional more elements to be inserted in the IdHashMap. The collection may reserve more space to speculatively avoid frequent reallocations. After calling reserve, capacity will be greater than or equal to self.len() + additional. Does nothing if capacity is already sufficient.

§Panics

Panics if the new capacity overflows isize::MAX bytes, and aborts the program in case of an allocation error. Use try_reserve instead if you want to handle memory allocation failure.

§Examples
use iddqd::{IdHashItem, IdHashMap, id_upcast};

#[derive(Debug, PartialEq, Eq, Hash)]
struct Item {
    id: String,
    value: u32,
}

impl IdHashItem for Item {
    type Key<'a> = &'a str;
    fn key(&self) -> Self::Key<'_> {
        &self.id
    }
    id_upcast!();
}

let mut map: IdHashMap<Item> = IdHashMap::new();
map.reserve(100);
assert!(map.capacity() >= 100);
Source

pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>

Tries to reserve capacity for at least additional more elements to be inserted in the IdHashMap. The collection may reserve more space to speculatively avoid frequent reallocations. After calling try_reserve, capacity will be greater than or equal to self.len() + additional if it returns Ok(()). Does nothing if capacity is already sufficient.

§Errors

If the capacity overflows, or the allocator reports a failure, then an error is returned.

§Notes

If reservation fails partway through, some internal structures may have already increased their capacity. The map remains in a valid state but may have uneven capacities across its internal structures.

§Examples
use iddqd::{IdHashItem, IdHashMap, id_upcast};

#[derive(Debug, PartialEq, Eq, Hash)]
struct Item {
    id: String,
    value: u32,
}

impl IdHashItem for Item {
    type Key<'a> = &'a str;
    fn key(&self) -> Self::Key<'_> {
        &self.id
    }
    id_upcast!();
}

let mut map: IdHashMap<Item> = IdHashMap::new();
map.try_reserve(100).expect("allocation should succeed");
assert!(map.capacity() >= 100);
Source

pub fn shrink_to_fit(&mut self)

Shrinks the capacity of the map as much as possible. It will drop down as much as possible while maintaining the internal rules and possibly leaving some space in accordance with the resize policy.

§Examples
use iddqd::{IdHashItem, IdHashMap, id_upcast};

#[derive(Debug, PartialEq, Eq, Hash)]
struct Item {
    id: String,
    value: u32,
}

impl IdHashItem for Item {
    type Key<'a> = &'a str;
    fn key(&self) -> Self::Key<'_> {
        &self.id
    }
    id_upcast!();
}

let mut map: IdHashMap<Item> = IdHashMap::with_capacity(100);
map.insert_unique(Item { id: "foo".to_string(), value: 1 }).unwrap();
map.insert_unique(Item { id: "bar".to_string(), value: 2 }).unwrap();
assert!(map.capacity() >= 100);
map.shrink_to_fit();
assert!(map.capacity() >= 2);
Source

pub fn shrink_to(&mut self, min_capacity: usize)

Shrinks the capacity of the map with a lower limit. It will drop down no lower than the supplied limit while maintaining the internal rules and possibly leaving some space in accordance with the resize policy.

If the current capacity is less than the lower limit, this is a no-op.

§Examples
use iddqd::{IdHashItem, IdHashMap, id_upcast};

#[derive(Debug, PartialEq, Eq, Hash)]
struct Item {
    id: String,
    value: u32,
}

impl IdHashItem for Item {
    type Key<'a> = &'a str;
    fn key(&self) -> Self::Key<'_> {
        &self.id
    }
    id_upcast!();
}

let mut map: IdHashMap<Item> = IdHashMap::with_capacity(100);
map.insert_unique(Item { id: "foo".to_string(), value: 1 }).unwrap();
map.insert_unique(Item { id: "bar".to_string(), value: 2 }).unwrap();
assert!(map.capacity() >= 100);
map.shrink_to(10);
assert!(map.capacity() >= 10);
map.shrink_to(0);
assert!(map.capacity() >= 2);
Source

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

Iterates over the items in the map.

Similar to HashMap, the iteration order is arbitrary and not guaranteed to be stable.

§Examples
use iddqd::{IdHashItem, IdHashMap, id_upcast};

#[derive(Debug, PartialEq, Eq, Hash)]
struct Item {
    id: String,
    value: u32,
}

impl IdHashItem for Item {
    type Key<'a> = &'a str;
    fn key(&self) -> Self::Key<'_> {
        &self.id
    }
    id_upcast!();
}

let mut map = IdHashMap::new();
map.insert_unique(Item { id: "foo".to_string(), value: 42 }).unwrap();
map.insert_unique(Item { id: "bar".to_string(), value: 20 }).unwrap();

let mut values: Vec<u32> = map.iter().map(|item| item.value).collect();
values.sort();
assert_eq!(values, vec![20, 42]);
Source

pub fn iter_mut(&mut self) -> IterMut<'_, T, S, A>

Iterates over the items in the map, allowing for mutation.

Similar to HashMap, the iteration order is arbitrary and not guaranteed to be stable.

§Examples
use iddqd::{IdHashItem, IdHashMap, id_upcast};

#[derive(Debug, PartialEq, Eq, Hash)]
struct Item {
    id: String,
    value: u32,
}

impl IdHashItem for Item {
    type Key<'a> = &'a str;
    fn key(&self) -> Self::Key<'_> {
        &self.id
    }
    id_upcast!();
}

let mut map = IdHashMap::new();
map.insert_unique(Item { id: "foo".to_string(), value: 42 }).unwrap();
map.insert_unique(Item { id: "bar".to_string(), value: 20 }).unwrap();

for mut item in map.iter_mut() {
    item.value *= 2;
}

assert_eq!(map.get("foo").unwrap().value, 84);
assert_eq!(map.get("bar").unwrap().value, 40);
Source

pub fn insert_overwrite(&mut self, value: T) -> Option<T>

Inserts a value into the map, removing and returning the conflicting item, if any.

§Examples
use iddqd::{IdHashItem, IdHashMap, id_upcast};

#[derive(Debug, PartialEq, Eq, Hash)]
struct Item {
    id: String,
    value: u32,
}

impl IdHashItem for Item {
    type Key<'a> = &'a str;
    fn key(&self) -> Self::Key<'_> {
        &self.id
    }
    id_upcast!();
}

let mut map = IdHashMap::new();

// First insertion returns None
let old = map.insert_overwrite(Item { id: "foo".to_string(), value: 42 });
assert!(old.is_none());

// Second insertion with same key returns the old value
let old = map.insert_overwrite(Item { id: "foo".to_string(), value: 100 });
assert_eq!(old.unwrap().value, 42);
assert_eq!(map.get("foo").unwrap().value, 100);
Source

pub fn insert_unique(&mut self, value: T) -> Result<(), DuplicateItem<T, &T>>

Inserts a value into the set, returning an error if any duplicates were added.

§Examples
use iddqd::{IdHashItem, IdHashMap, id_upcast};

#[derive(Debug, PartialEq, Eq, Hash)]
struct Item {
    id: String,
    value: u32,
}

impl IdHashItem for Item {
    type Key<'a> = &'a str;
    fn key(&self) -> Self::Key<'_> {
        &self.id
    }
    id_upcast!();
}

let mut map = IdHashMap::new();

// First insertion succeeds
assert!(
    map.insert_unique(Item { id: "foo".to_string(), value: 42 }).is_ok()
);

// Second insertion with different key succeeds
assert!(
    map.insert_unique(Item { id: "bar".to_string(), value: 20 }).is_ok()
);

// Third insertion with duplicate key fails
assert!(
    map.insert_unique(Item { id: "foo".to_string(), value: 100 }).is_err()
);
Source

pub fn contains_key<'a, Q>(&'a self, key1: &Q) -> bool
where Q: Hash + Equivalent<<T as IdHashItem>::Key<'a>> + ?Sized,

Returns true if the map contains the given key.

§Examples
use iddqd::{IdHashItem, IdHashMap, id_upcast};

#[derive(Debug, PartialEq, Eq, Hash)]
struct Item {
    id: String,
    value: u32,
}

impl IdHashItem for Item {
    type Key<'a> = &'a str;
    fn key(&self) -> Self::Key<'_> {
        &self.id
    }
    id_upcast!();
}

let mut map = IdHashMap::new();
map.insert_unique(Item { id: "foo".to_string(), value: 42 }).unwrap();

assert!(map.contains_key("foo"));
assert!(!map.contains_key("bar"));
Source

pub fn get<'a, Q>(&'a self, key: &Q) -> Option<&'a T>
where Q: Hash + Equivalent<<T as IdHashItem>::Key<'a>> + ?Sized,

Gets a reference to the value associated with the given key.

§Examples
use iddqd::{IdHashItem, IdHashMap, id_upcast};

#[derive(Debug, PartialEq, Eq, Hash)]
struct Item {
    id: String,
    value: u32,
}

impl IdHashItem for Item {
    type Key<'a> = &'a str;
    fn key(&self) -> Self::Key<'_> {
        &self.id
    }
    id_upcast!();
}

let mut map = IdHashMap::new();
map.insert_unique(Item { id: "foo".to_string(), value: 42 }).unwrap();

assert_eq!(map.get("foo").unwrap().value, 42);
assert!(map.get("bar").is_none());
Source

pub fn get_mut<'a, Q>(&'a mut self, key: &Q) -> Option<RefMut<'a, T, S>>
where Q: Hash + Equivalent<<T as IdHashItem>::Key<'a>> + ?Sized,

Gets a mutable reference to the value associated with the given key.

§Examples
use iddqd::{IdHashItem, IdHashMap, id_upcast};

#[derive(Debug, PartialEq, Eq, Hash)]
struct Item {
    id: String,
    value: u32,
}

impl IdHashItem for Item {
    type Key<'a> = &'a str;
    fn key(&self) -> Self::Key<'_> {
        &self.id
    }
    id_upcast!();
}

let mut map = IdHashMap::new();
map.insert_unique(Item { id: "foo".to_string(), value: 42 }).unwrap();

if let Some(mut item) = map.get_mut("foo") {
    item.value = 100;
}

assert_eq!(map.get("foo").unwrap().value, 100);
assert!(map.get_mut("bar").is_none());
Source

pub fn remove<'a, Q>(&'a mut self, key: &Q) -> Option<T>
where Q: Hash + Equivalent<<T as IdHashItem>::Key<'a>> + ?Sized,

Removes an item from the map by its key.

§Examples
use iddqd::{IdHashItem, IdHashMap, id_upcast};

#[derive(Debug, PartialEq, Eq, Hash)]
struct Item {
    id: String,
    value: u32,
}

impl IdHashItem for Item {
    type Key<'a> = &'a str;
    fn key(&self) -> Self::Key<'_> {
        &self.id
    }
    id_upcast!();
}

let mut map = IdHashMap::new();
map.insert_unique(Item { id: "foo".to_string(), value: 42 }).unwrap();

let removed = map.remove("foo");
assert_eq!(removed.unwrap().value, 42);
assert!(map.is_empty());

// Removing non-existent key returns None
assert!(map.remove("bar").is_none());
Source

pub fn entry<'a>( &'a mut self, key: <T as IdHashItem>::Key<'_>, ) -> Entry<'a, T, S, A>

Retrieves an entry by its key.

Due to borrow checker limitations, this always accepts an owned key rather than a borrowed form of it.

§Examples
use iddqd::{IdHashItem, IdHashMap, id_upcast};

#[derive(Debug, PartialEq, Eq, Hash)]
struct Item {
    id: String,
    value: u32,
}

impl IdHashItem for Item {
    type Key<'a> = &'a str;
    fn key(&self) -> Self::Key<'_> {
        &self.id
    }
    id_upcast!();
}

let mut map = IdHashMap::new();

// Use entry API for conditional insertion
map.entry("foo").or_insert(Item { id: "foo".to_string(), value: 42 });
map.entry("bar").or_insert(Item { id: "bar".to_string(), value: 20 });

assert_eq!(map.len(), 2);
Source

pub fn retain<'a, F>(&'a mut self, f: F)
where F: FnMut(RefMut<'a, T, S>) -> bool,

Retains only the elements specified by the predicate.

In other words, remove all items T for which f(RefMut<T>) returns false. The elements are visited in an arbitrary order.

§Examples
use iddqd::{IdHashItem, IdHashMap, id_upcast};

#[derive(Debug, PartialEq, Eq, Hash)]
struct Item {
    id: String,
    value: u32,
}

impl IdHashItem for Item {
    type Key<'a> = &'a str;

    fn key(&self) -> Self::Key<'_> {
        &self.id
    }

    id_upcast!();
}

let mut map = IdHashMap::new();
map.insert_unique(Item { id: "foo".to_string(), value: 42 }).unwrap();
map.insert_unique(Item { id: "bar".to_string(), value: 20 }).unwrap();
map.insert_unique(Item { id: "baz".to_string(), value: 99 }).unwrap();

// Retain only items where value is greater than 30
map.retain(|item| item.value > 30);

assert_eq!(map.len(), 2);
assert_eq!(map.get("foo").unwrap().value, 42);
assert_eq!(map.get("baz").unwrap().value, 99);
assert!(map.get("bar").is_none());

Trait Implementations§

Source§

impl Clone for PageRecords

Source§

fn clone(&self) -> PageRecords

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

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

Performs copy-assignment from source. Read more
Source§

impl Debug for PageRecords

Source§

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

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

impl Deref for PageRecords

Source§

type Target = IdHashMap<PageRecord>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for PageRecords

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V