+1
Daily
+1
Weekly
-1
Monthly
17,457
stars
1,819
forks
321
watchers
166
prs
129
issues
24
releases
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.ComparatorTop issues
#179Using generics30 comments · 2022-01-15#93Puzzle about the iterative sequence7 comments · 2018-09-30#243Interfaces support any types6 comments · 2024-03-05#113Tree can't serialize []byte as keys5 comments · 2019-06-13#97add Copy to (Array)List5 comments · 2018-12-16#161Add Trie4 comments · 2021-02-04#60Add Skip Lists4 comments · 2017-07-16#284Why does the type of linkedliststack need to be comparable3 comments · 2025-06-26
Latest release
v1.18.1 v1.18.1 2022-04-18- [x] Fix in ArrayList.Contains function against nil values 205