Java中包含()的最快数据结构?
Java 中对 contains() 运算速度最快的数据结构是什么?
What's the data structure in Java that has the fastest operation for contains() ?
例如我有一组数字 { 1, 7, 12, 14, 20... }
e.g. i have a set of numbers { 1, 7, 12, 14, 20... }
给定另一个任意数字 x,生成 x 是否包含在集合中的布尔值的最快方法(平均而言)是什么?!contains() 的概率大约高出 5 倍.
Given another arbitrary number x, what's the fastest way (on average) to generate the boolean value of whether x is contained in the set or not? The probability for !contains() is about 5x higher.
所有的map结构都提供o(1)操作吗?HashSet 是最快的方法吗?
Do all the map structures provide o(1) operation? Is HashSet the fastest way to go?
推荐答案
查看基于集合 (Hashset, enumset) 和哈希 (HashMap,linkedhash...,idnetityhash..) 的实现.他们有 O(1) for contains()
look at set (Hashset, enumset) and hash (HashMap,linkedhash...,idnetityhash..) based implementations. they have O(1) for contains()
这份备忘单很有帮助.
相关文章