fix: Removes broken OrderedHashSet and adds a simple OrderedSet (#1756)
> [!CAUTION] > **BREAKING CHANGE** > Removed `OrderdHashSet` and `PooledOrderedHashSet` due to bugs. > [!NOTE] > **Developer Note** > The OrderedSet is not a full data structure. It is not particularly efficient. Pull Requests are welcome for a better implementation, especially if it ends up supporting `ISet<T>` and `IReadOnlySet<T>` ## Summary The ordered hash set was buggy. It's kind of painful to implement, so for now, I added a simple `OrderedSet` to suffice for gumps. Please reach out if this causes disruption!
This commit is contained in:
parent
dc118d836f
commit
4ea1d79cad
30 changed files with 121 additions and 1258 deletions
|
|
@ -1,46 +0,0 @@
|
|||
using System.Linq;
|
||||
using Server.Collections;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests
|
||||
{
|
||||
public class OrderedHashSetTests
|
||||
{
|
||||
[Fact]
|
||||
public void TestOrderedHashSet()
|
||||
{
|
||||
var set = new OrderedHashSet<string>(1)
|
||||
{
|
||||
"random string1", "another random string1", "another random string2", "another random string3"
|
||||
};
|
||||
set.Remove("another random string1");
|
||||
var list = set.ToList();
|
||||
|
||||
string[] arr = { "random string1", "another random string2", "another random string3" };
|
||||
int i = 0;
|
||||
foreach (var entry in list)
|
||||
{
|
||||
Assert.Equal(entry, arr[i++]);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestOrderedHashWithNull()
|
||||
{
|
||||
var set = new OrderedHashSet<string>(1)
|
||||
{
|
||||
"random string1", null, "another random string2", "another random string3"
|
||||
};
|
||||
|
||||
set.Remove("another random string1");
|
||||
var list = set.ToList();
|
||||
|
||||
string[] arr = { "random string1", null, "another random string2", "another random string3" };
|
||||
int i = 0;
|
||||
foreach (var entry in list)
|
||||
{
|
||||
Assert.Equal(entry, arr[i++]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
29
Projects/Server.Tests/Tests/Collections/OrderedSetTests.cs
Normal file
29
Projects/Server.Tests/Tests/Collections/OrderedSetTests.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
using Server.Collections;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests;
|
||||
|
||||
public class OrderedSetTests
|
||||
{
|
||||
[Fact]
|
||||
public void TestOrderedSet()
|
||||
{
|
||||
int[] expected = [6, 2, 4, 23, 0];
|
||||
var set = new OrderedSet<int>();
|
||||
for (var i = 0; i < expected.Length; i++)
|
||||
{
|
||||
set.Add(expected[i]);
|
||||
}
|
||||
|
||||
Assert.Equal(expected.Length, set.Count);
|
||||
|
||||
Assert.True(set.Contains(4));
|
||||
Assert.False(set.Contains(8));
|
||||
|
||||
int index = 0;
|
||||
foreach (var value in set)
|
||||
{
|
||||
Assert.Equal(expected[index++], value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue