Last active
October 31, 2020 21:02
-
-
Save joao-r-reis/f1b08711494b8f9e5a1921aad8235932 to your computer and use it in GitHub Desktop.
Insert.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void Insert(TKey key, TValue value, bool add) | |
{ | |
// these 3 variables are fields of the Dictionary | |
// int[] buckets; | |
// Entry[] entries; | |
// IEqualityComparer<TKey> comparer; | |
int hashCode = comparer.GetHashCode(key) & 0x7FFFFFFF; | |
int targetBucket = hashCode % buckets.Length; | |
for (int i = buckets[targetBucket]; i >= 0; i = entries[i].next) | |
{ | |
if (entries[i].hashCode == hashCode && comparer.Equals(entries[i].key, key)) | |
{ | |
if (add) | |
{ | |
ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_AddingDuplicate); | |
} | |
entries[i].value = value; | |
return; | |
} | |
} | |
// removed add logic for simplicity | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment