fix(core): Adds ability to store null value in ordered hash set (#447)

- [X] Adds the ability to store a null value in an ordered hash set

TODO:
Optimized the OrderedHashSet. See this:
* https://github.com/dotnet/runtime/issues/10050
Looks like the OrderedDictionary that I based this structure from was not updated.
See the source for diffing:
https://github.com/dotnet/runtime/blob/master/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/HashSet.cs

Difference between a HashSet and an OrderedHashSet is updating the indexes of the entries after fixing the chain to preserve insertion order.
This commit is contained in:
Kamron Batman 2021-02-03 17:57:03 -08:00 • committed by GitHub
parent 3664149422
commit 995149ad01
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 75 additions and 21 deletions

View file

@ -9,7 +9,10 @@ namespace Server.Tests
[Fact]
public void TestOrderedHashSet()
{
var set = new OrderedHashSet<string>(1) { "random string1", "another random string1", "another random string2", "another random string3" };
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();
@ -20,5 +23,24 @@ namespace Server.Tests
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++]);
}
}
}
}