英文:
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
CopyOnWriteArraySet是CopyOnWriteArrayList的Set包装器,它将元素存储在数组中,因此不使用哈希。这就是为什么它没有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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论