deque: github.com/tebeka/deque Index | Files

package deque

import "github.com/tebeka/deque"

Package deque provides a double ended queue modeled after Python's collections.deque

Example:

import (
	"fmt"

	"github.com/tebeka/deque"
)

func Example() {
	// Create a new deque and put some numbers in it.
	dq := deque.New()
	for i := 0; i < 5; i++ {
		dq.Append(i)
	}

	// Pop from the left
	val, _ := dq.PopLeft()
	fmt.Println(val) // 0

	// Get an item
	val, _ = dq.Get(2)
	fmt.Println(val) // 2

	// Set an item
	dq.Set(2, "hello")

	// Rotate
	dq.Rotate(-2)

	// Print
	fmt.Println(dq)

	// Output:
	// Deque{"hello", 4, 1, 2}
}

Index

Package Files

deque.go doc.go

Constants

const (

    // Version is the package version
    Version = "1.0.0"
)

type Deque Uses

type Deque struct {
    // contains filtered or unexported fields
}

Deque is a double ended queue

func New Uses

func New() *Deque

New returns a new unbounded Deque

func NewBounded Uses

func NewBounded(maxSize int) (*Deque, error)

NewBounded returns a new bounded Deque A bounded Deque will not grow over maxSize items

func (*Deque) Append Uses

func (dq *Deque) Append(item interface{})

Append appends an item to the right of the deque

func (*Deque) AppendLeft Uses

func (dq *Deque) AppendLeft(item interface{})

AppendLeft appends an item to the left of the deque

func (*Deque) Get Uses

func (dq *Deque) Get(i int) (interface{}, error)

Get return the item at position i

func (*Deque) Len Uses

func (dq *Deque) Len() int

Len returns the number of items in the queue

func (*Deque) Pop Uses

func (dq *Deque) Pop() (interface{}, error)

Pop removes and return the rightmost element

func (*Deque) PopLeft Uses

func (dq *Deque) PopLeft() (interface{}, error)

PopLeft removes and return the leftmost element.

func (*Deque) Rotate Uses

func (dq *Deque) Rotate(n int)

Rotate rotates the queue. If n is positive then rotate right n steps, otherwise rotate left -n steps

func (*Deque) Set Uses

func (dq *Deque) Set(i int, val interface{}) error

Set sets the item at position i to val

func (*Deque) String Uses

func (dq *Deque) String() string

Package deque imports 2 packages (graph). Updated 2016-07-16. Refresh now. Tools for package owners.