deque_int

package
v0.0.0-...-4c8ddd0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2022 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package deque_int implements an efficient double ended queue to store integers. An iterator is provided with which forward and backward iteration through the deque is possible.

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
}

Deque is a double ended queue that can handle items of any type.

func New

func New() *Deque

New returns a pointer to an empty deque.

func (*Deque) Back

func (d *Deque) Back() *Iterator

Back returns an iterator positioned at the back of the deque, or nil if the deque is empty.

func (*Deque) BackItem

func (d *Deque) BackItem() int

BackItem returns the item at the back of the deque. Returns the zero value when the deque is empty.

func (*Deque) Clear

func (d *Deque) Clear()

Clear removes all items from the deque.

func (*Deque) Front

func (d *Deque) Front() *Iterator

Front returns an iterator positioned at the front of the deque, or nil if the deque is empty.

func (*Deque) FrontItem

func (d *Deque) FrontItem() int

FrontItem returns the item at the front of the deque. Returns the zero value when the deque is empty.

func (*Deque) PopBack

func (d *Deque) PopBack() int

PopBack removes and returns the item from the back of the deque. Returns the zero value when the deque is empty.

func (*Deque) PopFront

func (d *Deque) PopFront() int

PopFront removes and returns the item from the front of the deque. Returns the zero value when the deque is empty.

func (*Deque) PushBack

func (d *Deque) PushBack(item int)

PushBack adds an item to the back of the deque.

func (*Deque) PushFront

func (d *Deque) PushFront(item int)

PushFront adds an item to the front of the deque.

func (*Deque) Size

func (d *Deque) Size() int

Size returns the number of items in the deque.

type Iterator

type Iterator struct {
	Value int
	// contains filtered or unexported fields
}

Iterator points to a deque item and can be used to iterate through the deque.

Example
package main

import (
	"fmt"

	"github.com/notnot/container/deque_int"
)

func main() {
	const N = 10
	deque := deque_int.New()
	for i := 0; i < N; i++ {
		deque.PushBack(i)
	}

	// iterate from front to back
	for it := deque.Front(); it != nil; it = it.Next() {
		fmt.Printf("%v", it.Value)
	}
	fmt.Println()

	// iterate from back to front
	for it := deque.Back(); it != nil; it = it.Prev() {
		fmt.Printf("%v", it.Value)
	}
	fmt.Println()

}
Output:

0123456789
9876543210

func (*Iterator) Next

func (it *Iterator) Next() *Iterator

Next returns an iterator that points to the next deque element, or nil if there is no next element.

func (*Iterator) Prev

func (it *Iterator) Prev() *Iterator

Prev returns an iterator that points to the previous deque element, or nil if there is no previous element.

Jump to

Keyboard shortcuts

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