https://github.com/discord/deque
Fast bounded deque using two rotating lists.
https://github.com/discord/deque
datastructures elixir
Last synced: about 2 months ago
JSON representation
Fast bounded deque using two rotating lists.
- Host: GitHub
- URL: https://github.com/discord/deque
- Owner: discord
- License: mit
- Created: 2017-02-15T21:00:12.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2023-05-31T02:35:12.000Z (over 2 years ago)
- Last Synced: 2025-01-28T12:56:19.289Z (12 months ago)
- Topics: datastructures, elixir
- Language: Elixir
- Homepage:
- Size: 11.7 KB
- Stars: 153
- Watchers: 176
- Forks: 18
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Deque
[](https://travis-ci.org/discordapp/deque)
[](https://hex.pm/packages/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
- Bounded size
- `Enumerable` protocol
- `Collectable` protocol
- `Inspect` protocol
## Usage
Add it to `mix.exs`
```elixir
defp deps do
[{:deque, "~> 1.0"}]
end
```
Then use it like other Elixir data structures.
```elixir
# 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
Deque is released under [the MIT License](LICENSE).
Check [LICENSE](LICENSE) file for more information.