You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the filter is archetypal, call size_hint() to get the count without iterating. Otherwise, use an ordinary count().
Will both "archetypal => can return exact size" and "not archetypal => can't ever return exact size" always be true?
I'm not at all familiar with all this, but would it make sense to have a trait const that specifies whether size_hint() is accurate, or if adding a something new anyway, just an additional function such as size_exact() that returns an Option<usize>? Its default implementation could just return None.
Will both "archetypal => can return exact size" and "not archetypal => can't ever return exact size" always be true?
I'm not at all familiar with all this, but would it make sense to have a trait const that specifies whether size_hint() is accurate, or if adding a something new anyway, just an additional function such as size_exact() that returns an Option<usize>? Its default implementation could just return None.
Yup, I think that's what QueryFilter::IS_ARCHETYPAL is! The idea is that all queries filter to a certain set of tables or archetypes, but only queries with Added or Changed will further filter that by looking at individual entities. So if we know we don't have those, then we know exactly how many entities will match.
It gets used in the size_hint implementation to determine the minimum size.
let max_size = self.cursor.max_remaining(self.tables,self.archetypes);
let archetype_query = F::IS_ARCHETYPAL;
let min_size = if archetype_query { max_size }else{0};
(min_size asusize,Some(max_size asusize))
}
There's also an ArchetypeFilter trait that's implemented if and only if IS_ARCHETYPAL is true. That's used to get the ExactSizeIterator impl that enables len().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A-ECSEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleD-StraightforwardSimple bug fixes and API improvements, docs, test and examplesS-Ready-For-Final-ReviewThis PR has been approved by the community. It's ready for a maintainer to consider merging it
5 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
Make it easy to efficiently count the number of entities matching a query.
Solution
Implement a
Query::count()method.Use
as_nop()to skip initializing the fetch state, like we do foris_empty()andcontains().If the filter is archetypal, call
size_hint()to get the count without iterating. Otherwise, use an ordinarycount().