zoukankan      html  css  js  c++  java
  • .NET面试题系列(十二)Dictionary原理

    序言

    Dictionary的构造

    下面的代码我看看Dictionary在构造时都做了什么:

    private void Initialize(int capacity)
            {
                int prime = HashHelpers.GetPrime(capacity);
                this.buckets = new int[prime];
                for (int i = 0; i < this.buckets.Length; i++)
                {
                    this.buckets[i] = -1;
                }
                this.entries = new Entry<TKey, TValue>[prime];
                this.freeList = -1;
            }

    我们看到,Dictionary在构造的时候做了以下几件事:

    1. 初始化一个this.buckets = new int[prime]

    2. 初始化一个this.entries = new Entry<TKey, TValue>[prime]

    3. Bucket和entries的容量都为大于字典容量的一个最小的质数

    其中this.buckets主要用来进行Hash碰撞this.entries用来存储字典的内容,并且标识下一个元素的位置

    hash冲突怎么办?

    资料

    https://www.cnblogs.com/InCerry/p/10325290.html

    https://blog.csdn.net/zhaoguanghui2012/article/details/88105715

  • 相关阅读:
    Java并发初识
    go交叉编译
    MRC与ARC混合开发配置
    Hibernate配置文件
    LEFT JOIN重复数据
    Ext.ViewPort布局
    Hibernate学习映射文件
    AjaxMethod方法
    DataBinder
    subsonic 获取记录数量
  • 原文地址:https://www.cnblogs.com/cnki/p/9407964.html
Copyright © 2011-2022 走看看