ETS 设置保留顺序?
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 技术交流群。

不,对于表类型
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.