queue

package
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: 4

Documentation

Overview

Package queue implements a FIFO (first in first out) data structure 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.

Example (Usage)

Simple usage example that inserts the numbers 0, 1, 2 into a queue and then removes them one by one, printing them to the standard output.

package main

import (
	"fmt"

	"gopkg.in/karalabe/cookiejar.v2/collections/queue"
)

func main() {
	// Create a queue an push some data in
	q := queue.New()
	for i := 0; i < 3; i++ {
		q.Push(i)
	}
	// Pop out the queue contents and display them
	for !q.Empty() {
		fmt.Println(q.Pop())
	}
}
Output:

0
1
2

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

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

First in, first out data structure.

func New

func New() *Queue

Creates a new, empty queue.

func (*Queue) Empty

func (q *Queue) Empty() bool

Checks whether the queue is empty.

func (*Queue) Front

func (q *Queue) Front() interface{}

Returns the first element in the queue. Note, no bounds checking are done.

func (*Queue) Pop

func (q *Queue) Pop() (res interface{})

Pops out an element from the queue. Note, no bounds checking are done.

func (*Queue) Push

func (q *Queue) Push(data interface{})

Pushes a new element into the queue, expanding it if necessary.

func (*Queue) Reset

func (q *Queue) Reset()

Clears out the contents of the queue.

func (*Queue) Size

func (q *Queue) Size() int

Returns the number of elements in the queue.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL