OrderedDict
is similar to a dictionary. However, unlike a dictionary, it maintains the insertion order of its entries. All the operations that can be performed in the dictionary can also be performed in the OrderedDict
.
Here is a sample code for using the OrderedDict
in Julia:
using DataStructures# Create a new OrderedDict objectdict = OrderedDict{Char,Int}()dict['a'] = 1;dict['b'] = 2;dict['c'] = 3;dict['d'] = 4;println(dict);
OrderedDict
object with the name dict
. dict
object.dict
. Notice how the entries of the dict
are printed in their order of insertion.The OrderedSet
is similar to a set. However, unlike a set, it maintains the insertion order of its elements. All the operations that can be performed in a set can also be performed in the OrderedSet
.
Here is a sample code for using the OrderedSet
in Julia:
using DataStructures# Create a new OrderedSet objectset = OrderedSet{Int}()push!(set,1)push!(set,2)push!(set,10)push!(set,3)println(set);
OrderedSet
object with the name set
. set
object using the push!
method.set
. Notice how the elements of the set
are printed in their order of insertion.