pub struct EntitySet<I: EntityId, V: Hash + Eq, RS: BuildHasher = RandomState> { /* private fields */ }Expand description
An [indexmap::IndexSet] with strongly-typed indices.
An EntitySet assigns sequential IDs to each inserted value V. However, if a value which is
already present is inserted again, the pre-existing ID will be reused.
Implementations§
Source§impl<I, V, RS> EntitySet<I, V, RS>
impl<I, V, RS> EntitySet<I, V, RS>
pub fn with_hasher(h: RS) -> Self
pub fn with_capacity_and_hasher(n: usize, h: RS) -> Self
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn next_id(&self) -> I
pub fn clear(&mut self)
Sourcepub fn insert(&mut self, v: V) -> (I, bool)
pub fn insert(&mut self, v: V) -> (I, bool)
Insert a value into the set.
If the value was not previously present in the set, returns (id, true). Otherwise,
returns (id, false).
Sourcepub fn insert_new(&mut self, v: V) -> I
pub fn insert_new(&mut self, v: V) -> I
Insert a new value into the set.
Panics if the value is already present in the set.
Sourcepub fn get<Q>(&self, key: &Q) -> Option<I>
pub fn get<Q>(&self, key: &Q) -> Option<I>
Returns the ID for a given value, if already present in the set.
pub fn contains<Q>(&self, key: &Q) -> bool
pub fn ids(&self) -> EntityRange<I>
pub fn iter(&self) -> Iter<'_, I, V> ⓘ
pub fn values(&self) -> Iter<'_, V> ⓘ
pub fn into_values(self) -> IntoIter<V> ⓘ
pub fn into_vec(self) -> EntityVec<I, V>
Sourcepub fn get_or_insert(
&mut self,
key: &(impl ToOwned<Owned = V> + Hash + Equivalent<V> + ?Sized),
) -> I
pub fn get_or_insert( &mut self, key: &(impl ToOwned<Owned = V> + Hash + Equivalent<V> + ?Sized), ) -> I
Return an ID for a given value, whether pre-existing or newly allocated.
This function allows providing a reference for the purpose of looking up the value. In this
case, the value is only cloned if necessary (by means of ToOwned).
Trait Implementations§
Source§impl<I: Clone + EntityId, V: Clone + Hash + Eq, RS: Clone + BuildHasher> Clone for EntitySet<I, V, RS>
impl<I: Clone + EntityId, V: Clone + Hash + Eq, RS: Clone + BuildHasher> Clone for EntitySet<I, V, RS>
impl<I, V, RS> Eq for EntitySet<I, V, RS>
Source§impl<I, V, RS> Extend<V> for EntitySet<I, V, RS>
impl<I, V, RS> Extend<V> for EntitySet<I, V, RS>
Source§fn extend<T: IntoIterator<Item = V>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = V>>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: T)
fn extend_one(&mut self, item: T)
🔬This is a nightly-only experimental API. (
extend_one)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
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<I, V, RS> FromIterator<V> for EntitySet<I, V, RS>
impl<I, V, RS> FromIterator<V> for EntitySet<I, V, RS>
Source§fn from_iter<T>(iter: T) -> Selfwhere
T: IntoIterator<Item = V>,
fn from_iter<T>(iter: T) -> Selfwhere
T: IntoIterator<Item = V>,
Creates a value from an iterator. Read more
Source§impl<I, V, RS> IntoIterator for EntitySet<I, V, RS>
impl<I, V, RS> IntoIterator for EntitySet<I, V, RS>
Source§impl<'a, I, V, RS> IntoIterator for &'a EntitySet<I, V, RS>
impl<'a, I, V, RS> IntoIterator for &'a EntitySet<I, V, RS>
Auto Trait Implementations§
impl<I, V, RS> Freeze for EntitySet<I, V, RS>where
RS: Freeze,
impl<I, V, RS> RefUnwindSafe for EntitySet<I, V, RS>
impl<I, V, RS> Send for EntitySet<I, V, RS>
impl<I, V, RS> Sync for EntitySet<I, V, RS>
impl<I, V, RS> Unpin for EntitySet<I, V, RS>
impl<I, V, RS> UnsafeUnpin for EntitySet<I, V, RS>where
RS: UnsafeUnpin,
impl<I, V, RS> UnwindSafe for EntitySet<I, V, RS>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.