CopyOnWriteArraySet与HashSet中的插入顺序

huangapple go评论126阅读模式
英文:

Insertion order in CopyOnWriteArraySet VS HashSet

问题

每个人都知道HashSet根据哈希表的大小和元素的哈希码值将元素存储在中。

但是CopyOnWriteArraySet如何存储元素呢?我以为它会对这些桶进行快照并复制它们。看起来似乎并不是这样。它是逐个在一个'普通'数组中存储并检查equals()吗?
它是否甚至使用哈希原理?

英文:

Everyone knows HashSet stores elements in buckets based on the size of the hashtable and the elements' hash code values.

But how does CopyOnWriteArraySet store elements? I thought it makes a snapshot of those buckets and copies them. Looks like it doesn't. Does it store them in 'normal' array 1 by 1 and checks equals()?
Does it even use hashing principle?

答案1

得分: 1

CopyOnWriteArraySetCopyOnWriteArrayListSet包装器,它将元素存储在数组中,因此不使用哈希。这就是为什么它没有HashSet的O(1)查找优势。

文档称它仅适用于小型集合。

英文:

CopyOnWriteArraySet is a Set-wrapper for CopyOnWriteArrayList, which stores its elements in an array, so it does not use hashing. That's why it doesn't have the O(1) lookup benefit of a HashSet.

The docs say it is only suitable for small sets.

huangapple
  • 本文由 发表于 2020年8月22日 20:24:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/63536155.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定