pub struct PageRecords(pub IdHashMap<PageRecord>);Tuple Fields§
§0: IdHashMap<PageRecord>Implementations§
Source§impl PageRecords
impl PageRecords
pub fn insert_view<C>(&mut self, s: &SimulationState<C>, v: &mut View)
pub fn push_sim_end(&mut self, pageid: &PageId, e: SimEnd)
pub fn depth(&self) -> usize
Source§impl PageRecords
impl PageRecords
Methods from Deref<Target = IdHashMap<PageRecord>>§
Sourcepub fn allocator(&self) -> &A
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();Sourcepub fn capacity(&self) -> usize
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);Sourcepub fn is_empty(&self) -> bool
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());Sourcepub fn len(&self) -> usize
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);Sourcepub fn clear(&mut self)
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);Sourcepub fn reserve(&mut self, additional: usize)
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);Sourcepub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
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);Sourcepub fn shrink_to_fit(&mut self)
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);Sourcepub fn shrink_to(&mut self, min_capacity: usize)
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);Sourcepub fn iter(&self) -> Iter<'_, T>
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]);Sourcepub fn iter_mut(&mut self) -> IterMut<'_, T, S, A>
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);Sourcepub fn insert_overwrite(&mut self, value: T) -> Option<T>
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);Sourcepub fn insert_unique(&mut self, value: T) -> Result<(), DuplicateItem<T, &T>>
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()
);Sourcepub fn contains_key<'a, Q>(&'a self, key1: &Q) -> bool
pub fn contains_key<'a, Q>(&'a self, key1: &Q) -> bool
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"));Sourcepub fn get<'a, Q>(&'a self, key: &Q) -> Option<&'a T>
pub fn get<'a, Q>(&'a self, key: &Q) -> Option<&'a T>
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());Sourcepub fn get_mut<'a, Q>(&'a mut self, key: &Q) -> Option<RefMut<'a, T, S>>
pub fn get_mut<'a, Q>(&'a mut self, key: &Q) -> Option<RefMut<'a, T, S>>
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());Sourcepub fn remove<'a, Q>(&'a mut self, key: &Q) -> Option<T>
pub fn remove<'a, Q>(&'a mut self, key: &Q) -> Option<T>
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());Sourcepub fn entry<'a>(
&'a mut self,
key: <T as IdHashItem>::Key<'_>,
) -> Entry<'a, T, S, A>
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);Sourcepub fn retain<'a, F>(&'a mut self, f: F)
pub fn retain<'a, F>(&'a mut self, f: F)
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
impl Clone for PageRecords
Source§fn clone(&self) -> PageRecords
fn clone(&self) -> PageRecords
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more