Created
August 21, 2012 06:52
-
-
Save droyad/3412797 to your computer and use it in GitHub Desktop.
This file contains 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 struct Entry | |
{ | |
public int hashCode; | |
public int next; | |
public TKey key; | |
public TValue value; | |
} | |
private Dictionary<TKey, TValue>.Entry[] entries; | |
private int[] buckets; | |
public bool TryGetValue(TKey key, out TValue value) | |
{ | |
int entry = this.FindEntry(key); | |
if (entry >= 0) | |
{ | |
value = this.entries[entry].value; | |
return true; | |
} | |
else | |
{ | |
value = default (TValue); | |
return false; | |
} | |
} | |
private int FindEntry(TKey key) | |
{ | |
if ((object) key == null) | |
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key); | |
if (this.buckets != null) | |
{ | |
int num = this.comparer.GetHashCode(key) & int.MaxValue; | |
for (int index = this.buckets[num % this.buckets.Length]; index >= 0; index = this.entries[index].next) | |
{ | |
if (this.entries[index].hashCode == num && this.comparer.Equals(this.entries[index].key, key)) | |
return index; | |
} | |
} | |
return -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment