Git Product home page Git Product logo

gostructures's Introduction

GoStructures

Build Status

Building Classic Data Structures in Go

Stack

A Stack implemented as a linked list

stack := NewStack()
stack.Push(23)

value, err := stack.Pop()
assert(value == 23)

value, err = stack.Pop()
assert(err == errors.New("empty stack"))

MultiStack

A Stack of Stacks that resizes

// with a maxlength of 64 for each stack
stack := NewMultiStack(64)
stack.Push(23)

value, err := stack.Pop()
assert(value == 23)

Queue

A FIFO Queue implemented as a linked list

queue := NewQueue()
queue.Push(21)
queue.Push(42)

value, err := queue.Pop()
assert(value == 21)

value, err = queue.Pop()
assert(value == 42)

value, err = queue.Pop()
assert(err == errors.New("empty queue"))

BitVector

A BitVector stores as a list of 64 bit ints

vec := NewBitVector(100)

vec.Add(7)
vec.Add(23)
vec.Add(64)
vec.Add(99)

assert(vec.Contains(23))
assert(!vec.Contains(77))

MaxHeap

A tree structure that always keeps the max value at the top

heap := NewMaxHeap()
heap.Push(7)
heap.Push(23)

assert(heap.Max() == 23)

heap.Pop()
assert(heap.Max() == 7)

Graph

A directional Graph implemented with a vertex list with adjency list for each vertex

graph := NewGraph()
graph.AddVertex("a")
graph.AddVertex("b")
graph.AddVertex("c")

graph.AddEdge("a", "b")
graph.AddEdge("a", "c")

assert(GraphConnected(&graph, "a", "b"))
assert(!GraphConnected(&graph, "b", "c"))

Trie

A trie implemented as a tree

trie := NewTrie()
trie.AddWord("test")

assert(trie.ContainsWord("test"))
assert(!trie.ContainsWord("tes"))

assert(trie.WordsWithPrefix("tes") == []string{"test"})

gostructures's People

Contributors

matthewrudy avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

wade-welles

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.