Rename EntityMap to SecondaryMap (#528)

* Rename `EntityMap` to `SecondaryMap`
This commit is contained in:
Muhammad Mominul Huque
2018-09-27 01:03:44 +06:00
committed by Dan Gohman
parent 7ff71fcfd9
commit d266b1a42d
18 changed files with 91 additions and 91 deletions

View File

@@ -15,7 +15,7 @@
//!
//! - [`PrimaryMap`](struct.PrimaryMap.html) is used to keep track of a vector of entities,
//! assigning a unique entity reference to each.
//! - [`EntityMap`](struct.EntityMap.html) is used to associate secondary information to an entity.
//! - [`SecondaryMap`](struct.SecondaryMap.html) is used to associate secondary information to an entity.
//! The map is implemented as a simple vector, so it does not keep track of which entities have
//! been inserted. Instead, any unknown entities map to the default value.
//! - [`SparseMap`](struct.SparseMap.html) is used to associate secondary information to a small
@@ -70,7 +70,7 @@ mod std {
pub extern crate core as __core;
/// A type wrapping a small integer index should implement `EntityRef` so it can be used as the key
/// of an `EntityMap` or `SparseMap`.
/// of an `SecondaryMap` or `SparseMap`.
pub trait EntityRef: Copy + Eq {
/// Create a new entity reference from a small integer.
/// This should crash if the requested index is not representable.
@@ -135,7 +135,7 @@ mod sparse;
pub use self::iter::{Iter, IterMut};
pub use self::keys::Keys;
pub use self::list::{EntityList, ListPool};
pub use self::map::EntityMap;
pub use self::map::SecondaryMap;
pub use self::primary::PrimaryMap;
pub use self::set::EntitySet;
pub use self::sparse::{SparseMap, SparseMapValue, SparseSet};

View File

@@ -8,14 +8,14 @@ use {EntityRef, Iter, IterMut, Keys};
/// A mapping `K -> V` for densely indexed entity references.
///
/// The `EntityMap` data structure uses the dense index space to implement a map with a vector.
/// Unlike `PrimaryMap`, an `EntityMap` can't be used to allocate entity references. It is used to
/// The `SecondaryMap` data structure uses the dense index space to implement a map with a vector.
/// Unlike `PrimaryMap`, an `SecondaryMap` can't be used to allocate entity references. It is used to
/// associate secondary information with entities.
///
/// The map does not track if an entry for a key has been inserted or not. Instead it behaves as if
/// all keys have a default entry from the beginning.
#[derive(Debug, Clone)]
pub struct EntityMap<K, V>
pub struct SecondaryMap<K, V>
where
K: EntityRef,
V: Clone,
@@ -25,8 +25,8 @@ where
unused: PhantomData<K>,
}
/// Shared `EntityMap` implementation for all value types.
impl<K, V> EntityMap<K, V>
/// Shared `SecondaryMap` implementation for all value types.
impl<K, V> SecondaryMap<K, V>
where
K: EntityRef,
V: Clone,
@@ -100,10 +100,10 @@ where
}
}
/// Immutable indexing into an `EntityMap`.
/// Immutable indexing into an `SecondaryMap`.
///
/// All keys are permitted. Untouched entries have the default value.
impl<K, V> Index<K> for EntityMap<K, V>
impl<K, V> Index<K> for SecondaryMap<K, V>
where
K: EntityRef,
V: Clone,
@@ -115,10 +115,10 @@ where
}
}
/// Mutable indexing into an `EntityMap`.
/// Mutable indexing into an `SecondaryMap`.
///
/// The map grows as needed to accommodate new keys.
impl<K, V> IndexMut<K> for EntityMap<K, V>
impl<K, V> IndexMut<K> for SecondaryMap<K, V>
where
K: EntityRef,
V: Clone,
@@ -154,7 +154,7 @@ mod tests {
let r0 = E(0);
let r1 = E(1);
let r2 = E(2);
let mut m = EntityMap::new();
let mut m = SecondaryMap::new();
let v: Vec<E> = m.keys().collect();
assert_eq!(v, []);

View File

@@ -7,7 +7,7 @@ use {EntityRef, Keys};
/// A set of `K` for densely indexed entity references.
///
/// The `EntitySet` data structure uses the dense index space to implement a set with a bitvector.
/// Like `EntityMap`, an `EntitySet` is used to associate secondary information with entities.
/// Like `SecondaryMap`, an `EntitySet` is used to associate secondary information with entities.
#[derive(Debug, Clone)]
pub struct EntitySet<K>
where

View File

@@ -11,7 +11,7 @@ use std::mem;
use std::slice;
use std::u32;
use std::vec::Vec;
use {EntityMap, EntityRef};
use {EntityRef, SecondaryMap};
/// Trait for extracting keys from values stored in a `SparseMap`.
///
@@ -27,16 +27,16 @@ pub trait SparseMapValue<K> {
///
/// A `SparseMap<K, V>` map provides:
///
/// - Memory usage equivalent to `EntityMap<K, u32>` + `Vec<V>`, so much smaller than
/// `EntityMap<K, V>` for sparse mappings of larger `V` types.
/// - Constant time lookup, slightly slower than `EntityMap`.
/// - Memory usage equivalent to `SecondaryMap<K, u32>` + `Vec<V>`, so much smaller than
/// `SecondaryMap<K, V>` for sparse mappings of larger `V` types.
/// - Constant time lookup, slightly slower than `SecondaryMap`.
/// - A very fast, constant time `clear()` operation.
/// - Fast insert and erase operations.
/// - Stable iteration that is as fast as a `Vec<V>`.
///
/// # Compared to `EntityMap`
/// # Compared to `SecondaryMap`
///
/// When should we use a `SparseMap` instead of a secondary `EntityMap`? First of all, `SparseMap`
/// When should we use a `SparseMap` instead of a secondary `SecondaryMap`? First of all, `SparseMap`
/// does not provide the functionality of a `PrimaryMap` which can allocate and assign entity
/// references to objects as they are pushed onto the map. It is only the secondary entity maps
/// that can be replaced with a `SparseMap`.
@@ -44,10 +44,10 @@ pub trait SparseMapValue<K> {
/// - A secondary entity map assigns a default mapping to all keys. It doesn't distinguish between
/// an unmapped key and one that maps to the default value. `SparseMap` does not require
/// `Default` values, and it tracks accurately if a key has been mapped or not.
/// - Iterating over the contents of an `EntityMap` is linear in the size of the *key space*, while
/// - Iterating over the contents of an `SecondaryMap` is linear in the size of the *key space*, while
/// iterating over a `SparseMap` is linear in the number of elements in the mapping. This is an
/// advantage precisely when the mapping is sparse.
/// - `SparseMap::clear()` is constant time and super-fast. `EntityMap::clear()` is linear in the
/// - `SparseMap::clear()` is constant time and super-fast. `SecondaryMap::clear()` is linear in the
/// size of the key space. (Or, rather the required `resize()` call following the `clear()` is).
/// - `SparseMap` requires the values to implement `SparseMapValue<K>` which means that they must
/// contain their own key.
@@ -56,7 +56,7 @@ where
K: EntityRef,
V: SparseMapValue<K>,
{
sparse: EntityMap<K, u32>,
sparse: SecondaryMap<K, u32>,
dense: Vec<V>,
}
@@ -68,7 +68,7 @@ where
/// Create a new empty mapping.
pub fn new() -> Self {
Self {
sparse: EntityMap::new(),
sparse: SecondaryMap::new(),
dense: Vec::new(),
}
}