adt

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2020 License: MIT Imports: 1 Imported by: 2

README

GoDoc Build Status Go Report Card

Package adt implements various abstract data types.

Stack

Stack implements a LIFO stack using a singly-linked list.

Queue

Queue implements a FIFO queue using a doubly-linked list.

DisjointSet

DisjointSet implements a merge-set or union-find data structure.

PriorityQueue

PriorityQueue implements a priority queue using a heap.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DisjointSet

type DisjointSet struct {
	Value interface{}
	// contains filtered or unexported fields
}

DisjointSet is a data structure that tracks a set of elements partitioned into a number of non-overlapping (disjoint) subsets.

func NewDisjointSet

func NewDisjointSet(v interface{}) *DisjointSet

NewDisjointSet returns a disjoint-set initialized to contain only value v.

func Union

func Union(x, y *DisjointSet) *DisjointSet

Union finds thes the representative element of x and y and merges the smaller of the two sets into the other.

func (*DisjointSet) Find

func (d *DisjointSet) Find() *DisjointSet

Find finds the root (or representative element) of disjoint-set d.

type Element

type Element struct {
	Value interface{}
	// contains filtered or unexported fields
}

Element is an element of a queue.

type Frame

type Frame struct {
	Value interface{}
	// contains filtered or unexported fields
}

Frame is an element of a stack.

type PriorityQueue

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

PriorityQueue represents an ordered collection of elements that can be accessed in a priority-first manner. Elements with a higher priority are retrieved before elements with a lower priority.

func NewPriorityQueue

func NewPriorityQueue(n int) *PriorityQueue

NewPriorityQueue returns a priority queue of size n.

func (PriorityQueue) Len

func (pq PriorityQueue) Len() int

Len returns the number of elements in the queue.

func (*PriorityQueue) Pop

func (pq *PriorityQueue) Pop() interface{}

Pop removes the element with the highest priority and returns its value.

func (*PriorityQueue) Push

func (pq *PriorityQueue) Push(v interface{}, p int)

Push inserts a new element e with value v and priority p to the queue.

type Queue

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

Queue represents an ordered collection of elements that can be accessed in a first-in, first-out manner. The zero value for Queue is an empty queue ready to use.

func NewQueue

func NewQueue() *Queue

NewQueue returns an initialized queue.

func (*Queue) Dequeue

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

Dequeue removes and returns the front-most element of queue q.

func (*Queue) Enqueue

func (q *Queue) Enqueue(v interface{}) *Element

Enqueue inserts a new element e with value v to the back of queue q and returns e.

func (*Queue) Len

func (q *Queue) Len() int

Len returns the number of elements in the queue.

type Stack

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

Stack represents an ordered collection of elements that can be accessed in a last-in, first-out manner. The zero value for Stack is an empty stack ready to use.

func NewStack

func NewStack() *Stack

NewStack returns an initalized stack.

func (*Stack) Pop

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

Pop removes and returns the top-most frame of stack s.

func (*Stack) Push

func (s *Stack) Push(v interface{}) *Frame

Push inserts a new frame with value v on the top of stack s and returns f.

func (*Stack) Size

func (s *Stack) Size() int

Size returns the number of frames in the stack.

Jump to

Keyboard shortcuts

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