Reputation: 1745
I have some code like this:
Table = ets:new(table, [bag]),
true = ets:insert(Table, {bucket_1, some_value_1}),
true = ets:insert(Table, {bucket_1, some_value_2}),
true = ets:insert(Table, {bucket_1, some_value_3}),
LookupResult = ets:lookup(Table, bucket_1),
?_assertEqual(
[{bucket_1, some_value_1}, {bucket_1, some_value_2}, {bucket_1, some_value_3}],
LookupResult
).
Is ETS guarantees ordering of elements within bucket? Should I expect, that ETS saves order of elements, as elements has been added to table?
Upvotes: 3
Views: 852
Reputation: 1080
The specification of lookup/2
says:
[...] the time order of object insertions is preserved; the first object inserted with the given key will be first in the resulting list, and so on.
Upvotes: 5