Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Go
  3. deque

deque

MITGov1.2.1

A fast ring-buffer deque (double-ended queue) implementation in Go with O(1) operations and optimized memory performance.

GitHubGitHub
786 stars67 forks0 contributors

What is deque?

Deque is a Go library that provides a high-performance double-ended queue (deque) data structure using a ring buffer. It efficiently supports both queue (FIFO) and stack (LIFO) operations with constant-time performance, optimized for CPU and garbage collection efficiency.

Target Audience

Go developers who need a memory-efficient and fast deque implementation for scenarios like task scheduling, buffering, or algorithm implementations requiring O(1) operations at both ends.

Value Proposition

Developers choose this over alternatives because it uses a ring buffer that reduces allocations and GC pauses compared to slice or linked-list implementations, offers type safety via Go generics, and provides iterators for efficient traversal and removal.

Overview

Fast ring-buffer deque (double-ended queue)

Use Cases

Best For

  • Implementing high-performance queues (FIFO) with constant-time enqueue and dequeue operations.
  • Building stacks (LIFO) where fast push and pop operations at one end are critical.
  • Applications requiring memory efficiency and minimal garbage collection pauses, such as real-time systems or high-throughput data processing.
  • Scenarios where a double-ended queue is needed for algorithms like breadth-first search or sliding window problems.
  • Go projects using generics for type-safe data structures that integrate with stdlib packages like slices and iter.
  • Optimizing performance in balanced workloads where items frequently move in and out of the deque, leveraging the ring buffer's reuse of space.

Not Ideal For

  • Projects requiring out-of-the-box concurrent access without additional synchronization layers
  • Applications that prefer error returns or default values over panics for empty deque operations
  • Simple scripts or prototypes where Go's built-in slices suffice and deque complexity is unnecessary
  • Use cases needing lock-free data structures without external concurrency management

Pros & Cons

Pros

Ring-Buffer Efficiency

Uses a circular buffer that resizes by powers of two, reducing allocations and GC pauses compared to slice or linked-list implementations, as highlighted in the README for optimal performance.

Constant-Time Operations

Provides O(1) addition and removal at both ends, enabling high-throughput queue and stack operations suitable for real-time systems or algorithm implementations.

Type Safety with Generics

Leverages Go generics for compile-time type checks, allowing deques of any specified type and ensuring type-safe usage without runtime assertions.

Iterator Integration

Includes iterators for traversal and item removal, compatible with Go's stdlib slices and iter packages, facilitating efficient data processing and avoiding intermediate resizes.

Cons

Panic on Empty Read

Panics when reading from an empty deque, forcing explicit length checks and adding boilerplate, which can lead to runtime crashes if not carefully handled in production code.

No Built-in Concurrency Safety

Leaves concurrency safety entirely to the application, requiring external synchronization like mutexes, complicating code in multi-goroutine environments and increasing development overhead.

Configuration-Dependent Performance

Requires tuning of base capacity via SetBaseCap to minimize resizing; improper settings can lead to frequent reallocations, negating performance benefits in unbalanced workloads.

Frequently Asked Questions

Quick Stats

Stars786
Forks67
Contributors0
Open Issues4
Last commit2 months ago
CreatedSince 2018

Tags

#circular-buffer#queue#stack#double-ended-queue#go-library#data-structures#golang#deque#generics#ring-buffer#performance

Built With

G
Go

Included in

Go169.1k
Auto-fetched 6 hours ago

Related Projects

hatchethatchet

🪓 An orchestration engine for background tasks, AI agents, and durable workflows

Stars7,895
Forks492
Last commit11 hours ago
goconcurrentqueuegoconcurrentqueue

Go concurrent-safe, goroutine-safe, thread-safe queue

Stars434
Forks35
Last commit3 years ago
queuequeue

⏪️ Go package providing multiple queue implementations. Developed in a thread-safe generic way.

Stars366
Forks15
Last commit8 days ago
dequedeque

A highly optimized double-ended queue

Stars205
Forks7
Last commit3 years ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub