discord/deque
Fast bounded deque using two rotating lists.
{ "createdAt": "2017-02-15T21:00:12Z", "defaultBranch": "master", "description": "Fast bounded deque using two rotating lists.", "fullName": "discord/deque", "homepage": "", "language": "Elixir", "name": "deque", "pushedAt": "2023-05-31T02:35:12Z", "stargazersCount": 156, "topics": [ "datastructures", "elixir" ], "updatedAt": "2025-11-08T14:59:35Z", "url": "https://github.com/discord/deque"}Erlang only supports fast prepends to lists while appending requires a full copy. Getting the size of a list is also a
O(n) operation. This library implements a deque using two rotating lists to support fast append and prepend as well as
O(1) size via an internal counter.
Features
Section titled “Features”- Bounded size
EnumerableprotocolCollectableprotocolInspectprotocol
Add it to mix.exs
defp deps do [{:deque, "~> 1.0"}]endThen use it like other Elixir data structures.
# Deque<[3, 2, 1]>deque = Deque.new(5) |> Deque.appendleft(1) |> Deque.appendleft(2) |> Deque.appendleft(3)
# Deque<[2, 1]>{3, deque} = Deque.popleft(deque)
# Deque<[6, 7, 8, 9, 10]>Enum.into(0..10, Deque.new(5))License
Section titled “License”Deque is released under [the MIT License]!(LICENSE). Check [LICENSE]!(LICENSE) file for more information.