OrderedCollections (ordered_collections v0.3.0)
OrderedCollections provides sorted data structures for Elixir,
including a SortedMap
and (eventually) a SortedSet
.
Modules
OrderedCollections.SortedMap
- A sorted key-value store implemented using Erlang's:gb_trees
.OrderedCollections.SortedSet
- A sorted set implemented using Erlang's:gb_sets
.
Examples
iex> sm = OrderedCollections.SortedMap.new(%{b: 2, a: 1})
iex> OrderedCollections.SortedMap.get(sm, :a)
1
You can also use convenience functions:
iex> sm = OrderedCollections.new_map(%{x: 10})
iex> sm = OrderedCollections.put_map(sm, :y, 20)
iex> OrderedCollections.get_map(sm, :y)
20
Summary
Functions
Retrieves the value for the given key from a SortedMap, returning a default if the key is missing.
Creates a new empty SortedMap.
Creates a new SortedMap from a regular map.
Inserts a key-value pair into a SortedMap.
Creates a map from a SortedMap.
Functions
@spec get_map(OrderedCollections.SortedMap.t(), any(), any()) :: any()
Retrieves the value for the given key from a SortedMap, returning a default if the key is missing.
@spec new_map() :: OrderedCollections.SortedMap.t()
Creates a new empty SortedMap.
Examples
iex> sm = OrderedCollections.new_map() iex> OrderedCollections.to_map(sm) %{}
@spec new_map(map()) :: OrderedCollections.SortedMap.t()
Creates a new SortedMap from a regular map.
Examples
iex> m = %{b: 2, a: 1} iex> sm = OrderedCollections.new_map(m) iex> OrderedCollections.get_map(sm, :a) 1
@spec put_map(OrderedCollections.SortedMap.t(), any(), any()) :: OrderedCollections.SortedMap.t()
Inserts a key-value pair into a SortedMap.
@spec to_map(OrderedCollections.SortedMap.t()) :: map()
Creates a map from a SortedMap.
Examples
iex> sm = OrderedCollections.new_map(%{b: 2, a: 1}) iex> OrderedCollections.to_map(sm) %{a: 1, b: 2}