Hallux.OrderedMap (Hallux v1.2.0) View Source
An ordered sequence that is also a hashmap on values.
- Items consist of a value and an order key. Values are hashed.
- The sequence is always sorted by the order, new items are inserted at their order position.
- Values can be retrieved in O(log(n)) if addressed by order key.
- All keys to an item can be retrieved in O(m*log(n)), where m is the number of occurrences of that value. (Currently, hash collisions are not checked.)
Link to this section Summary
Functions
Find all entries with a given value.
Get an ordered map of all values with the given order key.
Insert a value and key.
Return a list of all keys, in order.
(O(1))
. Returns an empty OrderedMap
.
(O(n log(n)))
. Returns an OrderedMap
filled with the list of key-value-pairs.
Split according to the order key.
Return a list of all values, in order of the keys.
Link to this section Functions
Find all entries with a given value.
Examples
iex> my_map = new([b: "yes", a: "no", c: "no", d: "yes", b: "no", e: "no"])
#HalluxOrderedMap<[a: "no", b: "yes", b: "no", c: "no", d: "yes", e: "no"]>
iex> filter_value(my_map, "yes")
#HalluxOrderedMap<[b: "yes", d: "yes"]>
Get an ordered map of all values with the given order key.
## Examples
iex> my_map = new([b: "b1", a: "a", c: "c", b: "b2"])
#HalluxOrderedMap<[a: "a", b: "b1", b: "b2", c: "c"]>
iex> get(my_map, :b)
#HalluxOrderedMap<[b: "b1", b: "b2"]>
Insert a value and key.
Examples
iex> my_map = new([b: "b1", a: "a", c: "c", b: "b2"])
#HalluxOrderedMap<[a: "a", b: "b1", b: "b2", c: "c"]>
iex> insert(my_map, :a, "A")
#HalluxOrderedMap<[a: "a", a: "A", b: "b1", b: "b2", c: "c"]>
Return a list of all keys, in order.
Examples
iex> ordered_map = OrderedMap.new([a: 1, c: 3, b: 2, b: 4])
#HalluxOrderedMap<[a: 1, b: 2, b: 4, c: 3]>
iex> keys(ordered_map)
[:a, :b, :b, :c]
(O(1))
. Returns an empty OrderedMap
.
Examples
iex> new()
#HalluxOrderedMap<[]>
(O(n log(n)))
. Returns an OrderedMap
filled with the list of key-value-pairs.
Examples
iex> new([{1, "hai"}]) |> Enum.to_list()
[{1, "hai"}]
iex> new([{23, 5}, {1, "hai"}, {"something", [:some, :thing]}, {:foo, "foo"}])
#HalluxOrderedMap<[{1, "hai"}, {23, 5}, {:foo, "foo"}, {"something", [:some, :thing]}]>
Split according to the order key.
Examples
iex> my_map = new([b: "b1", a: "a", c: "c", b: "b2"])
#HalluxOrderedMap<[a: "a", b: "b1", b: "b2", c: "c"]>
iex> {a, b, c} = split(my_map, :b)
iex> a
#HalluxOrderedMap<[a: "a"]>
iex> b
#HalluxOrderedMap<[b: "b1", b: "b2"]>
iex> c
#HalluxOrderedMap<[c: "c"]>
Return a list of all values, in order of the keys.
Examples
iex> ordered_map = OrderedMap.new([a: 1, c: 3, b: 2, b: 4])
#HalluxOrderedMap<[a: 1, b: 2, b: 4, c: 3]>
iex> values(ordered_map)
[1, 2, 4, 3]