ListSet (collection.immutable.ListSet) is a inverse ordered set. I need ordered set. This is a example of original ListSet:
var a = ListSet(1,2,3)
var ite = a.iterator
ite.next // returns 3
ite.next // returns 2
ite.next // returns 1
And this is a example of I need:
var a = ListSet(1,2,3)
var ite = a.iterator
ite.next // returns 1
ite.next // returns 2
ite.next // returns 3
UPDATE:
"Ordered" is a "Insertion Ordered" for me. I need this:
var a = ListSet(1,2,3)
a += 5
a += 4
var ite = a.iterator
ite.next // returns 1
ite.next // returns 2
ite.next // returns 3
ite.next // returns 5
ite.next // returns 4
What is an insertion order. An insertion order is a contract between an advertiser or advertising agency and a publisher to run an advertising campaign in print or online.
Insertion order refers to the order in which you are adding elements to the data structure (i.e., a collection like List , Set , Map , etc..). For example, a List object maintains the order in which you are adding elements, whereas a Set object doesn't maintain the order of the elements in which they are inserted.
In scala, ListSet class implements immutable sets using a list-based data structure. Elements are stored in reversed insertion order, That means the newest element is at the head of the list. It maintains insertion order. Listset is used only for a small number of elements.
Unlike lists, ordinary sets do not preserve the order in which we insert the elements. This is because the elements in a set are usually not stored in the order in which they appear.
collection.mutable.LinkedHashSet
is a set that iterates its members in the same sequence they were inserted. (I avoid the term "ordered" here, since I prefer to reserve that to cases of an ordering relation on the values, not the particular sequence in which some actions were carried out.)
var eti = a.toList.reverse.iterator
It is not ordered:
val a = ListSet(3,1,2)
val ite = a.iterator
ite.next // returns 2
ite.next // returns 1
ite.next // returns 3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With