Rename EntityMap to ElementMap (tests not yet updated)
This commit is contained in:
+9
-9
@@ -1,30 +1,30 @@
|
||||
//! Provides maps to associate custom data to graph vertices and edges.
|
||||
//!
|
||||
//! [`EntityMap`] provides a copy-on-write, [`Vec`]-backed map to associate data to either all
|
||||
//! [`ElementMap`] provides a copy-on-write, [`Vec`]-backed map to associate data to either all
|
||||
//! vertices or all edges in a graph.
|
||||
|
||||
use std::ops::{Index, IndexMut};
|
||||
|
||||
/// A map to associate custom data to graph vertices or edges.
|
||||
///
|
||||
/// This map uses raw entity indices to associate homogenous custom data of type `T` to graph
|
||||
/// This map uses raw element indices to associate homogenous custom data of type `T` to graph
|
||||
/// vertices or edges. The implementation uses a [`Vec`], allocating contiguous slots for the data,
|
||||
/// which means that the provided index conversion function should map entities to contiguous
|
||||
/// which means that the provided index conversion function should map elements to contiguous
|
||||
/// indices, or indices with relatively few gaps.
|
||||
///
|
||||
/// Data allocation happens as copy-on-write, i.e. the backing [`Vec`] is only resized if a value is
|
||||
/// written beyond current capacity, but the `default` value can transparently be read. No bound or
|
||||
/// validity checks are performed by the map on the provided entity handles.
|
||||
/// validity checks are performed by the map on the provided element handles.
|
||||
///
|
||||
/// Use [`GraphTopology::vertex_map`] or [`GraphTopology::edge_map`] to obtain an `EntityMap` for
|
||||
/// Use [`GraphTopology::vertex_map`] or [`GraphTopology::edge_map`] to obtain an `ElementMap` for
|
||||
/// vertices or edges, respectively.
|
||||
pub struct EntityMap<E: Copy, T: Clone> {
|
||||
pub struct ElementMap<E: Copy, T: Clone> {
|
||||
data: Vec<T>,
|
||||
default: T,
|
||||
to_index: fn(E) -> usize,
|
||||
}
|
||||
|
||||
impl<E: Copy, T: Clone> EntityMap<E, T> {
|
||||
impl<E: Copy, T: Clone> ElementMap<E, T> {
|
||||
/// Creates a new map with the given `default` value, an index conversion function `to_index`,
|
||||
/// and an initial `capacity`.
|
||||
pub fn new(default: T, to_index: fn(E) -> usize, capacity: usize) -> Self {
|
||||
@@ -53,7 +53,7 @@ impl<E: Copy, T: Clone> EntityMap<E, T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: Copy, T: Clone> Index<E> for EntityMap<E, T> {
|
||||
impl<E: Copy, T: Clone> Index<E> for ElementMap<E, T> {
|
||||
type Output = T;
|
||||
|
||||
fn index(&self, e: E) -> &T {
|
||||
@@ -66,7 +66,7 @@ impl<E: Copy, T: Clone> Index<E> for EntityMap<E, T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: Copy, T: Clone> IndexMut<E> for EntityMap<E, T> {
|
||||
impl<E: Copy, T: Clone> IndexMut<E> for ElementMap<E, T> {
|
||||
fn index_mut(&mut self, e: E) -> &mut T {
|
||||
let i = (self.to_index)(e);
|
||||
if i >= self.data.len() {
|
||||
|
||||
Reference in New Issue
Block a user