pub struct EntitySet<'a, E: Entity>(/* private fields */);Expand description
Opaque public wrapper around the internal set-expression tree.
Implementations§
Source§impl<'a, E: Entity> EntitySet<'a, E>
impl<'a, E: Entity> EntitySet<'a, E>
pub fn union(self, other: Self) -> Self
pub fn intersection(self, other: Self) -> Self
pub fn difference(self, other: Self) -> Self
Sourcepub fn contains(&self, entity_id: EntityId<E>) -> bool
pub fn contains(&self, entity_id: EntityId<E>) -> bool
Test whether entity_id is a member of this set.
Sourcepub fn to_owned_vec(self) -> Vec<EntityId<E>>
pub fn to_owned_vec(self) -> Vec<EntityId<E>>
Collect this set’s contents into an owned vector of EntityId<E>.
Sourcepub fn sample_entity_excluding<R, X>(
&self,
rng: &mut R,
excluded: X,
) -> Option<EntityId<E>>
pub fn sample_entity_excluding<R, X>( &self, rng: &mut R, excluded: X, ) -> Option<EntityId<E>>
Sample a single entity uniformly from this set, excluding any entity
equal to excluded. Returns None if the set is empty or contains
only the excluded entity.
For source-leaf sets with random-access backing (PopulationRange,
IndexSet), runs in O(1) with at most two index lookups and no
iterator construction. Falls back to O(n) reservoir sampling for
composite sets and PropertySet sources.
Sourcepub fn sample_entity<R>(&self, rng: &mut R) -> Option<EntityId<E>>where
R: Rng,
pub fn sample_entity<R>(&self, rng: &mut R) -> Option<EntityId<E>>where
R: Rng,
Sample a single entity uniformly from this set. Returns None if the
set is empty.
Sourcepub fn count_and_sample_entity<R>(
&self,
rng: &mut R,
) -> (usize, Option<EntityId<E>>)where
R: Rng,
pub fn count_and_sample_entity<R>(
&self,
rng: &mut R,
) -> (usize, Option<EntityId<E>>)where
R: Rng,
Count the entities in this set and sample one uniformly from them.
Returns (count, sample) where sample is None iff count == 0.