From de5d8947371fff34340affe84302558eed019057 Mon Sep 17 00:00:00 2001 From: emirpasic Date: Wed, 19 Sep 2018 05:40:24 +0200 Subject: [PATCH] - update documentation, closes #73 --- README.md | 2 +- examples/README.md | 29 +++++++++++++++++++ examples/{ => arraylist}/arraylist.go | 4 +-- examples/{ => arraystack}/arraystack.go | 4 +-- examples/{ => avltree}/avltree.go | 4 +-- examples/{ => binaryheap}/binaryheap.go | 4 +-- examples/{ => btree}/btree.go | 4 +-- .../customcomparator.go | 4 +-- .../doublylinkedlist.go | 4 +-- .../enumerablewithindex.go | 4 +-- .../enumerablewithkey.go | 4 +-- examples/{ => hashbidimap}/hashbidimap.go | 4 +-- examples/{ => hashmap}/hashmap.go | 4 +-- examples/{ => hashset}/hashset.go | 4 +-- .../iteratorwithindex.go | 4 +-- .../{ => iteratorwithkey}/iteratorwithkey.go | 4 +-- .../{ => linkedliststack}/linkedliststack.go | 4 +-- examples/{ => redblacktree}/redblacktree.go | 4 +-- .../redblacktreeextended.go | 4 +-- examples/{ => serialization}/serialization.go | 2 +- .../singlylinkedlist.go | 4 +-- examples/{ => sort}/sort.go | 4 +-- examples/{ => treebidimap}/treebidimap.go | 4 +-- examples/{ => treemap}/treemap.go | 4 +-- examples/{ => treeset}/treeset.go | 4 +-- 25 files changed, 75 insertions(+), 46 deletions(-) create mode 100644 examples/README.md rename examples/{ => arraylist}/arraylist.go (96%) rename examples/{ => arraystack}/arraystack.go (94%) rename examples/{ => avltree}/avltree.go (96%) rename examples/{ => binaryheap}/binaryheap.go (97%) rename examples/{ => btree}/btree.go (97%) rename examples/{ => customcomparator}/customcomparator.go (94%) rename examples/{ => doublylinkedlist}/doublylinkedlist.go (95%) rename examples/{ => enumerablewithindex}/enumerablewithindex.go (97%) rename examples/{ => enumerablewithkey}/enumerablewithkey.go (97%) rename examples/{ => hashbidimap}/hashbidimap.go (95%) rename examples/{ => hashmap}/hashmap.go (94%) rename examples/{ => hashset}/hashset.go (94%) rename examples/{ => iteratorwithindex}/iteratorwithindex.go (96%) rename examples/{ => iteratorwithkey}/iteratorwithkey.go (96%) rename examples/{ => linkedliststack}/linkedliststack.go (93%) rename examples/{ => redblacktree}/redblacktree.go (96%) rename examples/{ => redblacktreeextended}/redblacktreeextended.go (98%) rename examples/{ => serialization}/serialization.go (98%) rename examples/{ => singlylinkedlist}/singlylinkedlist.go (95%) rename examples/{ => sort}/sort.go (94%) rename examples/{ => treebidimap}/treebidimap.go (95%) rename examples/{ => treemap}/treemap.go (95%) rename examples/{ => treeset}/treeset.go (95%) diff --git a/README.md b/README.md index 1a545fa..cfcdb6c 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..8a1e8ca --- /dev/null +++ b/examples/README.md @@ -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) diff --git a/examples/arraylist.go b/examples/arraylist/arraylist.go similarity index 96% rename from examples/arraylist.go rename to examples/arraylist/arraylist.go index 8e983fa..4d4fbd9 100644 --- a/examples/arraylist.go +++ b/examples/arraylist/arraylist.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package examples +package main import ( "github.com/emirpasic/gods/lists/arraylist" @@ -10,7 +10,7 @@ import ( ) // ArrayListExample to demonstrate basic usage of ArrayList -func ArrayListExample() { +func main() { list := arraylist.New() list.Add("a") // ["a"] list.Add("c", "b") // ["a","c","b"] diff --git a/examples/arraystack.go b/examples/arraystack/arraystack.go similarity index 94% rename from examples/arraystack.go rename to examples/arraystack/arraystack.go index 84c2d89..aa06eaf 100644 --- a/examples/arraystack.go +++ b/examples/arraystack/arraystack.go @@ -2,12 +2,12 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package examples +package main import "github.com/emirpasic/gods/stacks/arraystack" // ArrayStackExample to demonstrate basic usage of ArrayStack -func ArrayStackExample() { +func main() { stack := arraystack.New() // empty stack.Push(1) // 1 stack.Push(2) // 1, 2 diff --git a/examples/avltree.go b/examples/avltree/avltree.go similarity index 96% rename from examples/avltree.go rename to examples/avltree/avltree.go index bd3f96e..b6d1aab 100644 --- a/examples/avltree.go +++ b/examples/avltree/avltree.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package examples +package main import ( "fmt" @@ -10,7 +10,7 @@ import ( ) // AVLTreeExample to demonstrate basic usage of AVLTree -func AVLTreeExample() { +func main() { tree := avl.NewWithIntComparator() // empty(keys are of type int) tree.Put(1, "x") // 1->x diff --git a/examples/binaryheap.go b/examples/binaryheap/binaryheap.go similarity index 97% rename from examples/binaryheap.go rename to examples/binaryheap/binaryheap.go index c56dc27..4bc9381 100644 --- a/examples/binaryheap.go +++ b/examples/binaryheap/binaryheap.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package examples +package main import ( "github.com/emirpasic/gods/trees/binaryheap" @@ -10,7 +10,7 @@ import ( ) // BinaryHeapExample to demonstrate basic usage of BinaryHeap -func BinaryHeapExample() { +func main() { // Min-heap heap := binaryheap.NewWithIntComparator() // empty (min-heap) diff --git a/examples/btree.go b/examples/btree/btree.go similarity index 97% rename from examples/btree.go rename to examples/btree/btree.go index b907696..ea61b03 100644 --- a/examples/btree.go +++ b/examples/btree/btree.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package examples +package main import ( "fmt" @@ -10,7 +10,7 @@ import ( ) // BTreeExample to demonstrate basic usage of BTree -func BTreeExample() { +func main() { tree := btree.NewWithIntComparator(3) // empty (keys are of type int) tree.Put(1, "x") // 1->x diff --git a/examples/customcomparator.go b/examples/customcomparator/customcomparator.go similarity index 94% rename from examples/customcomparator.go rename to examples/customcomparator/customcomparator.go index 4c9f8de..b61d969 100644 --- a/examples/customcomparator.go +++ b/examples/customcomparator/customcomparator.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package examples +package main import ( "fmt" @@ -33,7 +33,7 @@ func byID(a, b interface{}) int { } // CustomComparatorExample to demonstrate basic usage of CustomComparator -func CustomComparatorExample() { +func main() { set := treeset.NewWith(byID) set.Add(User{2, "Second"}) diff --git a/examples/doublylinkedlist.go b/examples/doublylinkedlist/doublylinkedlist.go similarity index 95% rename from examples/doublylinkedlist.go rename to examples/doublylinkedlist/doublylinkedlist.go index 95a64a2..99ec995 100644 --- a/examples/doublylinkedlist.go +++ b/examples/doublylinkedlist/doublylinkedlist.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package examples +package main import ( dll "github.com/emirpasic/gods/lists/doublylinkedlist" @@ -10,7 +10,7 @@ import ( ) // DoublyLinkedListExample to demonstrate basic usage of DoublyLinkedList -func DoublyLinkedListExample() { +func main() { list := dll.New() list.Add("a") // ["a"] list.Append("b") // ["a","b"] (same as Add()) diff --git a/examples/enumerablewithindex.go b/examples/enumerablewithindex/enumerablewithindex.go similarity index 97% rename from examples/enumerablewithindex.go rename to examples/enumerablewithindex/enumerablewithindex.go index a33399a..9545911 100644 --- a/examples/enumerablewithindex.go +++ b/examples/enumerablewithindex/enumerablewithindex.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package examples +package main import ( "fmt" @@ -18,7 +18,7 @@ func printSet(txt string, set *treeset.Set) { } // EnumerableWithIndexExample to demonstrate basic usage of EnumerableWithIndex -func EnumerableWithIndexExample() { +func main() { set := treeset.NewWithIntComparator() set.Add(2, 3, 4, 2, 5, 6, 7, 8) printSet("Initial", set) // [ 2 3 4 5 6 7 8 ] diff --git a/examples/enumerablewithkey.go b/examples/enumerablewithkey/enumerablewithkey.go similarity index 97% rename from examples/enumerablewithkey.go rename to examples/enumerablewithkey/enumerablewithkey.go index c9123ab..7f05040 100644 --- a/examples/enumerablewithkey.go +++ b/examples/enumerablewithkey/enumerablewithkey.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package examples +package main import ( "fmt" @@ -18,7 +18,7 @@ func printMap(txt string, m *treemap.Map) { } // EunumerableWithKeyExample to demonstrate basic usage of EunumerableWithKey -func EunumerableWithKeyExample() { +func main() { m := treemap.NewWithStringComparator() m.Put("g", 7) m.Put("f", 6) diff --git a/examples/hashbidimap.go b/examples/hashbidimap/hashbidimap.go similarity index 95% rename from examples/hashbidimap.go rename to examples/hashbidimap/hashbidimap.go index 861fff9..26350b8 100644 --- a/examples/hashbidimap.go +++ b/examples/hashbidimap/hashbidimap.go @@ -2,12 +2,12 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package examples +package main import "github.com/emirpasic/gods/maps/hashbidimap" // HashBidiMapExample to demonstrate basic usage of HashMap -func HashBidiMapExample() { +func main() { m := hashbidimap.New() // empty m.Put(1, "x") // 1->x m.Put(3, "b") // 1->x, 3->b (random order) diff --git a/examples/hashmap.go b/examples/hashmap/hashmap.go similarity index 94% rename from examples/hashmap.go rename to examples/hashmap/hashmap.go index f49c042..2fda79e 100644 --- a/examples/hashmap.go +++ b/examples/hashmap/hashmap.go @@ -2,12 +2,12 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package examples +package main import "github.com/emirpasic/gods/maps/hashmap" // HashMapExample to demonstrate basic usage of HashMap -func HashMapExample() { +func main() { m := hashmap.New() // empty m.Put(1, "x") // 1->x m.Put(2, "b") // 2->b, 1->x (random order) diff --git a/examples/hashset.go b/examples/hashset/hashset.go similarity index 94% rename from examples/hashset.go rename to examples/hashset/hashset.go index 5fe2bd0..6c366e5 100644 --- a/examples/hashset.go +++ b/examples/hashset/hashset.go @@ -2,12 +2,12 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package examples +package main import "github.com/emirpasic/gods/sets/hashset" // HashSetExample to demonstrate basic usage of HashSet -func HashSetExample() { +func main() { set := hashset.New() // empty (keys are of type int) set.Add(1) // 1 set.Add(2, 2, 3, 4, 5) // 3, 1, 2, 4, 5 (random order, duplicates ignored) diff --git a/examples/iteratorwithindex.go b/examples/iteratorwithindex/iteratorwithindex.go similarity index 96% rename from examples/iteratorwithindex.go rename to examples/iteratorwithindex/iteratorwithindex.go index 86d6bd1..d15c439 100644 --- a/examples/iteratorwithindex.go +++ b/examples/iteratorwithindex/iteratorwithindex.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package examples +package main import ( "fmt" @@ -10,7 +10,7 @@ import ( ) // IteratorWithIndexExample to demonstrate basic usage of IteratorWithIndex -func IteratorWithIndexExample() { +func main() { set := treeset.NewWithStringComparator() set.Add("a", "b", "c") it := set.Iterator() diff --git a/examples/iteratorwithkey.go b/examples/iteratorwithkey/iteratorwithkey.go similarity index 96% rename from examples/iteratorwithkey.go rename to examples/iteratorwithkey/iteratorwithkey.go index 94e5618..4efeb7e 100644 --- a/examples/iteratorwithkey.go +++ b/examples/iteratorwithkey/iteratorwithkey.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package examples +package main import ( "fmt" @@ -10,7 +10,7 @@ import ( ) // IteratorWithKeyExample to demonstrate basic usage of IteratorWithKey -func IteratorWithKeyExample() { +func main() { m := treemap.NewWithIntComparator() m.Put(1, "a") m.Put(2, "b") diff --git a/examples/linkedliststack.go b/examples/linkedliststack/linkedliststack.go similarity index 93% rename from examples/linkedliststack.go rename to examples/linkedliststack/linkedliststack.go index 46ddf40..e9f1a68 100644 --- a/examples/linkedliststack.go +++ b/examples/linkedliststack/linkedliststack.go @@ -2,12 +2,12 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package examples +package main import lls "github.com/emirpasic/gods/stacks/linkedliststack" // LinkedListStackExample to demonstrate basic usage of LinkedListStack -func LinkedListStackExample() { +func main() { stack := lls.New() // empty stack.Push(1) // 1 stack.Push(2) // 1, 2 diff --git a/examples/redblacktree.go b/examples/redblacktree/redblacktree.go similarity index 96% rename from examples/redblacktree.go rename to examples/redblacktree/redblacktree.go index ad36e6c..b7d9803 100644 --- a/examples/redblacktree.go +++ b/examples/redblacktree/redblacktree.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package examples +package main import ( "fmt" @@ -10,7 +10,7 @@ import ( ) // RedBlackTreeExample to demonstrate basic usage of RedBlackTree -func RedBlackTreeExample() { +func main() { tree := rbt.NewWithIntComparator() // empty(keys are of type int) tree.Put(1, "x") // 1->x diff --git a/examples/redblacktreeextended.go b/examples/redblacktreeextended/redblacktreeextended.go similarity index 98% rename from examples/redblacktreeextended.go rename to examples/redblacktreeextended/redblacktreeextended.go index 9823a6b..6e90129 100644 --- a/examples/redblacktreeextended.go +++ b/examples/redblacktreeextended/redblacktreeextended.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package examples +package redblacktreeextended import ( "fmt" @@ -81,7 +81,7 @@ func print(tree *RedBlackTreeExtended) { } // RedBlackTreeExtendedExample main method on how to use the custom red-black tree above -func RedBlackTreeExtendedExample() { +func main() { tree := RedBlackTreeExtended{rbt.NewWithIntComparator()} tree.Put(1, "a") // 1->x (in order) diff --git a/examples/serialization.go b/examples/serialization/serialization.go similarity index 98% rename from examples/serialization.go rename to examples/serialization/serialization.go index 72a1ebf..2f94c5e 100644 --- a/examples/serialization.go +++ b/examples/serialization/serialization.go @@ -1,4 +1,4 @@ -package examples +package serialization import ( "fmt" diff --git a/examples/singlylinkedlist.go b/examples/singlylinkedlist/singlylinkedlist.go similarity index 95% rename from examples/singlylinkedlist.go rename to examples/singlylinkedlist/singlylinkedlist.go index 5d3036a..93b4cca 100644 --- a/examples/singlylinkedlist.go +++ b/examples/singlylinkedlist/singlylinkedlist.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package examples +package main import ( sll "github.com/emirpasic/gods/lists/singlylinkedlist" @@ -10,7 +10,7 @@ import ( ) // SinglyLinkedListExample to demonstrate basic usage of SinglyLinkedList -func SinglyLinkedListExample() { +func main() { list := sll.New() list.Add("a") // ["a"] list.Append("b") // ["a","b"] (same as Add()) diff --git a/examples/sort.go b/examples/sort/sort.go similarity index 94% rename from examples/sort.go rename to examples/sort/sort.go index 854b95b..9f0bd2a 100644 --- a/examples/sort.go +++ b/examples/sort/sort.go @@ -2,12 +2,12 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package examples +package main import "github.com/emirpasic/gods/utils" // SortExample to demonstrate basic usage of basic sort -func SortExample() { +func main() { strings := []interface{}{} // [] strings = append(strings, "d") // ["d"] strings = append(strings, "a") // ["d","a"] diff --git a/examples/treebidimap.go b/examples/treebidimap/treebidimap.go similarity index 95% rename from examples/treebidimap.go rename to examples/treebidimap/treebidimap.go index f4138cb..0c63f12 100644 --- a/examples/treebidimap.go +++ b/examples/treebidimap/treebidimap.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package examples +package main import ( "github.com/emirpasic/gods/maps/treebidimap" @@ -10,7 +10,7 @@ import ( ) // TreeBidiMapExample to demonstrate basic usage of TreeBidiMap -func TreeBidiMapExample() { +func main() { m := treebidimap.NewWith(utils.IntComparator, utils.StringComparator) m.Put(1, "x") // 1->x m.Put(3, "b") // 1->x, 3->b (ordered) diff --git a/examples/treemap.go b/examples/treemap/treemap.go similarity index 95% rename from examples/treemap.go rename to examples/treemap/treemap.go index 0f4e8d6..66b62cc 100644 --- a/examples/treemap.go +++ b/examples/treemap/treemap.go @@ -2,12 +2,12 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package examples +package main import "github.com/emirpasic/gods/maps/treemap" // TreeMapExample to demonstrate basic usage of TreeMap -func TreeMapExample() { +func main() { m := treemap.NewWithIntComparator() // empty (keys are of type int) m.Put(1, "x") // 1->x m.Put(2, "b") // 1->x, 2->b (in order) diff --git a/examples/treeset.go b/examples/treeset/treeset.go similarity index 95% rename from examples/treeset.go rename to examples/treeset/treeset.go index 23caa16..15a7f81 100644 --- a/examples/treeset.go +++ b/examples/treeset/treeset.go @@ -2,12 +2,12 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package examples +package main import "github.com/emirpasic/gods/sets/treeset" // TreeSetExample to demonstrate basic usage of TreeSet -func TreeSetExample() { +func main() { set := treeset.NewWithIntComparator() // empty set.Add(1) // 1 set.Add(2, 2, 3, 4, 5) // 1, 2, 3, 4, 5 (in order, duplicates ignored)