1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-18 16:10:26 +02:00

Merge pull request #1762 from disarray2077/patch-9

Add `Remove` method to HashSet Enumerator
This commit is contained in:
Brian Fiete 2022-11-30 14:54:37 -08:00 committed by GitHub
commit 17aafaeb66
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -228,6 +228,51 @@ namespace System.Collections
CopyTo(array, arrayIndex, mCount);
}
private bool RemoveEntry(int32 hashCode, int_cosize index)
{
if (mBuckets != null)
{
int32 bucket = hashCode % (int32)mBuckets.Count;
int32 last = -1;
for (int32 i = mBuckets[bucket] - 1; i >= 0; last = i,i = mSlots[i].mNext)
{
if (i == index)
{
if (last < 0)
{
// first iteration; update buckets
mBuckets[bucket] = mSlots[i].mNext + 1;
}
else
{
// subsequent iterations; update 'next' pointers
mSlots[last].mNext = mSlots[i].mNext;
}
mSlots[i].mHashCode = -1;
mSlots[i].mValue = default(T);
mSlots[i].mNext = mFreeList;
mCount--;
#if VERSION_HASHSET
mVersion++;
#endif
if (mCount == 0)
{
mLastIndex = 0;
mFreeList = -1;
}
else
{
mFreeList = i;
}
return true;
}
}
}
// either m_buckets is null or wasn't found
return false;
}
bool Remove(T item, T* outValue)
{
if (mBuckets != null)
@ -1231,6 +1276,16 @@ namespace System.Collections
}
}
public void Remove() mut
{
int_cosize curIdx = mIndex - 1;
mSet.RemoveEntry(mSet.mSlots[curIdx].mHashCode, curIdx);
#if VERSION_HASHSET
mVersion = mSet.mVersion;
#endif
mIndex = curIdx;
}
public void Reset() mut
{
#if VERSION_HASHSET