Java中包含()的最快数据结构? [英] Fastest data structure for contains() in Java?

查看:18
本文介绍了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中包含()的最快数据结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆