This commit is contained in:
Andrew Gillis 2018-04-24 17:51:08 -04:00
parent 822a94c81c
commit 61131f5ce5
2 changed files with 12 additions and 8 deletions

View file

@ -7,7 +7,7 @@
Extremely fast ring-buffer deque ([double-ended queue](https://en.wikipedia.org/wiki/Double-ended_queue)) implementation.
[![GoDoc](https://godoc.org/github.com/gammazero/deque?status.png)](https://godoc.org/github.com/gammazero/deque)
[![GoDoc](https://godoc.org/github.com/gammazero/deque?status.svg)](https://godoc.org/github.com/gammazero/deque)
This deque implementation is optimized for CPU and GC performance. The circular buffer automatically re-sizes by powers of two, growing when additional capacity is needed and shrinking when only a quarter of the capacity is used, and uses bitwise arithmetic for all calculations.

View file

@ -1,13 +1,15 @@
/*
Package deque provides a fast, ring-buffer deque (double-ended queue) that
automatically re-sizes by powers of two. This allows bitwise arithmetic for
all calculations. The ring-buffer implementation significantly improves memory
and time performance with fewer GC pauses, compared to implementations based on
slices and linked lists.
Package deque provides a fast ring-buffer deque (double-ended queue)
implementation. The ring-buffer automatically re-sizes by powers of two,
growing when additional capacity is needed and shrinking when only a quarter of
the capacity is used, and uses bitwise arithmetic for all calculations.
The ring-buffer implementation significantly improves memory and time
performance with fewer GC pauses, compared to implementations based on slices
and linked lists.
For maximum speed, this deque implementation leaves concurrency safety up to
the application to provide, however is best for the application if needed at
all.
the application to provide, however the application chooses, if needed at all.
Queue (FIFO) operations are supported using PushBack() and PopFront(). Stack
(LIFO) operations are supported using PushBack() and PopBack().
@ -139,6 +141,8 @@ func (q *Deque) PeekAt(i int) interface{} {
}
// Clear removes all elements from the queue, but retains the current capacity.
// The queue will not be resized smaller as long as items are only added.
// Only when items are removed is the queue subject to getting resized smaller.
func (q *Deque) Clear() {
// bitwise modulus
mbits := len(q.buf) - 1