forked from bit/DotRecastNetSim
added WangHash for DtNodePool
This commit is contained in:
parent
94ed3d646c
commit
2d3ca5b321
|
@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||
|
||||
### Added
|
||||
- Added DtNodePool tests
|
||||
- Added WangHash() for DtNodePool
|
||||
- Added avg, min, max, sampling updated times in CrowdAgentProfilingTool
|
||||
|
||||
### Fixed
|
||||
|
|
|
@ -1,10 +1,26 @@
|
|||
namespace DotRecast.Core
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace DotRecast.Core
|
||||
{
|
||||
public static class RcHashCodes
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int CombineHashCodes(int h1, int h2)
|
||||
{
|
||||
return (((h1 << 5) + h1) ^ h2);
|
||||
}
|
||||
|
||||
// From Thomas Wang, https://gist.github.com/badboy/6267743
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static uint WangHash(uint a)
|
||||
{
|
||||
a = (~a) + (a << 18); // a = (a << 18) - a - 1;
|
||||
a = a ^ (a >> 31);
|
||||
a = a * 21; // a = (a + (a << 2)) + (a << 4);
|
||||
a = a ^ (a >> 11);
|
||||
a = a + (a << 6);
|
||||
a = a ^ (a >> 22);
|
||||
return (uint)a;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -24,11 +24,13 @@ namespace DotRecast.Detour
|
|||
{
|
||||
public class DtNodePool
|
||||
{
|
||||
private readonly Dictionary<long, List<DtNode>> m_map = new Dictionary<long, List<DtNode>>();
|
||||
private readonly List<DtNode> m_nodes = new List<DtNode>();
|
||||
private readonly Dictionary<long, List<DtNode>> m_map;
|
||||
private readonly List<DtNode> m_nodes;
|
||||
|
||||
public DtNodePool()
|
||||
{
|
||||
m_map = new Dictionary<long, List<DtNode>>();
|
||||
m_nodes = new List<DtNode>();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
using NUnit.Framework;
|
||||
|
||||
namespace DotRecast.Core.Test;
|
||||
|
||||
public class RcHashCodesTest
|
||||
{
|
||||
[Test]
|
||||
public void TestCombineHashCodes()
|
||||
{
|
||||
Assert.That(RcHashCodes.CombineHashCodes(0, 0), Is.EqualTo(0));
|
||||
Assert.That(RcHashCodes.CombineHashCodes(int.MaxValue, int.MaxValue), Is.EqualTo(32));
|
||||
Assert.That(RcHashCodes.CombineHashCodes(int.MaxValue, int.MinValue), Is.EqualTo(-33));
|
||||
Assert.That(RcHashCodes.CombineHashCodes(int.MinValue, int.MinValue), Is.EqualTo(0));
|
||||
Assert.That(RcHashCodes.CombineHashCodes(int.MinValue, int.MaxValue), Is.EqualTo(-1));
|
||||
Assert.That(RcHashCodes.CombineHashCodes(int.MaxValue / 2, int.MaxValue / 2), Is.EqualTo(32));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestIntHash()
|
||||
{
|
||||
Assert.That(RcHashCodes.WangHash(0), Is.EqualTo(4158654902));
|
||||
Assert.That(RcHashCodes.WangHash(1), Is.EqualTo(357654460));
|
||||
Assert.That(RcHashCodes.WangHash(2), Is.EqualTo(715307540));
|
||||
Assert.That(RcHashCodes.WangHash(3), Is.EqualTo(1072960876));
|
||||
|
||||
Assert.That(RcHashCodes.WangHash(4), Is.EqualTo(1430614333));
|
||||
Assert.That(RcHashCodes.WangHash(5), Is.EqualTo(1788267159));
|
||||
Assert.That(RcHashCodes.WangHash(6), Is.EqualTo(2145921005));
|
||||
Assert.That(RcHashCodes.WangHash(7), Is.EqualTo(2503556531));
|
||||
|
||||
Assert.That(RcHashCodes.WangHash(8), Is.EqualTo(2861226262));
|
||||
Assert.That(RcHashCodes.WangHash(9), Is.EqualTo(3218863982));
|
||||
Assert.That(RcHashCodes.WangHash(10), Is.EqualTo(3576533554));
|
||||
Assert.That(RcHashCodes.WangHash(11), Is.EqualTo(3934169234));
|
||||
|
||||
//
|
||||
Assert.That(RcHashCodes.WangHash(int.MaxValue), Is.EqualTo(1755403298));
|
||||
Assert.That(RcHashCodes.WangHash(uint.MaxValue), Is.EqualTo(3971045735));
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@ using NUnit.Framework;
|
|||
|
||||
namespace DotRecast.Core.Test;
|
||||
|
||||
public class Vector3Tests
|
||||
public class Vector3Test
|
||||
{
|
||||
[Test]
|
||||
[Repeat(100000)]
|
Loading…
Reference in New Issue