Documentation
¶
Overview ¶
Package deque implements a double ended queue supporting arbitrary types (even a mixture).
Internally it uses a dynamically growing circular slice of blocks, resulting in faster resizes than a simple dynamic array/slice would allow, yet less gc overhead.
Example (Usage) ¶
Simple usage example that inserts the numbers 0, 1, 2 into a deque and then removes them one by one, varying the removal side.
package main import ( "fmt" "gopkg.in/karalabe/cookiejar.v1/collections/deque" ) func main() { // Create a deque an push some data in d := deque.New() for i := 0; i < 3; i++ { d.PushLeft(i) } // Pop out the deque contents and display them fmt.Println(d.PopLeft()) fmt.Println(d.PopRight()) fmt.Println(d.PopLeft()) }
Output: 2 0 1
Index ¶
- type Deque
- func (d *Deque) Empty() bool
- func (d *Deque) Left() interface{}
- func (d *Deque) PopLeft() (res interface{})
- func (d *Deque) PopRight() (res interface{})
- func (d *Deque) PushLeft(data interface{})
- func (d *Deque) PushRight(data interface{})
- func (d *Deque) Reset()
- func (d *Deque) Right() interface{}
- func (d *Deque) Size() int
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Deque ¶
type Deque struct {
// contains filtered or unexported fields
}
Double ended queue data structure.
func (*Deque) Left ¶
func (d *Deque) Left() interface{}
Returns the leftmost element from the deque. No bounds are checked.
func (*Deque) PopLeft ¶
func (d *Deque) PopLeft() (res interface{})
Pops out an element from the queue from the left. Note, no bounds checking are done.
func (*Deque) PopRight ¶
func (d *Deque) PopRight() (res interface{})
Pops out an element from the queue from the right. Note, no bounds checking are done.
func (*Deque) PushLeft ¶
func (d *Deque) PushLeft(data interface{})
Pushes a new element into the queue from the left, expanding it if necessary.
func (*Deque) PushRight ¶
func (d *Deque) PushRight(data interface{})
Pushes a new element into the queue from the right, expanding it if necessary.