Added more constructors to collections

hashcode getters, equality comparers, also a Span property for IndexedFishSet
This commit is contained in:
bbradson
2024-04-28 20:09:11 +02:00
parent b5cda73ecd
commit 91975828e4
12 changed files with 82 additions and 4 deletions
+24
View File
@@ -149,6 +149,21 @@ public class FishSet<T> : ISet<T>, IReadOnlyCollection<T>, ICollection
Initialize(minimumCapacity);
}
public unsafe FishSet(int minimumCapacity, delegate*<T?, int> hashCodeGetter = default,
delegate*<T?, T?, bool> equalityComparer = default)
{
InitializeDelegates(hashCodeGetter, equalityComparer);
Initialize(minimumCapacity);
}
public unsafe FishSet(int minimumCapacity, T defaultValue, delegate*<T?, int> hashCodeGetter = default,
delegate*<T?, T?, bool> equalityComparer = default)
{
_defaultValue = defaultValue;
InitializeDelegates(hashCodeGetter, equalityComparer);
Initialize(minimumCapacity);
}
[MemberNotNull(nameof(_buckets))]
[MemberNotNull(nameof(_tails))]
private void Initialize(int minimumCapacity = 0)
@@ -163,6 +178,15 @@ public class FishSet<T> : ISet<T>, IReadOnlyCollection<T>, ICollection
_wrapAroundMask = _buckets.Length - 1;
}
private unsafe void InitializeDelegates(delegate*<T?, int> hashCodeGetter, delegate*<T?, T?, bool> equalityComparer)
{
if (hashCodeGetter != default)
_hashCodeGetter = hashCodeGetter;
if (equalityComparer != default)
_equalityComparer = equalityComparer;
}
public FishSet(IEnumerable<T> entries) : this(0)
{
foreach (var entry in entries)