使用替代比较器时,在哈希集查找中维护O(1)吗? [英] O(1) maintained in hashset lookups when using alternative comparator?

查看:192
本文介绍了使用替代比较器时,在哈希集查找中维护O(1)吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我为System.Collections.Generic中的通用HashSet<T>定义了自己的比较器,并且其运行时为O(1),则哈希集的查找时间是否仍为O(1)?

If I define my own comparator for the generic HashSet<T> in System.Collections.Generic, and its runtime is O(1), is the lookup time of the hashset still O(1)?

我想不只是因为似乎没有一种设置比较器的方法.

I would think no just because there doesn't appear to be a way to set the comparator.

推荐答案

常规哈希集的查找时间为O(1)的原因是,它使用开放式寻址将对象放置到数组中,因此不会即使您使用自己的比较器也要更改.

The reason that the lookup time of a regular hashset is O(1) is because it uses open addressing to place objects into the array, so that won't change even if you use your own comparator.

这篇关于使用替代比较器时,在哈希集查找中维护O(1)吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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