go-util: github.com/vaelen/go-util/collections Index | Files

package collections

import "github.com/vaelen/go-util/collections"

Index

Package Files

collections.go fifoqueue.go heap.go linkedlist.go stack.go template.go

type Collection Uses

type Collection interface {
    // Size returns the number of items in the list
    Size() int
}

A Collection is a collection of items with no guaranteed order

type FIFOQueue Uses

type FIFOQueue LinkedList

A FIFOQueue is a first-in-first-out queue. It is implemented as a doubly linked list. It implements the Queue interface.

func (*FIFOQueue) Iterator Uses

func (l *FIFOQueue) Iterator() Iterator

Iterator returns an iterator that doesn't modify the queue.

func (*FIFOQueue) Pop Uses

func (l *FIFOQueue) Pop() interface{}

Pop removes an item from the front of the queue.

func (*FIFOQueue) Push Uses

func (l *FIFOQueue) Push(value interface{})

Push adds an item to the back of the queue.

func (*FIFOQueue) Size Uses

func (l *FIFOQueue) Size() int

Size returns the number of items in the queue.

type Heap Uses

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

Heap represents a Minimum Heap. Heap can be used as a priority queue.

func NewHeap Uses

func NewHeap(comp sort.Comparator) *Heap

NewHeap constructs an empty heap.

func NewHeapFromSlice Uses

func NewHeapFromSlice(list []interface{}, comp sort.Comparator) *Heap

NewHeapFromSlice constructs a new heap from the given slice. It creates a copy of the slice so that the original slice is not affected.

func (*Heap) Add Uses

func (h *Heap) Add(value interface{})

Add adds a new item to the heap

func (*Heap) Pop Uses

func (h *Heap) Pop() interface{}

Pop removes a value from the queue by calling Remove()

func (*Heap) Push Uses

func (h *Heap) Push(value interface{})

Push adds a value to the queue by calling Add()

func (*Heap) Remove Uses

func (h *Heap) Remove() interface{}

Remove returns the first item from the heap

func (*Heap) Size Uses

func (h *Heap) Size() int

Size returns the number of items in the heap

type Iterable Uses

type Iterable interface {
    // Iterator returns an iterator that does not modify the list
    Iterator() Iterator
}

An Iterable is a collection that can be iterated over

type IterableQueue Uses

type IterableQueue interface {
    Queue
    Iterable
}

An IterableQueue is an iterable queue

type Iterator Uses

type Iterator interface {
    // HasNext returns true if there are more items to iterate over.
    HasNext() bool
    // Next returns the next value in the iterator.
    // It returns nil if the iterator has reached the end of the
    // collection.
    Next() interface{}
}

An Iterator iterates through the values in a collection

type LinkedList Uses

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

LinkedList implements a doubly linked list. Items can be removed or added from the start or end in constant time. Items can be iterated over either forward or backward in linear time.

func (*LinkedList) AddFirst Uses

func (l *LinkedList) AddFirst(value interface{})

AddFirst adds an item to the start of the list.

func (*LinkedList) AddLast Uses

func (l *LinkedList) AddLast(value interface{})

AddLast adds an item to the end of the list.

func (*LinkedList) ForwardIterator Uses

func (l *LinkedList) ForwardIterator() ListIterator

ForwardIterator returns an iterator that iterates over the items in the list from first to last

func (*LinkedList) Iterator Uses

func (l *LinkedList) Iterator() Iterator

Iterator returns an iterator that iterates over the items in the list from first to last without changing the list.

func (*LinkedList) RemoveFirst Uses

func (l *LinkedList) RemoveFirst() interface{}

RemoveFirst removes an item from the start of the list.

func (*LinkedList) RemoveLast Uses

func (l *LinkedList) RemoveLast() interface{}

RemoveLast removes an item from the end of the list.

func (*LinkedList) ReverseIterator Uses

func (l *LinkedList) ReverseIterator() ListIterator

ReverseIterator returns an iterator that iterates over the items in the list from last to first

func (*LinkedList) Size Uses

func (l *LinkedList) Size() int

Size returns the number of items in the list

type List Uses

type List interface {
    Collection
    Iterable
}

A List is an iterable collection

type ListIterator Uses

type ListIterator interface {
    Iterator
    // HasPrevious returns true if there are previous items to
    // iterate over.
    HasPrevious() bool
    // Previous returns the previous value from the iterator.
    // It returns nil if the iterator has reached the start of the
    // collection.
    Previous() interface{}
}

A ListIterator is an ordered iterator. It can iterate forwards and backwards as well as modify the list.

type Queue Uses

type Queue interface {
    Collection
    // Push adds an item to the queue
    Push(value interface{})
    // Pop removes an item from the queue
    Pop() interface{}
}

A Queue is a type of list where new items are always added and removed in a specific order.

type Stack Uses

type Stack LinkedList

A Stack is a FILO queue. It is implemented as a double linked list.

func (*Stack) Iterator Uses

func (l *Stack) Iterator() Iterator

Iterator returns an Iterator that doesn't modify the stack

func (*Stack) Pop Uses

func (l *Stack) Pop() interface{}

Pop removes the top item of the stack

func (*Stack) Push Uses

func (l *Stack) Push(value interface{})

Push adds an item to the top of the stack

func (*Stack) Size Uses

func (l *Stack) Size() int

Size returns the number of items on the stack.

Package collections imports 1 packages (graph). Updated 2019-11-13. Refresh now. Tools for package owners.