-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from andreakarasho/advanced-or
Advanced or
- Loading branch information
Showing
10 changed files
with
499 additions
and
350 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
namespace TinyEcs; | ||
|
||
internal static class Hashing | ||
{ | ||
const ulong FIXED = 314159; | ||
|
||
public static ulong Calculate(ReadOnlySpan<ComponentInfo> components) | ||
{ | ||
var hc = (ulong)components.Length; | ||
foreach (ref readonly var val in components) | ||
hc = unchecked(hc * FIXED + val.ID); | ||
return hc; | ||
} | ||
|
||
public static ulong Calculate(ReadOnlySpan<QueryTerm> terms) | ||
{ | ||
var hc = (ulong)terms.Length; | ||
foreach (ref readonly var val in terms) | ||
hc = unchecked(hc * FIXED + (ulong)val.Id + (byte)val.Op + | ||
(val is ContainerQueryTerm container ? container.Terms.Aggregate(0Ul, static (a, b) => a + b.Id.Value) : 0)); | ||
return hc; | ||
} | ||
|
||
public static ulong Calculate(IEnumerable<EcsID> terms) | ||
{ | ||
var hc = (ulong)terms.Count(); | ||
foreach (var val in terms) | ||
hc = unchecked(hc * FIXED + val); | ||
return hc; | ||
} | ||
} |
Oops, something went wrong.