Table of Contents

Class QueryManager

Namespace
KeenEyes
Assembly
KeenEyes.Core.dll

Manages query caching and archetype matching for efficient query execution. Caches archetype matches per query descriptor and invalidates on archetype changes.

public sealed class QueryManager
Inheritance
QueryManager
Inherited Members

Remarks

The QueryManager maintains a cache of archetype matches for each unique query. On first execution, a query computes which archetypes match and caches the result. Subsequent queries with the same descriptor return cached results in O(1) time.

When a new archetype is created (due to entity component changes), the cache is invalidated for queries that could match the new archetype. This uses an incremental invalidation strategy to minimize overhead.

This implementation is thread-safe for concurrent query execution. The cache uses ConcurrentDictionary<TKey, TValue> for thread-safe entry management and KeenEyes.ArchetypeCache for lock-free archetype reads with synchronized writes.

Constructors

QueryManager(ArchetypeManager)

Creates a new QueryManager for the specified archetype manager.

public QueryManager(ArchetypeManager archetypeManager)

Parameters

archetypeManager ArchetypeManager

The archetype manager to query.

Properties

CacheHits

Gets the number of cache hits.

public long CacheHits { get; }

Property Value

long

CacheMisses

Gets the number of cache misses.

public long CacheMisses { get; }

Property Value

long

CachedQueryCount

Gets the number of queries currently cached.

public int CachedQueryCount { get; }

Property Value

int

HitRate

Gets the cache hit rate as a percentage.

public double HitRate { get; }

Property Value

double

Methods

GetMatchingArchetypes(QueryDescription)

Gets the archetypes matching the specified query description. Uses cached results when available.

public IReadOnlyList<Archetype> GetMatchingArchetypes(QueryDescription description)

Parameters

description QueryDescription

The query description.

Returns

IReadOnlyList<Archetype>

A list of matching archetypes.

GetMatchingArchetypes(QueryDescriptor)

Gets the archetypes matching the specified query descriptor. Uses cached results when available.

public IReadOnlyList<Archetype> GetMatchingArchetypes(QueryDescriptor descriptor)

Parameters

descriptor QueryDescriptor

The query descriptor.

Returns

IReadOnlyList<Archetype>

A list of matching archetypes.

Remarks

This method is thread-safe. Concurrent calls with the same descriptor may both compute matching archetypes if called simultaneously before the cache is populated, but the result will be consistent.

InvalidateCache()

Invalidates the entire cache.

public void InvalidateCache()

Remarks

This method is thread-safe. New queries will recompute matching archetypes after invalidation.

InvalidateQuery(QueryDescriptor)

Invalidates a specific query from the cache.

public void InvalidateQuery(QueryDescriptor descriptor)

Parameters

descriptor QueryDescriptor

The query descriptor to invalidate.

Remarks

This method is thread-safe. The next query with this descriptor will recompute matching archetypes.

ResetStatistics()

Clears all statistics.

public void ResetStatistics()