Skip to content

Commit

Permalink
add index docs
Browse files Browse the repository at this point in the history
  • Loading branch information
friflo committed Dec 1, 2024
1 parent 724d36d commit 38781f6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ECS/Index/ComponentIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
// ReSharper disable once CheckNamespace
namespace Friflo.Engine.ECS;

/// <summary>
/// The index for <see cref="IIndexedComponent{TValue}"/> struct's to search entities with a specific component value in O(1).
/// </summary>
public readonly struct ComponentIndex <TIndexedComponent,TValue>
where TIndexedComponent : struct, IIndexedComponent<TValue>
{
Expand Down
4 changes: 4 additions & 0 deletions src/ECS/Index/LinkComponentIndex.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using System.Collections.Generic;
using Friflo.Engine.ECS.Index;
// ReSharper disable UnusedTypeParameter

// ReSharper disable once CheckNamespace
namespace Friflo.Engine.ECS;

/// <summary>
/// The index for <see cref="ILinkComponent"/> struct's to search entities with a specific entity in O(1).
/// </summary>
public readonly struct LinkComponentIndex <TLinkComponent>
where TLinkComponent: struct, ILinkComponent
{
Expand Down
1 change: 1 addition & 0 deletions src/Tests/ECS/Index/Test_Index.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public static void Test_Index_indexed_Entity()
entity2.AddComponent(new LinkComponent { entity = target5 }); AreEqual(2, values.Count);
entity3.AddComponent(new LinkComponent { entity = target5 }); AreEqual(2, values.Count);

AreEqual("Count: 2", index.ToString());
AreEqual(1, index[target4].Count);
AreEqual(2, index[target5].Count);

Expand Down
1 change: 1 addition & 0 deletions src/Tests/ECS/Index/Test_IndexedComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public static void Test_IndexedComponent_EntityExtension_Add()
entity.Add(new IndexedInt { value = 30 });
AreEqual(1, index[30].Count);
AreEqual(1, index.Values.Count);
AreEqual("Count: 1", index.ToString());

entity.Add(new IndexedInt { value = 31 });
AreEqual(1, index.Values.Count);
Expand Down

0 comments on commit 38781f6

Please sign in to comment.