C#常用集合的时间复杂度

C# 字典、集合、列表的时间复杂度 - 你也很优秀 - 博客园 (cnblogs.com)

 Dictionary查找Key的源码

private int FindEntry(TKey key) {
            if( key == null) {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
            }
 
            if (buckets != null) {
                int hashCode = comparer.GetHashCode(key) & 0x7FFFFFFF;
                for (int i = buckets[hashCode % buckets.Length]; i >= 0; i = entries[i].next) {
                    if (entries[i].hashCode == hashCode && comparer.Equals(entries[i].key, key)) return i;
                }
            }
            return -1;
        }

 

posted @ 2023-03-31 13:32  vba是最好的语言  阅读(35)  评论(0编辑  收藏  举报