Skip to content

Commit

Permalink
HashSets instead of SortedSets for Archetype lists.
Browse files Browse the repository at this point in the history
  • Loading branch information
thygrrr committed Oct 30, 2024
1 parent 9c4d70e commit abeb668
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion fennecs/Batch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void Submit()
}


internal Batch(SortedSet<Archetype> archetypes, World world, Mask mask, AddConflict addMode, RemoveConflict removeMode)
internal Batch(HashSet<Archetype> archetypes, World world, Mask mask, AddConflict addMode, RemoveConflict removeMode)
{
_world = world;
_mask = mask;
Expand Down
6 changes: 3 additions & 3 deletions fennecs/Mask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace fennecs;

internal sealed class Mask : IDisposable
{
internal readonly SortedSet<TypeExpression> HasTypes = [];
internal readonly SortedSet<TypeExpression> NotTypes = [];
internal readonly SortedSet<TypeExpression> AnyTypes = [];
internal readonly HashSet<TypeExpression> HasTypes = [];
internal readonly HashSet<TypeExpression> NotTypes = [];
internal readonly HashSet<TypeExpression> AnyTypes = [];

public bool SafeForAddition(TypeExpression typeExpression) => typeExpression.Matches(NotTypes);
public bool SafeForRemoval(TypeExpression typeExpression) => typeExpression.Matches(HasTypes) || typeExpression.Matches(AnyTypes);
Expand Down
4 changes: 2 additions & 2 deletions fennecs/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ internal void ForgetArchetype(Archetype archetype)
/// This query's currently matched Archetypes.
/// (affected by filters)
/// </summary>
internal readonly SortedSet<Archetype> Archetypes;
internal readonly HashSet<Archetype> Archetypes;

/// <summary>
/// The World this Query is associated with.
Expand All @@ -108,7 +108,7 @@ internal void ForgetArchetype(Archetype archetype)
/// </summary>
internal readonly Mask Mask;

internal Query(World world, Mask mask, SortedSet<Archetype> matchingTables)
internal Query(World world, Mask mask,HashSet<Archetype> matchingTables)
{
Archetypes = matchingTables;
World = world;
Expand Down
4 changes: 2 additions & 2 deletions fennecs/Stream.1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public record Stream<C0>(Query Query, Match Match0) : IEnumerable<(Entity, C0)>,
/// <summary>
/// Archetypes, or Archetypes that match the Stream's Subset and Exclude filters.
/// </summary>
protected SortedSet<Archetype> Filtered => Subset.IsEmpty && Exclude.IsEmpty
protected HashSet<Archetype> Filtered => Subset.IsEmpty && Exclude.IsEmpty
? Archetypes
: new(Archetypes.Where(a => (Subset.IsEmpty || a.Signature.Matches(Subset)) && !a.Signature.Matches(Exclude)));

Expand Down Expand Up @@ -49,7 +49,7 @@ public record Stream<C0>(Query Query, Match Match0) : IEnumerable<(Entity, C0)>,
/// <summary>
/// The Archetypes that this Stream is iterating over.
/// </summary>
protected SortedSet<Archetype> Archetypes => Query.Archetypes;
protected HashSet<Archetype> Archetypes => Query.Archetypes;

/// <summary>
/// The World this Stream is associated with.
Expand Down
2 changes: 1 addition & 1 deletion fennecs/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Archetype>(_archetypes.Where(table => table.Matches(mask)));
var matchingTables = new HashSet<Archetype>(_archetypes.Where(table => table.Matches(mask)));
query = new(this, mask.Clone(), matchingTables);
_queries.Add(query);
_queryCache.Add(query.Mask.GetHashCode(), query);
Expand Down

0 comments on commit abeb668

Please sign in to comment.