C# 数据结构 - Dictionary
1. Dictionary底层实现是使用 数组+单项链表,具体数据结构为
private int[] buckets;//hashcode 桶,始终指向当前桶的最后一个元素(Entry next 为-1)
private Entry[] entries;//所有存入的数据
其中Entry结构如下:
private struct Entry {
public int hashCode; // hashcode
public int next; // 下一个元素在enties中的索引
public TKey key; // Key
public TValue value; // Value
}
entries保存了所有添加进入的key:value元素
2. Dictionary的初始化过程
public Dictionary(int capacity, IEqualityComparer<TKey> comparer) {
if (capacity < 0) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.capacity);
if (capacity > 0) Initialize(capacity);
this.comparer = comparer ?? EqualityComparer<