@@ -6,11 +6,77 @@ This package implements associative containers that preserve the order of insert
66- OrderedSet
77- LittleDict
88
9- ## Contents
109
11- ``` @contents
12- Pages = [
13- "index.md",
14- "ordered_containers.md",
15- ]
10+ ## OrderedSets
11+
12+ ` OrderedSets ` are sets whose entries have a particular order.
13+ Order refers to * insertion order* , which allows deterministic
14+ iteration over the set:
15+
16+ ``` julia
17+ using Base. MathConstants
18+ s = OrderedSet ((π,e,γ,catalan,φ))
19+ for x in s
20+ println (x)
21+ end
22+ # > π = 3.1415926535897...
23+ # > ℯ = 2.7182818284590...
24+ # > γ = 0.5772156649015...
25+ # > catalan = 0.9159655941772...
26+ # > φ = 1.6180339887498...
27+ ```
28+ All ` Set ` operations are available for OrderedSets.
29+
30+ Note that to create an OrderedSet of a particular type, you must
31+ specify the type in curly-braces:
32+
33+ ``` julia
34+ # create an OrderedSet of Strings
35+ strs = OrderedSet {AbstractString} ()
36+ ```
37+
38+ ## OrderedDicts
39+ Similarly, ` OrderedDict ` are simply dictionaries whose entries have a particular
40+ order.
41+ ``` julia
42+ d = OrderedDict {Char,Int} ()
43+ for c in ' a' :' d'
44+ d[c] = c- ' a' + 1
45+ end
46+ for x in d
47+ println (x)
48+ end
49+ # > 'a' => 1
50+ # > 'b' => 2
51+ # > 'c' => 3
52+ # > 'd' => 4
53+ ```
54+ The insertion order is conserved when iterating on the dictionary itself,
55+ its keys (through ` keys(d) ` ), or its values (through ` values(d) ` ).
56+ All standard ` Associative ` and ` Dict ` functions are available for ` OrderedDicts `
57+
58+ ## LittleDict
59+ ``` julia
60+ d = LittleDict {Char,Int} ()
61+ for c in ' a' :' d'
62+ d[c] = c- ' a' + 1
63+ end
64+ for x in d
65+ println (x)
66+ end
67+ # > 'a' => 1
68+ # > 'b' => 2
69+ # > 'c' => 3
70+ # > 'd' => 4
71+ ```
72+ The ` LittleDict ` acts similarly to the ` OrderedDict ` .
73+ However for small collections it is much faster.
74+ Indeed the preceeding example (with the io redirected to ` devnull ` ), runs 4x faster in the ` LittleDict ` version as the earlier ` OrderedDict ` version.
75+
76+ ``` @docs
77+ OrderedDict
78+ OrderedSet
79+ LittleDict
80+ freeze
81+ OrderedCollections.isordered
1682```
0 commit comments