Skip to content

Instantly share code, notes, and snippets.

@joao-r-reis
Last active October 31, 2020 20:59
Show Gist options
  • Save joao-r-reis/0b4ef52cd14852e19985b2a3c9c8cafe to your computer and use it in GitHub Desktop.
Save joao-r-reis/0b4ef52cd14852e19985b2a3c9c8cafe to your computer and use it in GitHub Desktop.
TryAddInternal.cs
private bool TryAddInternal(TKey key, TValue value, bool updateIfExists, bool acquireLock, out TValue resultingValue)
{
IEqualityComparer<TKey> comparer = m_tables.m_comparer;
var hashcode = comparer.GetHashCode(key);
var bucketCount = m_tables.m_buckets.Length;
var bucketNo = (hashcode & 0x7fffffff) % bucketCount;
// removed locking logic for simplicity
for (Node node = tables.m_buckets[bucketNo]; node != null; node = node.m_next)
{
if (comparer.Equals(node.m_key, key))
{
return false;
}
}
// removed add logic for simplicity
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment