- update documentation, closes #73

pull/87/head
emirpasic 6 years ago
parent 8557a87b9f
commit de5d894737

@ -592,7 +592,7 @@ func main() {
} }
``` ```
Extending the red-black tree's functionality has been demonstrated in the following [example](https://github.com/emirpasic/gods/blob/master/examples/redblacktreeextended.go). Extending the red-black tree's functionality has been demonstrated in the following [example](https://github.com/emirpasic/gods/blob/master/examples/redblacktreeextended/redblacktreeextended.go).
#### AVLTree #### AVLTree

@ -0,0 +1,29 @@
# GoDS (Go Data Structures)
Various examples on how to use data structures.
## Examples
- [ArrayList](https://github.com/emirpasic/gods/blob/master/examples/arraylist/arraylist.go)
- [ArrayStack](https://github.com/emirpasic/gods/blob/master/examples/arraystack/arraystack.go)
- [AVLTree](https://github.com/emirpasic/gods/blob/master/examples/avltree/avltree.go)
- [BinaryHeap](https://github.com/emirpasic/gods/blob/master/examples/binaryheap/binaryheap.go)
- [BTree](https://github.com/emirpasic/gods/blob/master/examples/btree/btree.go)
- [Custom Comparator](https://github.com/emirpasic/gods/blob/master/examples/customcomparator/customcomparator.go)
- [DoublyLinkedList](https://github.com/emirpasic/gods/blob/master/examples/doublylinkedlist/doublylinkedlist.go)
- [EnumerableWithIndex](https://github.com/emirpasic/gods/blob/master/examples/enumerablewithindex/enumerablewithindex.go)
- [EnumerableWithKey](https://github.com/emirpasic/gods/blob/master/examples/enumerablewithkey/enumerablewithkey.go)
- [HashBidiMap](https://github.com/emirpasic/gods/blob/master/examples/hashbidimap/hashbidimap.go)
- [HashMap](https://github.com/emirpasic/gods/blob/master/examples/hashmap/hashmap.go)
- [HashSet](https://github.com/emirpasic/gods/blob/master/examples/hashset/hashset.go)
- [IteratorWithIndex](https://github.com/emirpasic/gods/blob/master/examples/iteratorwithindex/iteratorwithindex.go)
- [iteratorwithkey](https://github.com/emirpasic/gods/blob/master/examples/iteratorwithkey/iteratorwithkey.go)
- [IteratorWithKey](https://github.com/emirpasic/gods/blob/master/examples/linkedliststack/linkedliststack.go)
- [RedBlackTree](https://github.com/emirpasic/gods/blob/master/examples/redblacktree/redblacktree.go)
- [RedBlackTreeExtended](https://github.com/emirpasic/gods/blob/master/examples/redblacktreeextended/redblacktreeextended.go)
- [Serialization](https://github.com/emirpasic/gods/blob/master/examples/serialization/serialization.go)
- [SinglyLinkedList](https://github.com/emirpasic/gods/blob/master/examples/singlylinkedlist/singlylinkedlist.go)
- [Sort](https://github.com/emirpasic/gods/blob/master/examples/sort/sort.go)
- [TreeBidiMap](https://github.com/emirpasic/gods/blob/master/examples/treebidimap/treebidimap.go)
- [TreeMap](https://github.com/emirpasic/gods/blob/master/examples/treemap/treemap.go)
- [TreeSet](https://github.com/emirpasic/gods/blob/master/examples/treeset/treeset.go)

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package examples package main
import ( import (
"github.com/emirpasic/gods/lists/arraylist" "github.com/emirpasic/gods/lists/arraylist"
@ -10,7 +10,7 @@ import (
) )
// ArrayListExample to demonstrate basic usage of ArrayList // ArrayListExample to demonstrate basic usage of ArrayList
func ArrayListExample() { func main() {
list := arraylist.New() list := arraylist.New()
list.Add("a") // ["a"] list.Add("a") // ["a"]
list.Add("c", "b") // ["a","c","b"] list.Add("c", "b") // ["a","c","b"]

@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package examples package main
import "github.com/emirpasic/gods/stacks/arraystack" import "github.com/emirpasic/gods/stacks/arraystack"
// ArrayStackExample to demonstrate basic usage of ArrayStack // ArrayStackExample to demonstrate basic usage of ArrayStack
func ArrayStackExample() { func main() {
stack := arraystack.New() // empty stack := arraystack.New() // empty
stack.Push(1) // 1 stack.Push(1) // 1
stack.Push(2) // 1, 2 stack.Push(2) // 1, 2

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package examples package main
import ( import (
"fmt" "fmt"
@ -10,7 +10,7 @@ import (
) )
// AVLTreeExample to demonstrate basic usage of AVLTree // AVLTreeExample to demonstrate basic usage of AVLTree
func AVLTreeExample() { func main() {
tree := avl.NewWithIntComparator() // empty(keys are of type int) tree := avl.NewWithIntComparator() // empty(keys are of type int)
tree.Put(1, "x") // 1->x tree.Put(1, "x") // 1->x

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package examples package main
import ( import (
"github.com/emirpasic/gods/trees/binaryheap" "github.com/emirpasic/gods/trees/binaryheap"
@ -10,7 +10,7 @@ import (
) )
// BinaryHeapExample to demonstrate basic usage of BinaryHeap // BinaryHeapExample to demonstrate basic usage of BinaryHeap
func BinaryHeapExample() { func main() {
// Min-heap // Min-heap
heap := binaryheap.NewWithIntComparator() // empty (min-heap) heap := binaryheap.NewWithIntComparator() // empty (min-heap)

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package examples package main
import ( import (
"fmt" "fmt"
@ -10,7 +10,7 @@ import (
) )
// BTreeExample to demonstrate basic usage of BTree // BTreeExample to demonstrate basic usage of BTree
func BTreeExample() { func main() {
tree := btree.NewWithIntComparator(3) // empty (keys are of type int) tree := btree.NewWithIntComparator(3) // empty (keys are of type int)
tree.Put(1, "x") // 1->x tree.Put(1, "x") // 1->x

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package examples package main
import ( import (
"fmt" "fmt"
@ -33,7 +33,7 @@ func byID(a, b interface{}) int {
} }
// CustomComparatorExample to demonstrate basic usage of CustomComparator // CustomComparatorExample to demonstrate basic usage of CustomComparator
func CustomComparatorExample() { func main() {
set := treeset.NewWith(byID) set := treeset.NewWith(byID)
set.Add(User{2, "Second"}) set.Add(User{2, "Second"})

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package examples package main
import ( import (
dll "github.com/emirpasic/gods/lists/doublylinkedlist" dll "github.com/emirpasic/gods/lists/doublylinkedlist"
@ -10,7 +10,7 @@ import (
) )
// DoublyLinkedListExample to demonstrate basic usage of DoublyLinkedList // DoublyLinkedListExample to demonstrate basic usage of DoublyLinkedList
func DoublyLinkedListExample() { func main() {
list := dll.New() list := dll.New()
list.Add("a") // ["a"] list.Add("a") // ["a"]
list.Append("b") // ["a","b"] (same as Add()) list.Append("b") // ["a","b"] (same as Add())

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package examples package main
import ( import (
"fmt" "fmt"
@ -18,7 +18,7 @@ func printSet(txt string, set *treeset.Set) {
} }
// EnumerableWithIndexExample to demonstrate basic usage of EnumerableWithIndex // EnumerableWithIndexExample to demonstrate basic usage of EnumerableWithIndex
func EnumerableWithIndexExample() { func main() {
set := treeset.NewWithIntComparator() set := treeset.NewWithIntComparator()
set.Add(2, 3, 4, 2, 5, 6, 7, 8) set.Add(2, 3, 4, 2, 5, 6, 7, 8)
printSet("Initial", set) // [ 2 3 4 5 6 7 8 ] printSet("Initial", set) // [ 2 3 4 5 6 7 8 ]

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package examples package main
import ( import (
"fmt" "fmt"
@ -18,7 +18,7 @@ func printMap(txt string, m *treemap.Map) {
} }
// EunumerableWithKeyExample to demonstrate basic usage of EunumerableWithKey // EunumerableWithKeyExample to demonstrate basic usage of EunumerableWithKey
func EunumerableWithKeyExample() { func main() {
m := treemap.NewWithStringComparator() m := treemap.NewWithStringComparator()
m.Put("g", 7) m.Put("g", 7)
m.Put("f", 6) m.Put("f", 6)

@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package examples package main
import "github.com/emirpasic/gods/maps/hashbidimap" import "github.com/emirpasic/gods/maps/hashbidimap"
// HashBidiMapExample to demonstrate basic usage of HashMap // HashBidiMapExample to demonstrate basic usage of HashMap
func HashBidiMapExample() { func main() {
m := hashbidimap.New() // empty m := hashbidimap.New() // empty
m.Put(1, "x") // 1->x m.Put(1, "x") // 1->x
m.Put(3, "b") // 1->x, 3->b (random order) m.Put(3, "b") // 1->x, 3->b (random order)

@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package examples package main
import "github.com/emirpasic/gods/maps/hashmap" import "github.com/emirpasic/gods/maps/hashmap"
// HashMapExample to demonstrate basic usage of HashMap // HashMapExample to demonstrate basic usage of HashMap
func HashMapExample() { func main() {
m := hashmap.New() // empty m := hashmap.New() // empty
m.Put(1, "x") // 1->x m.Put(1, "x") // 1->x
m.Put(2, "b") // 2->b, 1->x (random order) m.Put(2, "b") // 2->b, 1->x (random order)

@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package examples package main
import "github.com/emirpasic/gods/sets/hashset" import "github.com/emirpasic/gods/sets/hashset"
// HashSetExample to demonstrate basic usage of HashSet // HashSetExample to demonstrate basic usage of HashSet
func HashSetExample() { func main() {
set := hashset.New() // empty (keys are of type int) set := hashset.New() // empty (keys are of type int)
set.Add(1) // 1 set.Add(1) // 1
set.Add(2, 2, 3, 4, 5) // 3, 1, 2, 4, 5 (random order, duplicates ignored) set.Add(2, 2, 3, 4, 5) // 3, 1, 2, 4, 5 (random order, duplicates ignored)

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package examples package main
import ( import (
"fmt" "fmt"
@ -10,7 +10,7 @@ import (
) )
// IteratorWithIndexExample to demonstrate basic usage of IteratorWithIndex // IteratorWithIndexExample to demonstrate basic usage of IteratorWithIndex
func IteratorWithIndexExample() { func main() {
set := treeset.NewWithStringComparator() set := treeset.NewWithStringComparator()
set.Add("a", "b", "c") set.Add("a", "b", "c")
it := set.Iterator() it := set.Iterator()

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package examples package main
import ( import (
"fmt" "fmt"
@ -10,7 +10,7 @@ import (
) )
// IteratorWithKeyExample to demonstrate basic usage of IteratorWithKey // IteratorWithKeyExample to demonstrate basic usage of IteratorWithKey
func IteratorWithKeyExample() { func main() {
m := treemap.NewWithIntComparator() m := treemap.NewWithIntComparator()
m.Put(1, "a") m.Put(1, "a")
m.Put(2, "b") m.Put(2, "b")

@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package examples package main
import lls "github.com/emirpasic/gods/stacks/linkedliststack" import lls "github.com/emirpasic/gods/stacks/linkedliststack"
// LinkedListStackExample to demonstrate basic usage of LinkedListStack // LinkedListStackExample to demonstrate basic usage of LinkedListStack
func LinkedListStackExample() { func main() {
stack := lls.New() // empty stack := lls.New() // empty
stack.Push(1) // 1 stack.Push(1) // 1
stack.Push(2) // 1, 2 stack.Push(2) // 1, 2

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package examples package main
import ( import (
"fmt" "fmt"
@ -10,7 +10,7 @@ import (
) )
// RedBlackTreeExample to demonstrate basic usage of RedBlackTree // RedBlackTreeExample to demonstrate basic usage of RedBlackTree
func RedBlackTreeExample() { func main() {
tree := rbt.NewWithIntComparator() // empty(keys are of type int) tree := rbt.NewWithIntComparator() // empty(keys are of type int)
tree.Put(1, "x") // 1->x tree.Put(1, "x") // 1->x

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package examples package redblacktreeextended
import ( import (
"fmt" "fmt"
@ -81,7 +81,7 @@ func print(tree *RedBlackTreeExtended) {
} }
// RedBlackTreeExtendedExample main method on how to use the custom red-black tree above // RedBlackTreeExtendedExample main method on how to use the custom red-black tree above
func RedBlackTreeExtendedExample() { func main() {
tree := RedBlackTreeExtended{rbt.NewWithIntComparator()} tree := RedBlackTreeExtended{rbt.NewWithIntComparator()}
tree.Put(1, "a") // 1->x (in order) tree.Put(1, "a") // 1->x (in order)

@ -1,4 +1,4 @@
package examples package serialization
import ( import (
"fmt" "fmt"

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package examples package main
import ( import (
sll "github.com/emirpasic/gods/lists/singlylinkedlist" sll "github.com/emirpasic/gods/lists/singlylinkedlist"
@ -10,7 +10,7 @@ import (
) )
// SinglyLinkedListExample to demonstrate basic usage of SinglyLinkedList // SinglyLinkedListExample to demonstrate basic usage of SinglyLinkedList
func SinglyLinkedListExample() { func main() {
list := sll.New() list := sll.New()
list.Add("a") // ["a"] list.Add("a") // ["a"]
list.Append("b") // ["a","b"] (same as Add()) list.Append("b") // ["a","b"] (same as Add())

@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package examples package main
import "github.com/emirpasic/gods/utils" import "github.com/emirpasic/gods/utils"
// SortExample to demonstrate basic usage of basic sort // SortExample to demonstrate basic usage of basic sort
func SortExample() { func main() {
strings := []interface{}{} // [] strings := []interface{}{} // []
strings = append(strings, "d") // ["d"] strings = append(strings, "d") // ["d"]
strings = append(strings, "a") // ["d","a"] strings = append(strings, "a") // ["d","a"]

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package examples package main
import ( import (
"github.com/emirpasic/gods/maps/treebidimap" "github.com/emirpasic/gods/maps/treebidimap"
@ -10,7 +10,7 @@ import (
) )
// TreeBidiMapExample to demonstrate basic usage of TreeBidiMap // TreeBidiMapExample to demonstrate basic usage of TreeBidiMap
func TreeBidiMapExample() { func main() {
m := treebidimap.NewWith(utils.IntComparator, utils.StringComparator) m := treebidimap.NewWith(utils.IntComparator, utils.StringComparator)
m.Put(1, "x") // 1->x m.Put(1, "x") // 1->x
m.Put(3, "b") // 1->x, 3->b (ordered) m.Put(3, "b") // 1->x, 3->b (ordered)

@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package examples package main
import "github.com/emirpasic/gods/maps/treemap" import "github.com/emirpasic/gods/maps/treemap"
// TreeMapExample to demonstrate basic usage of TreeMap // TreeMapExample to demonstrate basic usage of TreeMap
func TreeMapExample() { func main() {
m := treemap.NewWithIntComparator() // empty (keys are of type int) m := treemap.NewWithIntComparator() // empty (keys are of type int)
m.Put(1, "x") // 1->x m.Put(1, "x") // 1->x
m.Put(2, "b") // 1->x, 2->b (in order) m.Put(2, "b") // 1->x, 2->b (in order)

@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package examples package main
import "github.com/emirpasic/gods/sets/treeset" import "github.com/emirpasic/gods/sets/treeset"
// TreeSetExample to demonstrate basic usage of TreeSet // TreeSetExample to demonstrate basic usage of TreeSet
func TreeSetExample() { func main() {
set := treeset.NewWithIntComparator() // empty set := treeset.NewWithIntComparator() // empty
set.Add(1) // 1 set.Add(1) // 1
set.Add(2, 2, 3, 4, 5) // 1, 2, 3, 4, 5 (in order, duplicates ignored) set.Add(2, 2, 3, 4, 5) // 1, 2, 3, 4, 5 (in order, duplicates ignored)
Loading…
Cancel
Save