LinkedMapSet (LinkedMapSet v0.1.0) View Source
A LinkedMapSet
is an extension to MapSet
that keeps pointers to previous
and next elements based on add order.
Link to this section Summary
Functions
Adds an item to the linked map, or moves an existing one to tail.
Adds a new item to the linked map, unless it already exists.
Adds a new item to the linked map, or raises if value
already exists.
Returns whether the given value
exists in the given linked_map_set
.
Create a new LinkedMapSet
Remove an item from the linked map if it exists.
Removes an item from the linked map, or raises if it doesn't exist.
Returns the number of items in the linked_map_set
.
Returns the values as a List
in order.
Link to this section Types
Specs
Link to this section Functions
Specs
Adds an item to the linked map, or moves an existing one to tail.
Returns the updated LinkedMapSet
.
Examples
iex> LinkedMapSet.new() |> LinkedMapSet.add("foo")
iex> LinkedMapSet.new |> LinkedMapSet.add("foo") |> LinkedMapSet.add("bar")
%LinkedMapSet{
head: "foo",
items: %{
"bar" => %Node{next: nil, previous: "foo", value: "bar"},
"foo" => %Node{next: "bar", previous: nil, value: "foo"}
},
tail: "bar"
}
Specs
Adds a new item to the linked map, unless it already exists.
Returns the updated LinkedMapSet
.
Examples
iex> LinkedMapSet.new() |> LinkedMapSet.add("a") |> LinkedMapSet.add_new("a")
%LinkedMapSet{
head: "a",
items: %{
"a" => %Node{next: nil, previous: nil, value: "a"}
},
tail: "a"
}
Specs
Adds a new item to the linked map, or raises if value
already exists.
Returns the updated LinkedMapSet
or raises if value
already exists.
Behaves the same as add_new/2
but raises if value
already exists.
Examples
iex> LinkedMapSet.new() |> LinkedMapSet.add("a") |> LinkedMapSet.add_new!("a")
** (LinkedMapSet.DuplicateValueError) value "a" is already present
Specs
Returns whether the given value
exists in the given linked_map_set
.
Examples
iex> LinkedMapSet.new() |> LinkedMapSet.add("a") |> LinkedMapSet.member?("a")
true
iex> LinkedMapSet.new() |> LinkedMapSet.add("a") |> LinkedMapSet.member?("b")
false
Specs
new() :: t()
Create a new LinkedMapSet
Returns a new empty LinkedMapSet
.
Examples
iex> LinkedMapSet.new()
%LinkedMapSet{head: nil, items: %{}, tail: nil}
Specs
Remove an item from the linked map if it exists.
Returns the updated LinkedMapSet
.
Examples
iex> linked_map_set = LinkedMapSet.new |> LinkedMapSet.add("a") |> LinkedMapSet.add("b") |> LinkedMapSet.add("c")
%LinkedMapSet{
head: "a",
items: %{
"a" => %Node{next: "b", previous: nil, value: "a"},
"b" => %Node{next: "c", previous: "a", value: "b"},
"c" => %Node{next: nil, previous: "b", value: "c"}
},
tail: "c"
}
iex> LinkedMapSet.remove(linked_map_set, "b")
%LinkedMapSet{
head: "a",
items: %{
"a" => %Node{next: "c", previous: nil, value: "a"},
"c" => %Node{next: nil, previous: "a", value: "c"}
},
tail: "c"
}
Specs
Removes an item from the linked map, or raises if it doesn't exist.
Returns the updated LinkedMapSet
, or raises if value
doesn't exist.
Behavies the same as remove/2
, but raises if value
doesn't exist.
Examples
iex> LinkedMapSet.new() |> LinkedMapSet.add("a") |> LinkedMapSet.remove!("b")
** (LinkedMapSet.MissingValueError) value "b" is not present
Specs
size(t()) :: non_neg_integer()
Returns the number of items in the linked_map_set
.
Examples
iex> LinkedMapSet.new() |> LinkedMapSet.add("a") |> LinkedMapSet.size()
1
Specs
Returns the values as a List
in order.
Examples
iex> LinkedMapSet.new() |> LinkedMapSet.add("a") |> LinkedMapSet.add("b") |> LinkedMapSet.to_list()