Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/edwingeng/deque
A highly optimized double-ended queue
https://github.com/edwingeng/deque
array deque dequeue double-ended-queue golang list queue vector
Last synced: 13 days ago
JSON representation
A highly optimized double-ended queue
- Host: GitHub
- URL: https://github.com/edwingeng/deque
- Owner: edwingeng
- License: bsd-3-clause
- Created: 2019-02-01T03:32:28.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-09-14T00:30:28.000Z (about 1 year ago)
- Last Synced: 2024-07-31T20:48:18.725Z (3 months ago)
- Topics: array, deque, dequeue, double-ended-queue, golang, list, queue, vector
- Language: Go
- Homepage:
- Size: 112 KB
- Stars: 178
- Watchers: 5
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - deque - A highly optimized double-ended queue. (Data Structures and Algorithms / Queues)
- awesome-go - deque - A highly optimized double-ended queue. (Data Structures and Algorithms / Queues)
- awesome-go-extra - deque - ended queue|60|2|0|2019-02-01T03:32:28Z|2022-08-25T16:46:53Z| (Generators / Queues)
README
**Please use [v2](v2), the generic version, if you have golang 1.18 or above.**
# Overview
Deque is a highly optimized double-ended queue, which is
much efficient compared with `list.List` when adding or removing elements from
the beginning or the end.# Benchmark
```
PushBack/Deque 100000000 12.0 ns/op 8 B/op 0 allocs/op
PushBack/Deque 20000000 55.5 ns/op 24 B/op 1 allocs/op
PushBack/list.List 5000000 158.7 ns/op 56 B/op 1 allocs/opPushFront/Deque 195840157 9.2 ns/op 8 B/op 0 allocs/op
PushFront/Deque 30000000 49.2 ns/op 24 B/op 1 allocs/op
PushFront/list.List 5000000 159.2 ns/op 56 B/op 1 allocs/opRandom/Deque 65623633 15.1 ns/op 0 B/op 0 allocs/op
Random/Deque 50000000 24.7 ns/op 4 B/op 0 allocs/op
Random/list.List 30000000 46.9 ns/op 28 B/op 1 allocs/op
```# Getting Started
```
go get -u github.com/edwingeng/deque
```# Usage
``` go
dq := deque.NewDeque()
dq.PushBack(100)
dq.PushBack(200)
dq.PushBack(300)
for !dq.Empty() {
fmt.Println(dq.PopFront())
}dq.PushFront(100)
dq.PushFront(200)
dq.PushFront(300)
for i, n := 0, dq.Len(); i < n; i++ {
fmt.Println(dq.PopFront())
}// Output:
// 100
// 200
// 300
// 300
// 200
// 100
```# Harden the element data type
``` bash
./harden.sh [elemType]
```