唯一关联哈希图容器与关联哈希图容器的属性是什么

发布于 2024-12-28 01:54:50 字数 559 浏览 0 评论 0原文

注意:有时答案是“作为用户,您不应该担心实现细节”我会在这里指出,这是一个基于我想学习的内容的问题,就像我想实现它一样。

根据SGI

唯一关联容器是具有 容器中的每个键都是唯一的属性:容器中没有两个元素 唯一关联容器具有相同的密钥。

我就明白这么多了。没有进一步解释的是在键唯一和非唯一的情况下数据如何存储(我猜测没有解释的原因是它依赖于实现)。那么,当键唯一时,所有桶的大小都是 1 元素吗?我想不是因为冲突,如果是这样,一旦哈希器确定了存储桶编号,并且如果密钥是唯一的,那么该元素如何存储在存储桶本身中?

当键不唯一时怎么办?元素如何存储然后返回到存储桶或从存储桶返回?

如果其他点与(一般情况下)唯一关联容器关联容器如何存储它们的元素以及它们之间的差异(如果有的话)有关,我也将不胜感激。是任意的)。

NOTE: Sometimes the answers are "as a user you should not worry about implementation details" I will note here that this is a question based on what I want to learn as if I want to implement it.

According to SGI:

A Unique Associative Container is an Associative Container with the
property that each key in the container is unique: no two elements in
a Unique Associative Container have the same key.

That much I understand. What isn't explained further is how the data is stored in the case when the keys are unique and when they are not (I am guessing the reason this is not explained is that it is implementation dependant). So, when the keys are unique, are all buckets 1 element in size? I am thinking not because of collisions, and if so, once the bucket number is determined by the hasher, and if the key is unique, how is the element stored in the bucket itself?

What about when the keys are not unique? How are the elements stored and then returned to/from the buckets?

I would appreciate elaboration on other points as well if they relate to how (in general) an Unique Associative Container and an Associative Container store their elements and differences between them (if there are any).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紙鸢 2025-01-04 01:54:50

键在唯一关联容器中是唯一的。如您链接的页面上所述,如果您插入带有键 k 的某个元素 e,则后续调用具有相同键 k 的 insert() 将不会插入新元素。另请注意,您链接的页面中的 count() 方法返回 UAC​​ 中具有给定键的元素数量,该方法始终返回 0 或 1。

您关于“存储桶”的问题不清楚。容器如何在后端存储数据(例如,哈希映射是否通过链接或其他机制处理冲突)不应该影响您作为用户。

The keys are unique in a Unique Associative Container. As described on the page you linked, if you insert some element e with key k, subsequent calls to insert() with the same key k will not insert new elements. Also note from the page you linked that the count() method, which returns the number of elements in a UAC with a given key, always returns 0 or 1.

Your question about "buckets" is unclear. How the container buckets data on the back end -- whether or not a hash map, for instance, handles collisions by chaining or via another mechanism -- shouldn't affect you as a user.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文