Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ETS set preserving order?

Tags:

erlang

ets

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

like image 434
dijxtra Avatar asked Aug 02 '26 10:08

dijxtra


1 Answers

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.

like image 95
rvirding Avatar answered Aug 04 '26 09:08

rvirding



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!