Fastest data structure for contains() in Java?(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()
这份备忘单很有帮助.
这篇关于Java中包含()的最快数据结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Java中包含()的最快数据结构?
基础教程推荐
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- Struts2 URL 无法访问 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
