C#??Dictionary????????????
???????????? ???????[ 2015/8/6 10:28:35 ] ??????????????????? ????????
???????Dictionary???????????????List?????????????????????????????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?????????????????????£?
????????????this.buckets = new int[prime]
????????????this.entries = new Entry<TKey?? TValue>[prime]
????Bucket??entries?????????????????????????С??????
????????this.buckets???????????Hash?????this.entries?????洢????????????????????????λ?á?
??????????Dictionary<int??string> ????????????Dictionary??????????
???????????????????:
????Dictionary<int?? string> test = new Dictionary<int?? string>(6);
???????????
????????????????????Bucket??entries??仯
????Test.Add(4??”4″)??
????????Hash???? 4.GetHashCode()%7= 4??????????buckets???±??4?????????????Count?0???????????Entries?е?0????????????Count???1
????Test.Add(11??”11″)
????????Hash?? 11.GetHashCode()%7=4?????????????Buckets???±??4??????????????????????-1?????Count=1??????????????????entries???±??1???????У???????Buckets??????±??1??entries?У??±??1??entry????±??0??entries??
????Test.Add(18??”18″)
???????????18????HashCode????????Buckets???±??4?????????????????????count+1??λ???????Bucket?????????????????Next???Entries???±??1??????????????????hashcode??????????γ????????????????????????????????????????????????????
????Test.Add(19??”19″)
?????????????19?????Hash???????????????????????????????count+1??λ?á?
????????????????????仯
????Test.Remove(4)
???????????????????????????????????????????3?Σ????key?4??????????λ??????????????????FreeList??λ?????????????λ???FreeCount???1
????Test.Remove(18)
???????Key?18???????????????????????????????????2?Σ???????????????????????????FreeList???????????????Next????????FreeList????
????????????FreeList????????????????????治?????κ?????FreeCount??????????????????????
????Test.Add(20??”20″)
???????????????????????FreeList????????????????????????FreeList??????????λ???????FreeCount??1??FreeList?????????1
???????
??????????????飬??????????Dictionary??????????????????·??????У?
???????Hash??????????????Bucket????????????Bucket?????????????γ??????????
??????????Entries???е??????????????????
???????????????γ????FreeList????????????????????????FreeList??????????????FreeList???????count????????
??????????????Ч?????????????????????????????Dictionary????????
?????e????????????д???????????????????????????£?????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11