deque

package
Version: v2.0.0-...-8dcd6a7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2015 License: BSD-2-Clause Imports: 0 Imported by: 1

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.v2/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

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 New

func New() *Deque

Creates a new, empty deque.

func (*Deque) Empty

func (d *Deque) Empty() bool

Checks whether the queue is empty.

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.

func (*Deque) Reset

func (d *Deque) Reset()

Clears out the contents of the queue.

func (*Deque) Right

func (d *Deque) Right() interface{}

Returns the rightmost element from the deque. No bounds are checked.

func (*Deque) Size

func (d *Deque) Size() int

Returns the number of elements in the queue.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL