ETS 设置保留顺序?

发布于 12-14 13:51 字数 185 浏览 5 评论 0原文

ETS 集是否保证元组的内部顺序与其插入顺序相同?例如:我通过每秒插入一个元组来保留日志,时间戳是关键。在此示例中,set 是否保证元组按键排序?

我知道ordered_set会做我希望的事情,但它有插入开销。因此,如果 set 保持插入顺序,那么在我的示例中使用 set 会更有效。那么,是吗? :-)

提前致谢, 尼古拉

Does ETS set guarantee that internal order of tuples is the same as the order by which they were inserted? For instance: I keep a log by inserting a tuple every second, timestamp is the key. In this example, does set guarantee that tuples are sorted by the key?

I understand that ordered_set would do what I wish, but it has a insert overhead. So if set keeps the insert order, then using set would be much more efficient in my example. So, does it? :-)

Thanks in advance,
Nikola

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

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

发布评论

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

评论(2

冷︶言冷语的世界2024-12-21 13:51:55

不,对于表类型 set 来说,根本无法保证键的排序顺序。它们被散列,然后散列值用于将元素放入表中。该表有时会调整大小并重新排序,因此顺序会发生变化。所以不,你只是幸运而已。

No, for table type set there are no guarantees at all of what order the keys are sorted. They are hashed and then the hash value is used to put the elements in a table. The table is occasionally resized and resorted as well so the order will change. So no, you were just lucky.

勿忘初心2024-12-21 13:51:55

即使 ETS set 确实满足您今天的假设,也不能保证它在未来会继续这样做 - 特别是当存在 ordered_set 时 具有您需要的确切属性。

Even if the ETS set does fulfill your assumption today, there is no guarantee that it would continue to do so in the future -- especially when there is an ordered_set that has the exact property you need.

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