Why is Dictionary.First() so slow?

前端 未结 5 1101
自闭症患者
自闭症患者 2020-12-11 16:35

Not a real question because I already found out the answer, but still interesting thing.

I always thought that hash table is the fastest associative container if you

5条回答
  •  暖寄归人
    2020-12-11 17:32

    Without looking, the simplest implementation of a sorted dictionary is a sorted list (like TreeSet) of keys and a hash combined; the list gives you the ordering, the dictionary gives you values. Thus the keys are already available. Hashtable does not have keys readily available, thus the culprit is not first, it's keys (all without any shred of evidence, feel free to test the hypothesis ;D )

提交回复
热议问题