gpt4 book ai didi

c++ - unordered_map 如何处理负元素?

转载 作者:行者123 更新时间:2023-11-30 00:42:46 24 4
gpt4 key购买 nike

我可以将负元素指定为 map 中的键,例如 map[-1]=10; 它在后面如何处理它,它使用什么数据结构?我知道 unordered_map 在内部使用散列,它如何处理散列的负元素?如果我使用数组进行哈希运算,我无法对负元素进行哈希运算,因为数组索引不能为负数

最佳答案

Unordered map is an associative container that contains key-value pairs with unique keys. Search, insertion, and removal of elements have average constant-time complexity.

Internally, the elements are not sorted in any particular order, but organized into buckets. Which bucket an element is placed into depends entirely on the hash of its key. This allows fast access to individual elements, since once the hash is computed, it refers to the exact bucket the element is placed into.

unordered_map使用散列来访问元素。只要定义了哈希函数,对负整数或任何其他类型进行哈希处理就没有问题。

关于c++ - unordered_map<int,int> 如何处理负元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58297359/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com