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

查看:311
本文介绍了java中最快的数据结构()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组数字{1,7,12,14,20 ...}

e.g. i have a set of numbers { 1, 7, 12, 14, 20... }

给定另一个任意数字x,最快的方式(平均)是生成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.

所有地图结构是否提供o(1)操作? HashSet是最快的方法吗?

Do all the map structures provide o(1) operation? Is HashSet the fastest way to go?

推荐答案

查看set(Hashset,enumset)和hash(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天全站免登陆