哈希表的 size 是指桶(bucket)的数量还是 k-v 对的数量呢?

2020-10-28 09:50:56 +08:00
 zxCoder
 /**
         * Gets the size of the hash table
         * @return current size of the hash table
         */
        size_t GetSize();

英语比较差,不知道这个是表达什么意思

907 次点击
所在节点    问与答
6 条回复
kilasuelika
2020-10-28 09:54:18 +08:00
一般是 k-v 对
mazyi
2020-10-28 10:08:21 +08:00
看源码
zxCoder
2020-10-28 10:18:39 +08:00
@mazyi hhh 这是一个 project,源码要我自己写
Procumbens
2020-10-28 10:22:58 +08:00
C++
size(): Return container size - Returns the number of elements in the unordered_map container.

Java
size(): Returns the number of key-value mappings in this map.
icyalala
2020-10-28 10:50:45 +08:00
一般来说 size 就是 k-v pair 的数量,capacity 指 bucket 数量。
mazyi
2020-10-28 11:31:53 +08:00
@zxCoder 那就更好了,看别的语言的实现

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/719277

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX