17,452
stars
+-4+-3+-4
1,821
forks
–
watchers
–
prs
–
issues
–
releases
–
discussions
README
GoDS (Go Data Structures)
Implementation of various data structures and algorithms in Go.
Data Structures
- Containers
- Lists
- ArrayList
- SinglyLinkedList
- DoublyLinkedList
- Sets
- HashSet
- TreeSet
- LinkedHashSet
- Stacks
- LinkedListStack
- ArrayStack
- Maps
- HashMap
- TreeMap
- LinkedHashMap
- HashBidiMap
- TreeBidiMap
- Trees
- RedBlackTree
- AVLTree
- BTree
- BinaryHeap
- Queues
- LinkedListQueue
- ArrayQueue
- CircularBuffer
- PriorityQueue
- Functions
- Comparator
- Iterator
- IteratorWithIndex
- IteratorWithKey
- ReverseIteratorWithIndex
- ReverseIteratorWithKey
- Enumerable
- EnumerableWithIndex
- EnumerableWithKey
- Serialization
- JSONSerializer
- JSONDeserializer
- Sort
- Container
- Appendix
Containers
All data structures implement the container interface with the following methods:
go
type Container interface {
Empty() bool
Size() int
Clear()
Values() []interface{}
String() string
}
Containers are either ordered or unordered. All ordered containers provide stateful iterators and some of them allow enumerable functions.
| Data | Structure | Ordered | Iterator | Enumerable | Referenced by |
| :--- |:--------------------------------------| :---: | :---: | :---: | :---: |
| Lists |
| | ArrayList | yes | yes | yes | index |
| | SinglyLinkedList | yes | yes | yes | index |
| | DoublyLinkedList | yes | yes | yes | index |
| Sets |
| | HashSet | no | no | no | index |
| | TreeSet | yes | yes | yes | index |
| | LinkedHashSet | yes | yes | yes | index |
| Stacks |
| | LinkedListStack | yes | yes | no | index |
| | ArrayStack | yes | yes | no | index |
| Maps |
| | HashMap | no | no | no | key |
| | TreeMap | yes | yes | yes | key |
| | LinkedHashMap | yes | yes | yes | key |
| | HashBidiMap | no | no | no | key |
| | TreeBidiMap | yes | yes | yes | key |
| Trees |
| | RedBlackTree | yes | yes | no | key |
| | AVLTree | yes | yes | no | key |
| | BTree | yes | yes | no | key |
| | BinaryHeap | yes | yes | no | index |
| Queues |
| | LinkedListQueue | yes | yes | no | index |
| | ArrayQueue | yes | yes | no | index |
| | CircularBuffer | yes | yes | no | index |
| | PriorityQueue | yes | yes | no | index |
| | | | reversible | | bidirectional |
Lists
A list is a data structure that stores values and may have repeated values.
Implements Container interface.
go
type List interface {
Get(index int) (interface{}, bool)
Remove(index int)
Add(values ...interface{})
Contains(values ...interface{}) bool
Sort(comparator utils.Comparator