datastructure

package
v0.0.0-...-d7cfe2f Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2018 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

In progress

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BFSPath

type BFSPath struct {
	Source int
	DistTo map[int]int
	EdgeTo map[int]int
	Path   Queue
	G      *Graph
}

func NewBFSPath

func NewBFSPath(g *Graph, source int) *BFSPath

func (*BFSPath) BFS

func (b *BFSPath) BFS() <-chan interface{}

func (*BFSPath) HasPathTo

func (b *BFSPath) HasPathTo(v int) bool

func (*BFSPath) PathTo

func (b *BFSPath) PathTo(v int) <-chan interface{}

PathTo return a the shortest path between the vertice and the source.

type BNode

type BNode struct {
	Key   int
	Value int
	Left  *BNode
	Right *BNode
	Count int
	Level int
}

func NewBNode

func NewBNode(key, val, count int) *BNode

type Bag

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

func NewBag

func NewBag() *Bag

func (*Bag) Add

func (b *Bag) Add(i int)

func (*Bag) IsEmpty

func (b *Bag) IsEmpty(i int) bool

func (*Bag) Iterate

func (b *Bag) Iterate() <-chan int

func (*Bag) Size

func (b *Bag) Size() int

type BinaryHeap

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

func NewBinaryHeap

func NewBinaryHeap(capacity int) *BinaryHeap

func (*BinaryHeap) Add

func (b *BinaryHeap) Add(node int)

Add add node at the end, them swim it up At most 1 + lgN compares

func (*BinaryHeap) DeleteMax

func (b *BinaryHeap) DeleteMax()

DeleteMax exchanges root with node at end, them sink it down At most 2lnN compares

func (*BinaryHeap) Empty

func (b *BinaryHeap) Empty() bool

func (*BinaryHeap) Print

func (b *BinaryHeap) Print()

type ConnectedComponent

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

A connected component is a maximal set of connected vertices.

func NewConnectedComponent

func NewConnectedComponent(g *Graph) *ConnectedComponent

NewConnectedComponent preprocess the graph to find connected components in G

func (*ConnectedComponent) Connected

func (c *ConnectedComponent) Connected(v, w int) bool

Connected returns if v an w are connected.

func (*ConnectedComponent) Count

func (c *ConnectedComponent) Count() int

Count returns the number of connected components

func (*ConnectedComponent) Display

func (c *ConnectedComponent) Display()

func (*ConnectedComponent) GetID

func (c *ConnectedComponent) GetID(v int) int

getID returns the componenent identifier for v

type DFSPath

type DFSPath struct {
	Source int
	Marked map[int]bool
	Adj    map[int]int
	G      *Graph
}

func NewDFSPath

func NewDFSPath(g *Graph, source int) *DFSPath

func (*DFSPath) HasPathTo

func (g *DFSPath) HasPathTo(v int) bool

func (*DFSPath) PathTo

func (g *DFSPath) PathTo(v int) <-chan interface{}

PathTo return a path between the vertice and the source

func (*DFSPath) Print

func (g *DFSPath) Print()

type Graph

type Graph struct {
	Adjacencies map[int]*Bag
}

func NewGraph

func NewGraph() *Graph

New Graph creates an empty Graph with v vertices

func (*Graph) AddEdge

func (g *Graph) AddEdge(v, w int)

AddEdge add an edge v-w

func (*Graph) Adj

func (g *Graph) Adj(v int) <-chan int

Adj returns vertices adjacent to v

func (*Graph) Degree

func (g *Graph) Degree(v int) int

Degree computes the degree

func (*Graph) MaxDegree

func (g *Graph) MaxDegree() int

MaxDegree computes the max degree

func (*Graph) NbEdges

func (g *Graph) NbEdges() int

NbEdges returns the number of edges

func (*Graph) NbVertices

func (g *Graph) NbVertices() int

NbVertices returns the nunber of vertices

func (*Graph) NumberOfSelfLoops

func (g *Graph) NumberOfSelfLoops() int

NumberOfSelfLoops returns the number of Self loops

func (*Graph) String

func (g *Graph) String() string

String returns the string representation of the Graph

type HNode

type HNode struct {
	Key   string
	Value string
	Next  *HNode
}

type Hash

type Hash interface {
	Get(key string) string
	Put(key, value string)
}

func NewHashLinearProbing

func NewHashLinearProbing() Hash

func NewHashSeperateChaining

func NewHashSeperateChaining() Hash

type Node

type Node struct {
	Next  *Node
	Value interface{}
}

type Queue

type Queue interface {
	Enqueue(obj interface{})
	Dequeue() interface{}
	IsEmpty() bool
	Size() int
	Iterate() <-chan interface{}
}

func NewQueueLinkedList

func NewQueueLinkedList() Queue

type SimpleIterator

type SimpleIterator struct {
	Length int
	// contains filtered or unexported fields
}

SimpleIterator is a simple struct to illustrate an implementation of an iterator

func NewSimpleIterator

func NewSimpleIterator() *SimpleIterator

NewSimpleIterator initialize a new SimpleIterator

func (*SimpleIterator) Names

func (s *SimpleIterator) Names() <-chan string

Names return an Iterator by using a chanel

type Stack

type Stack interface {
	Push(item interface{})
	Pop() interface{}
	IsEmpty() bool
	Size() int
	Iterate() <-chan interface{}
}

func NewStackArray

func NewStackArray() Stack

func NewStackLinkedList

func NewStackLinkedList() Stack

type TNode

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

type TRNode

type TRNode struct {
	Key  interface{}
	Next []*TRNode
}

type TTNode

type TTNode struct {
	Key    string
	Value  interface{}
	Left   *TTNode
	Right  *TTNode
	Middle *TTNode
}

type Tree

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

A Tree is a simple binaray tree

func (*Tree) BFS

func (t *Tree) BFS() <-chan int

BFS traverses the tree in the level order

func (*Tree) DFS

func (t *Tree) DFS() <-chan int

DFS traverse the tree in pre-order

func (*Tree) DisplayBFS

func (t *Tree) DisplayBFS()

func (*Tree) InOrder

func (t *Tree) InOrder() <-chan int

InOrder traverse the tree in in-order

func (*Tree) PostOrder

func (t *Tree) PostOrder() <-chan int

PostOrder traverse the tree in post-order

type Trie

type Trie interface {
	Put(key string, val interface{})
	Get(key string) interface{}
}

func NewTrieRWay

func NewTrieRWay(size int) Trie

func NewTrieTernary

func NewTrieTernary() Trie

type TrieRWay

type TrieRWay struct {
	N    int
	Root *TRNode
}

func (*TrieRWay) Get

func (t *TrieRWay) Get(key string) interface{}

func (*TrieRWay) Put

func (t *TrieRWay) Put(key string, val interface{})

type Trie_Ternary

type Trie_Ternary struct {
	Root *TTNode
}

func (*Trie_Ternary) Get

func (t *Trie_Ternary) Get(key string) interface{}

func (*Trie_Ternary) Put

func (t *Trie_Ternary) Put(key string, val interface{})

Jump to

Keyboard shortcuts

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