From abeb668e2dd051a3e49db6c6777a9dc214820ecf Mon Sep 17 00:00:00 2001 From: Tiger Jove Date: Wed, 30 Oct 2024 22:28:59 +0100 Subject: [PATCH] HashSets instead of SortedSets for Archetype lists. --- fennecs/Batch.cs | 2 +- fennecs/Mask.cs | 6 +++--- fennecs/Query.cs | 4 ++-- fennecs/Stream.1.cs | 4 ++-- fennecs/World.cs | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/fennecs/Batch.cs b/fennecs/Batch.cs index 3f71cb6e..3010938f 100644 --- a/fennecs/Batch.cs +++ b/fennecs/Batch.cs @@ -35,7 +35,7 @@ public void Submit() } - internal Batch(SortedSet archetypes, World world, Mask mask, AddConflict addMode, RemoveConflict removeMode) + internal Batch(HashSet archetypes, World world, Mask mask, AddConflict addMode, RemoveConflict removeMode) { _world = world; _mask = mask; diff --git a/fennecs/Mask.cs b/fennecs/Mask.cs index 100330b1..251ab3f4 100644 --- a/fennecs/Mask.cs +++ b/fennecs/Mask.cs @@ -6,9 +6,9 @@ namespace fennecs; internal sealed class Mask : IDisposable { - internal readonly SortedSet HasTypes = []; - internal readonly SortedSet NotTypes = []; - internal readonly SortedSet AnyTypes = []; + internal readonly HashSet HasTypes = []; + internal readonly HashSet NotTypes = []; + internal readonly HashSet AnyTypes = []; public bool SafeForAddition(TypeExpression typeExpression) => typeExpression.Matches(NotTypes); public bool SafeForRemoval(TypeExpression typeExpression) => typeExpression.Matches(HasTypes) || typeExpression.Matches(AnyTypes); diff --git a/fennecs/Query.cs b/fennecs/Query.cs index 788853f1..a0552ad5 100644 --- a/fennecs/Query.cs +++ b/fennecs/Query.cs @@ -95,7 +95,7 @@ internal void ForgetArchetype(Archetype archetype) /// This query's currently matched Archetypes. /// (affected by filters) /// - internal readonly SortedSet Archetypes; + internal readonly HashSet Archetypes; /// /// The World this Query is associated with. @@ -108,7 +108,7 @@ internal void ForgetArchetype(Archetype archetype) /// internal readonly Mask Mask; - internal Query(World world, Mask mask, SortedSet matchingTables) + internal Query(World world, Mask mask,HashSet matchingTables) { Archetypes = matchingTables; World = world; diff --git a/fennecs/Stream.1.cs b/fennecs/Stream.1.cs index 1326b96a..93e1a410 100644 --- a/fennecs/Stream.1.cs +++ b/fennecs/Stream.1.cs @@ -20,7 +20,7 @@ public record Stream(Query Query, Match Match0) : IEnumerable<(Entity, C0)>, /// /// Archetypes, or Archetypes that match the Stream's Subset and Exclude filters. /// - protected SortedSet Filtered => Subset.IsEmpty && Exclude.IsEmpty + protected HashSet Filtered => Subset.IsEmpty && Exclude.IsEmpty ? Archetypes : new(Archetypes.Where(a => (Subset.IsEmpty || a.Signature.Matches(Subset)) && !a.Signature.Matches(Exclude))); @@ -49,7 +49,7 @@ public record Stream(Query Query, Match Match0) : IEnumerable<(Entity, C0)>, /// /// The Archetypes that this Stream is iterating over. /// - protected SortedSet Archetypes => Query.Archetypes; + protected HashSet Archetypes => Query.Archetypes; /// /// The World this Stream is associated with. diff --git a/fennecs/World.cs b/fennecs/World.cs index 9444d4cb..def2b03e 100644 --- a/fennecs/World.cs +++ b/fennecs/World.cs @@ -169,7 +169,7 @@ internal Query CompileQuery(Mask mask) if (_queryCache.TryGetValue(mask.GetHashCode(), out var query)) return query; // Create a new query and cache it. - var matchingTables = new SortedSet(_archetypes.Where(table => table.Matches(mask))); + var matchingTables = new HashSet(_archetypes.Where(table => table.Matches(mask))); query = new(this, mask.Clone(), matchingTables); _queries.Add(query); _queryCache.Add(query.Mask.GetHashCode(), query);