Java设置并包含 [英] Java set and contains

查看:83
本文介绍了Java设置并包含的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了声明:

HashSet为基本操作(添加,删除,包含和调整大小)提供恒定的时间性能.

HashSet offers constant time performance for the basic operations (add, remove, contains and size).

这里包含"正确吗? 虽然将存储桶入围是一项持久的性能-是否可以通过o(n)操作在存储桶中查找元素?

Is 'contains' true here? While shortlisting the bucket is a contant-time performance - isnt finding the elements within the bucket a o(n) operation?

我误会了吗?

推荐答案

n代表哈希中的元素数量,而不是存储桶中的元素数量.而且由于存储分区中的元素数量不会随集合的大小线性增长且受到限制,因此可能需要一个恒定的最大时间.并且恒定时间不会影响该表示法.至少如果您具有完善的哈希函数,这是另一个问题.

n in o(n) stands for the number of elements in the hash, not in the bucket. and since the number of elements inside the bucket doesn't grow linearly with the size of the set and is limited, there is a constant maximum time it may take. and constant times don't affect the notation. at least if you have a perfect hashing function, which is another problem altogether.

这篇关于Java设置并包含的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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