[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-4844":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":17,"stars30d":18,"stars90d":16,"forks30d":16,"starsTrendScore":17,"compositeScore":19,"rankGlobal":10,"rankLanguage":10,"license":20,"archived":21,"fork":21,"defaultBranch":22,"hasWiki":23,"hasPages":21,"topics":24,"createdAt":10,"pushedAt":10,"updatedAt":41,"readmeContent":42,"aiSummary":43,"trendingCount":16,"starSnapshotCount":16,"syncStatus":44,"lastSyncTime":45,"discoverSource":46},4844,"gods","emirpasic\u002Fgods","emirpasic","GoDS (Go Data Structures) - Sets, Lists, Stacks, Maps, Trees, Queues, and much more","",null,"Go",17441,1826,320,39,0,4,23,74.09,"Other",false,"master",true,[25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40],"avl-tree","b-tree","binary-heap","data-structure","enumerable","go","golang","iterator","list","map","queue","red-black-tree","set","sort","stack","tree","2026-06-12 04:00:23","[![GoDoc](https:\u002F\u002Fgodoc.org\u002Fgithub.com\u002Femirpasic\u002Fgods?status.svg)](https:\u002F\u002Fgodoc.org\u002Fgithub.com\u002Femirpasic\u002Fgods)\n[![Build Status](https:\u002F\u002Fcircleci.com\u002Fgh\u002Femirpasic\u002Fgods\u002Ftree\u002Fmaster.svg?style=shield)](https:\u002F\u002Fcircleci.com\u002Fgh\u002Femirpasic\u002Fgods?branch=master)\n[![Go Report Card](https:\u002F\u002Fgoreportcard.com\u002Fbadge\u002Fgithub.com\u002Femirpasic\u002Fgods)](https:\u002F\u002Fgoreportcard.com\u002Freport\u002Fgithub.com\u002Femirpasic\u002Fgods)\n[![codecov](https:\u002F\u002Fcodecov.io\u002Fgh\u002Femirpasic\u002Fgods\u002Fbranch\u002Fmaster\u002Fgraph\u002Fbadge.svg)](https:\u002F\u002Fcodecov.io\u002Fgh\u002Femirpasic\u002Fgods)\n[![Sourcegraph](https:\u002F\u002Fsourcegraph.com\u002Fgithub.com\u002Femirpasic\u002Fgods\u002F-\u002Fbadge.svg)](https:\u002F\u002Fsourcegraph.com\u002Fgithub.com\u002Femirpasic\u002Fgods?badge)\n[![Release](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Frelease\u002Femirpasic\u002Fgods.svg?style=flat-square)](https:\u002F\u002Fgithub.com\u002Femirpasic\u002Fgods\u002Freleases)\n[![Quality Gate Status](https:\u002F\u002Fsonarcloud.io\u002Fapi\u002Fproject_badges\u002Fmeasure?project=gods&metric=alert_status)](https:\u002F\u002Fsonarcloud.io\u002Fsummary\u002Fnew_code?id=gods)\n[![PyPI](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FLicense-BSD_2--Clause-green.svg)](https:\u002F\u002Fgithub.com\u002Femirpasic\u002Fgods\u002Fblob\u002Fmaster\u002FLICENSE)\n\n# GoDS (Go Data Structures)\n\nImplementation of various data structures and algorithms in Go.\n\n## Data Structures\n\n- [Containers](#containers)\n  - [Lists](#lists)\n    - [ArrayList](#arraylist)\n    - [SinglyLinkedList](#singlylinkedlist)\n    - [DoublyLinkedList](#doublylinkedlist)\n  - [Sets](#sets)\n    - [HashSet](#hashset)\n    - [TreeSet](#treeset)\n    - [LinkedHashSet](#linkedhashset)\n  - [Stacks](#stacks)\n    - [LinkedListStack](#linkedliststack)\n    - [ArrayStack](#arraystack)\n  - [Maps](#maps)\n    - [HashMap](#hashmap)\n    - [TreeMap](#treemap)\n    - [LinkedHashMap](#linkedhashmap)\n    - [HashBidiMap](#hashbidimap)\n    - [TreeBidiMap](#treebidimap)\n  - [Trees](#trees)\n    - [RedBlackTree](#redblacktree)\n    - [AVLTree](#avltree)\n    - [BTree](#btree)\n    - [BinaryHeap](#binaryheap)\n  - [Queues](#queues)\n    - [LinkedListQueue](#linkedlistqueue)\n    - [ArrayQueue](#arrayqueue)\n    - [CircularBuffer](#circularbuffer)\n    - [PriorityQueue](#priorityqueue)\n- [Functions](#functions)\n    - [Comparator](#comparator)\n    - [Iterator](#iterator)\n      - [IteratorWithIndex](#iteratorwithindex)\n      - [IteratorWithKey](#iteratorwithkey)\n      - [ReverseIteratorWithIndex](#reverseiteratorwithindex)\n      - [ReverseIteratorWithKey](#reverseiteratorwithkey)\n    - [Enumerable](#enumerable)\n      - [EnumerableWithIndex](#enumerablewithindex)\n      - [EnumerableWithKey](#enumerablewithkey)\n    - [Serialization](#serialization)\n      - [JSONSerializer](#jsonserializer)\n      - [JSONDeserializer](#jsondeserializer)\n    - [Sort](#sort)\n    - [Container](#container)\n- [Appendix](#appendix)\n\n\n## Containers\n\nAll data structures implement the container interface with the following methods:\n\n```go\ntype Container interface {\n\tEmpty() bool\n\tSize() int\n\tClear()\n\tValues() []interface{}\n\tString() string\n}\n```\n\nContainers are either ordered or unordered. All ordered containers provide [stateful iterators](#iterator) and some of them allow [enumerable functions](#enumerable).\n\n| **Data** | **Structure**                         | **Ordered** | **[Iterator](#iterator)** | **[Enumerable](#enumerable)** | **Referenced by** |\n| :--- |:--------------------------------------| :---: | :---: | :---: | :---: |\n| [Lists](#lists) |\n|   | [ArrayList](#arraylist)               | yes | yes* | yes | index |\n|   | [SinglyLinkedList](#singlylinkedlist) | yes | yes | yes | index |\n|   | [DoublyLinkedList](#doublylinkedlist) | yes | yes* | yes | index |\n| [Sets](#sets) |\n|   | [HashSet](#hashset)                   | no | no | no | index |\n|   | [TreeSet](#treeset)                   | yes | yes* | yes | index |\n|   | [LinkedHashSet](#linkedhashset)       | yes | yes* | yes | index |\n| [Stacks](#stacks) |\n|   | [LinkedListStack](#linkedliststack)   | yes | yes | no | index |\n|   | [ArrayStack](#arraystack)             | yes | yes* | no | index |\n| [Maps](#maps) |\n|   | [HashMap](#hashmap)                   | no | no | no | key |\n|   | [TreeMap](#treemap)                   | yes | yes* | yes | key |\n|   | [LinkedHashMap](#linkedhashmap)       | yes | yes* | yes | key |\n|   | [HashBidiMap](#hashbidimap)           | no | no | no | key* |\n|   | [TreeBidiMap](#treebidimap)           | yes | yes* | yes | key* |\n| [Trees](#trees) |\n|   | [RedBlackTree](#redblacktree)         | yes | yes* | no | key |\n|   | [AVLTree](#avltree)                   | yes | yes* | no | key |\n|   | [BTree](#btree)                       | yes | yes* | no | key |\n|   | [BinaryHeap](#binaryheap)             | yes | yes* | no | index |\n| [Queues](#queues) |\n|   | [LinkedListQueue](#linkedlistqueue)   | yes | yes | no | index |\n|   | [ArrayQueue](#arrayqueue)             | yes | yes* | no | index |\n|   | [CircularBuffer](#circularbuffer)     | yes | yes* | no | index |\n|   | [PriorityQueue](#priorityqueue)       | yes | yes* | no | index |\n|   |                                       |  | \u003Csub>\u003Csup>*reversible\u003C\u002Fsup>\u003C\u002Fsub> |  | \u003Csub>\u003Csup>*bidirectional\u003C\u002Fsup>\u003C\u002Fsub> |\n\n### Lists\n\nA list is a data structure that stores values and may have repeated values.\n\nImplements [Container](#containers) interface.\n\n```go\ntype List interface {\n\tGet(index int) (interface{}, bool)\n\tRemove(index int)\n\tAdd(values ...interface{})\n\tContains(values ...interface{}) bool\n\tSort(comparator utils.Comparator)\n\tSwap(index1, index2 int)\n\tInsert(index int, values ...interface{})\n\tSet(index int, value interface{})\n\n\tcontainers.Container\n\t\u002F\u002F Empty() bool\n\t\u002F\u002F Size() int\n\t\u002F\u002F Clear()\n\t\u002F\u002F Values() []interface{}\n    \u002F\u002F String() string\n}\n```\n\n#### ArrayList\n\nA [list](#lists) backed by a dynamic array that grows and shrinks implicitly.\n\nImplements [List](#lists), [ReverseIteratorWithIndex](#reverseiteratorwithindex), [EnumerableWithIndex](#enumerablewithindex), [JSONSerializer](#jsonserializer) and [JSONDeserializer](#jsondeserializer) interfaces.\n\n```go\npackage main\n\nimport (\n\t\"github.com\u002Femirpasic\u002Fgods\u002Flists\u002Farraylist\"\n\t\"github.com\u002Femirpasic\u002Fgods\u002Futils\"\n)\n\nfunc main() {\n\tlist := arraylist.New()\n\tlist.Add(\"a\")                         \u002F\u002F [\"a\"]\n\tlist.Add(\"c\", \"b\")                    \u002F\u002F [\"a\",\"c\",\"b\"]\n\tlist.Sort(utils.StringComparator)     \u002F\u002F [\"a\",\"b\",\"c\"]\n\t_, _ = list.Get(0)                    \u002F\u002F \"a\",true\n\t_, _ = list.Get(100)                  \u002F\u002F nil,false\n\t_ = list.Contains(\"a\", \"b\", \"c\")      \u002F\u002F true\n\t_ = list.Contains(\"a\", \"b\", \"c\", \"d\") \u002F\u002F false\n\tlist.Swap(0, 1)                       \u002F\u002F [\"b\",\"a\",c\"]\n\tlist.Remove(2)                        \u002F\u002F [\"b\",\"a\"]\n\tlist.Remove(1)                        \u002F\u002F [\"b\"]\n\tlist.Remove(0)                        \u002F\u002F []\n\tlist.Remove(0)                        \u002F\u002F [] (ignored)\n\t_ = list.Empty()                      \u002F\u002F true\n\t_ = list.Size()                       \u002F\u002F 0\n\tlist.Add(\"a\")                         \u002F\u002F [\"a\"]\n\tlist.Clear()                          \u002F\u002F []\n\tlist.Insert(0, \"b\")                   \u002F\u002F [\"b\"]\n\tlist.Insert(0, \"a\")                   \u002F\u002F [\"a\",\"b\"]\n}\n```\n\n#### SinglyLinkedList\n\nA [list](#lists) where each element points to the next element in the list.\n\nImplements [List](#lists), [IteratorWithIndex](#iteratorwithindex), [EnumerableWithIndex](#enumerablewithindex), [JSONSerializer](#jsonserializer) and [JSONDeserializer](#jsondeserializer) interfaces.\n\n```go\npackage main\n\nimport (\n\tsll \"github.com\u002Femirpasic\u002Fgods\u002Flists\u002Fsinglylinkedlist\"\n\t\"github.com\u002Femirpasic\u002Fgods\u002Futils\"\n)\n\nfunc main() {\n\tlist := sll.New()\n\tlist.Add(\"a\")                         \u002F\u002F [\"a\"]\n\tlist.Add(\"c\", \"b\")                    \u002F\u002F [\"a\",\"c\",\"b\"]\n\tlist.Sort(utils.StringComparator)     \u002F\u002F [\"a\",\"b\",\"c\"]\n\t_, _ = list.Get(0)                    \u002F\u002F \"a\",true\n\t_, _ = list.Get(100)                  \u002F\u002F nil,false\n\t_ = list.Contains(\"a\", \"b\", \"c\")      \u002F\u002F true\n\t_ = list.Contains(\"a\", \"b\", \"c\", \"d\") \u002F\u002F false\n\tlist.Swap(0, 1)                       \u002F\u002F [\"b\",\"a\",c\"]\n\tlist.Remove(2)                        \u002F\u002F [\"b\",\"a\"]\n\tlist.Remove(1)                        \u002F\u002F [\"b\"]\n\tlist.Remove(0)                        \u002F\u002F []\n\tlist.Remove(0)                        \u002F\u002F [] (ignored)\n\t_ = list.Empty()                      \u002F\u002F true\n\t_ = list.Size()                       \u002F\u002F 0\n\tlist.Add(\"a\")                         \u002F\u002F [\"a\"]\n\tlist.Clear()                          \u002F\u002F []\n\tlist.Insert(0, \"b\")                   \u002F\u002F [\"b\"]\n\tlist.Insert(0, \"a\")                   \u002F\u002F [\"a\",\"b\"]\n}\n```\n\n#### DoublyLinkedList\n\nA [list](#lists) where each element points to the next and previous elements in the list.\n\nImplements [List](#lists), [ReverseIteratorWithIndex](#reverseiteratorwithindex), [EnumerableWithIndex](#enumerablewithindex), [JSONSerializer](#jsonserializer) and [JSONDeserializer](#jsondeserializer) interfaces.\n\n```go\npackage main\n\nimport (\n\tdll \"github.com\u002Femirpasic\u002Fgods\u002Flists\u002Fdoublylinkedlist\"\n\t\"github.com\u002Femirpasic\u002Fgods\u002Futils\"\n)\n\nfunc main() {\n\tlist := dll.New()\n\tlist.Add(\"a\")                         \u002F\u002F [\"a\"]\n\tlist.Add(\"c\", \"b\")                    \u002F\u002F [\"a\",\"c\",\"b\"]\n\tlist.Sort(utils.StringComparator)     \u002F\u002F [\"a\",\"b\",\"c\"]\n\t_, _ = list.Get(0)                    \u002F\u002F \"a\",true\n\t_, _ = list.Get(100)                  \u002F\u002F nil,false\n\t_ = list.Contains(\"a\", \"b\", \"c\")      \u002F\u002F true\n\t_ = list.Contains(\"a\", \"b\", \"c\", \"d\") \u002F\u002F false\n\tlist.Swap(0, 1)                       \u002F\u002F [\"b\",\"a\",c\"]\n\tlist.Remove(2)                        \u002F\u002F [\"b\",\"a\"]\n\tlist.Remove(1)                        \u002F\u002F [\"b\"]\n\tlist.Remove(0)                        \u002F\u002F []\n\tlist.Remove(0)                        \u002F\u002F [] (ignored)\n\t_ = list.Empty()                      \u002F\u002F true\n\t_ = list.Size()                       \u002F\u002F 0\n\tlist.Add(\"a\")                         \u002F\u002F [\"a\"]\n\tlist.Clear()                          \u002F\u002F []\n\tlist.Insert(0, \"b\")                   \u002F\u002F [\"b\"]\n\tlist.Insert(0, \"a\")                   \u002F\u002F [\"a\",\"b\"]\n}\n```\n\n### Sets\n\nA set is a data structure that can store elements and has no repeated values. It is a computer implementation of the mathematical concept of a finite set. Unlike most other collection types, rather than retrieving a specific element from a set, one typically tests an element for membership in a set. This structure is often used to ensure that no duplicates are present in a container.\n\nSet additionally allow set operations such as [intersection](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FIntersection_(set_theory)), [union](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FUnion_(set_theory)), [difference](https:\u002F\u002Fproofwiki.org\u002Fwiki\u002FDefinition:Set_Difference), etc.\n\nImplements [Container](#containers) interface.\n\n```go\ntype Set interface {\n\tAdd(elements ...interface{})\n\tRemove(elements ...interface{})\n\tContains(elements ...interface{}) bool\n    \u002F\u002F Intersection(another *Set) *Set\n    \u002F\u002F Union(another *Set) *Set\n    \u002F\u002F Difference(another *Set) *Set\n\t\n\tcontainers.Container\n\t\u002F\u002F Empty() bool\n\t\u002F\u002F Size() int\n\t\u002F\u002F Clear()\n\t\u002F\u002F Values() []interface{}\n\t\u002F\u002F String() string\n}\n```\n\n#### HashSet\n\nA [set](#sets) backed by a hash table (actually a Go's map). It makes no guarantees as to the iteration order of the set.\n\nImplements [Set](#sets), [JSONSerializer](#jsonserializer) and [JSONDeserializer](#jsondeserializer) interfaces.\n\n```go\npackage main\n\nimport \"github.com\u002Femirpasic\u002Fgods\u002Fsets\u002Fhashset\"\n\nfunc main() {\n\tset := hashset.New()   \u002F\u002F empty\n\tset.Add(1)             \u002F\u002F 1\n\tset.Add(2, 2, 3, 4, 5) \u002F\u002F 3, 1, 2, 4, 5 (random order, duplicates ignored)\n\tset.Remove(4)          \u002F\u002F 5, 3, 2, 1 (random order)\n\tset.Remove(2, 3)       \u002F\u002F 1, 5 (random order)\n\tset.Contains(1)        \u002F\u002F true\n\tset.Contains(1, 5)     \u002F\u002F true\n\tset.Contains(1, 6)     \u002F\u002F false\n\t_ = set.Values()       \u002F\u002F []int{5,1} (random order)\n\tset.Clear()            \u002F\u002F empty\n\tset.Empty()            \u002F\u002F true\n\tset.Size()             \u002F\u002F 0\n}\n```\n\n#### TreeSet\n\nA [set](#sets) backed by a [red-black tree](#redblacktree) to keep the elements ordered with respect to the [comparator](#comparator).\n\nImplements [Set](#sets), [ReverseIteratorWithIndex](#reverseiteratorwithindex), [EnumerableWithIndex](#enumerablewithindex), [JSONSerializer](#jsonserializer) and [JSONDeserializer](#jsondeserializer) interfaces.\n\n```go\npackage main\n\nimport \"github.com\u002Femirpasic\u002Fgods\u002Fsets\u002Ftreeset\"\n\nfunc main() {\n\tset := treeset.NewWithIntComparator() \u002F\u002F empty (keys are of type int)\n\tset.Add(1)                            \u002F\u002F 1\n\tset.Add(2, 2, 3, 4, 5)                \u002F\u002F 1, 2, 3, 4, 5 (in order, duplicates ignored)\n\tset.Remove(4)                         \u002F\u002F 1, 2, 3, 5 (in order)\n\tset.Remove(2, 3)                      \u002F\u002F 1, 5 (in order)\n\tset.Contains(1)                       \u002F\u002F true\n\tset.Contains(1, 5)                    \u002F\u002F true\n\tset.Contains(1, 6)                    \u002F\u002F false\n\t_ = set.Values()                      \u002F\u002F []int{1,5} (in order)\n\tset.Clear()                           \u002F\u002F empty\n\tset.Empty()                           \u002F\u002F true\n\tset.Size()                            \u002F\u002F 0\n}\n```\n\n#### LinkedHashSet\n\nA [set](#sets) that preserves insertion-order. Data structure is backed by a hash table to store values and [doubly-linked list](#doublylinkedlist) to store insertion ordering.\n\nImplements [Set](#sets), [ReverseIteratorWithIndex](#reverseiteratorwithindex), [EnumerableWithIndex](#enumerablewithindex), [JSONSerializer](#jsonserializer) and [JSONDeserializer](#jsondeserializer) interfaces.\n\n```go\npackage main\n\nimport \"github.com\u002Femirpasic\u002Fgods\u002Fsets\u002Flinkedhashset\"\n\nfunc main() {\n\tset := linkedhashset.New() \u002F\u002F empty\n\tset.Add(5)                 \u002F\u002F 5\n\tset.Add(4, 4, 3, 2, 1)     \u002F\u002F 5, 4, 3, 2, 1 (in insertion-order, duplicates ignored)\n\tset.Add(4)                 \u002F\u002F 5, 4, 3, 2, 1 (duplicates ignored, insertion-order unchanged)\n\tset.Remove(4)              \u002F\u002F 5, 3, 2, 1 (in insertion-order)\n\tset.Remove(2, 3)           \u002F\u002F 5, 1 (in insertion-order)\n\tset.Contains(1)            \u002F\u002F true\n\tset.Contains(1, 5)         \u002F\u002F true\n\tset.Contains(1, 6)         \u002F\u002F false\n\t_ = set.Values()           \u002F\u002F []int{5, 1} (in insertion-order)\n\tset.Clear()                \u002F\u002F empty\n\tset.Empty()                \u002F\u002F true\n\tset.Size()                 \u002F\u002F 0\n}\n```\n\n### Stacks\n\nA stack that represents a last-in-first-out (LIFO) data structure. The usual push and pop operations are provided, as well as a method to peek at the top item on the stack.\n\nImplements [Container](#containers) interface.\n\n```go\ntype Stack interface {\n\tPush(value interface{})\n\tPop() (value interface{}, ok bool)\n\tPeek() (value interface{}, ok bool)\n\n\tcontainers.Container\n\t\u002F\u002F Empty() bool\n\t\u002F\u002F Size() int\n\t\u002F\u002F Clear()\n\t\u002F\u002F Values() []interface{}\n\t\u002F\u002F String() string\n}\n```\n\n#### LinkedListStack\n\nA [stack](#stacks) based on a [linked list](#singlylinkedlist).\n\nImplements [Stack](#stacks), [IteratorWithIndex](#iteratorwithindex), [JSONSerializer](#jsonserializer) and [JSONDeserializer](#jsondeserializer) interfaces.\n\n```go\npackage main\n\nimport lls \"github.com\u002Femirpasic\u002Fgods\u002Fstacks\u002Flinkedliststack\"\n\nfunc main() {\n\tstack := lls.New()  \u002F\u002F empty\n\tstack.Push(1)       \u002F\u002F 1\n\tstack.Push(2)       \u002F\u002F 1, 2\n\tstack.Values()      \u002F\u002F 2, 1 (LIFO order)\n\t_, _ = stack.Peek() \u002F\u002F 2,true\n\t_, _ = stack.Pop()  \u002F\u002F 2, true\n\t_, _ = stack.Pop()  \u002F\u002F 1, true\n\t_, _ = stack.Pop()  \u002F\u002F nil, false (nothing to pop)\n\tstack.Push(1)       \u002F\u002F 1\n\tstack.Clear()       \u002F\u002F empty\n\tstack.Empty()       \u002F\u002F true\n\tstack.Size()        \u002F\u002F 0\n}\n```\n\n#### ArrayStack\n\nA [stack](#stacks) based on a [array list](#arraylist).\n\nImplements [Stack](#stacks), [IteratorWithIndex](#iteratorwithindex), [JSONSerializer](#jsonserializer) and [JSONDeserializer](#jsondeserializer) interfaces.\n\n```go\npackage main\n\nimport \"github.com\u002Femirpasic\u002Fgods\u002Fstacks\u002Farraystack\"\n\nfunc main() {\n\tstack := arraystack.New() \u002F\u002F empty\n\tstack.Push(1)             \u002F\u002F 1\n\tstack.Push(2)             \u002F\u002F 1, 2\n\tstack.Values()            \u002F\u002F 2, 1 (LIFO order)\n\t_, _ = stack.Peek()       \u002F\u002F 2,true\n\t_, _ = stack.Pop()        \u002F\u002F 2, true\n\t_, _ = stack.Pop()        \u002F\u002F 1, true\n\t_, _ = stack.Pop()        \u002F\u002F nil, false (nothing to pop)\n\tstack.Push(1)             \u002F\u002F 1\n\tstack.Clear()             \u002F\u002F empty\n\tstack.Empty()             \u002F\u002F true\n\tstack.Size()              \u002F\u002F 0\n}\n```\n\n### Maps\n\nA Map is a data structure that maps keys to values. A map cannot contain duplicate keys and each key can map to at most one value.\n\nImplements [Container](#containers) interface.\n\n```go\ntype Map interface {\n\tPut(key interface{}, value interface{})\n\tGet(key interface{}) (value interface{}, found bool)\n\tRemove(key interface{})\n\tKeys() []interface{}\n\n\tcontainers.Container\n\t\u002F\u002F Empty() bool\n\t\u002F\u002F Size() int\n\t\u002F\u002F Clear()\n\t\u002F\u002F Values() []interface{}\n\t\u002F\u002F String() string\n}\n```\n\nA BidiMap is an extension to the Map. A bidirectional map (BidiMap), also called a hash bag, is an associative data structure in which the key-value pairs form a one-to-one relation. This relation works in both directions by allow the value to also act as a key to key, e.g. a pair (a,b) thus provides a coupling between 'a' and 'b' so that 'b' can be found when 'a' is used as a key and 'a' can be found when 'b' is used as a key.\n\n```go\ntype BidiMap interface {\n\tGetKey(value interface{}) (key interface{}, found bool)\n\n\tMap\n}\n```\n\n#### HashMap\n\nA [map](#maps) based on hash tables. Keys are unordered.\n\nImplements [Map](#maps), [JSONSerializer](#jsonserializer) and [JSONDeserializer](#jsondeserializer) interfaces.\n\n```go\npackage main\n\nimport \"github.com\u002Femirpasic\u002Fgods\u002Fmaps\u002Fhashmap\"\n\nfunc main() {\n\tm := hashmap.New() \u002F\u002F empty\n\tm.Put(1, \"x\")      \u002F\u002F 1->x\n\tm.Put(2, \"b\")      \u002F\u002F 2->b, 1->x (random order)\n\tm.Put(1, \"a\")      \u002F\u002F 2->b, 1->a (random order)\n\t_, _ = m.Get(2)    \u002F\u002F b, true\n\t_, _ = m.Get(3)    \u002F\u002F nil, false\n\t_ = m.Values()     \u002F\u002F []interface {}{\"b\", \"a\"} (random order)\n\t_ = m.Keys()       \u002F\u002F []interface {}{1, 2} (random order)\n\tm.Remove(1)        \u002F\u002F 2->b\n\tm.Clear()          \u002F\u002F empty\n\tm.Empty()          \u002F\u002F true\n\tm.Size()           \u002F\u002F 0\n}\n```\n\n#### TreeMap\n\nA [map](#maps) based on [red-black tree](#redblacktree). Keys are ordered with respect to the [comparator](#comparator).\n\nImplements [Map](#maps), [ReverseIteratorWithIndex](#reverseiteratorwithindex), [EnumerableWithKey](#enumerablewithkey), [JSONSerializer](#jsonserializer) and [JSONDeserializer](#jsondeserializer) interfaces.\n\n```go\npackage main\n\nimport \"github.com\u002Femirpasic\u002Fgods\u002Fmaps\u002Ftreemap\"\n\nfunc main() {\n\tm := treemap.NewWithIntComparator() \u002F\u002F empty (keys are of type int)\n\tm.Put(1, \"x\")                       \u002F\u002F 1->x\n\tm.Put(2, \"b\")                       \u002F\u002F 1->x, 2->b (in order)\n\tm.Put(1, \"a\")                       \u002F\u002F 1->a, 2->b (in order)\n\t_, _ = m.Get(2)                     \u002F\u002F b, true\n\t_, _ = m.Get(3)                     \u002F\u002F nil, false\n\t_ = m.Values()                      \u002F\u002F []interface {}{\"a\", \"b\"} (in order)\n\t_ = m.Keys()                        \u002F\u002F []interface {}{1, 2} (in order)\n\tm.Remove(1)                         \u002F\u002F 2->b\n\tm.Clear()                           \u002F\u002F empty\n\tm.Empty()                           \u002F\u002F true\n\tm.Size()                            \u002F\u002F 0\n\n\t\u002F\u002F Other:\n\tm.Min() \u002F\u002F Returns the minimum key and its value from map.\n\tm.Max() \u002F\u002F Returns the maximum key and its value from map.\n}\n```\n\n#### LinkedHashMap\n\nA [map](#maps) that preserves insertion-order. It is backed by a hash table to store values and [doubly-linked list](doublylinkedlist) to store ordering.\n\nImplements [Map](#maps), [ReverseIteratorWithIndex](#reverseiteratorwithindex), [EnumerableWithKey](#enumerablewithkey), [JSONSerializer](#jsonserializer) and [JSONDeserializer](#jsondeserializer) interfaces.\n\n```go\npackage main\n\nimport \"github.com\u002Femirpasic\u002Fgods\u002Fmaps\u002Flinkedhashmap\"\n\nfunc main() {\n\tm := linkedhashmap.New() \u002F\u002F empty (keys are of type int)\n\tm.Put(2, \"b\")            \u002F\u002F 2->b\n\tm.Put(1, \"x\")            \u002F\u002F 2->b, 1->x (insertion-order)\n\tm.Put(1, \"a\")            \u002F\u002F 2->b, 1->a (insertion-order)\n\t_, _ = m.Get(2)          \u002F\u002F b, true\n\t_, _ = m.Get(3)          \u002F\u002F nil, false\n\t_ = m.Values()           \u002F\u002F []interface {}{\"b\", \"a\"} (insertion-order)\n\t_ = m.Keys()             \u002F\u002F []interface {}{2, 1} (insertion-order)\n\tm.Remove(1)              \u002F\u002F 2->b\n\tm.Clear()                \u002F\u002F empty\n\tm.Empty()                \u002F\u002F true\n\tm.Size()                 \u002F\u002F 0\n}\n\n```\n\n#### HashBidiMap\n\nA [map](#maps) based on two hashmaps. Keys are unordered.\n\nImplements [BidiMap](#maps), [JSONSerializer](#jsonserializer) and [JSONDeserializer](#jsondeserializer) interfaces.\n\n```go\npackage main\n\nimport \"github.com\u002Femirpasic\u002Fgods\u002Fmaps\u002Fhashbidimap\"\n\nfunc main() {\n\tm := hashbidimap.New() \u002F\u002F empty\n\tm.Put(1, \"x\")          \u002F\u002F 1->x\n\tm.Put(3, \"b\")          \u002F\u002F 1->x, 3->b (random order)\n\tm.Put(1, \"a\")          \u002F\u002F 1->a, 3->b (random order)\n\tm.Put(2, \"b\")          \u002F\u002F 1->a, 2->b (random order)\n\t_, _ = m.GetKey(\"a\")   \u002F\u002F 1, true\n\t_, _ = m.Get(2)        \u002F\u002F b, true\n\t_, _ = m.Get(3)        \u002F\u002F nil, false\n\t_ = m.Values()         \u002F\u002F []interface {}{\"a\", \"b\"} (random order)\n\t_ = m.Keys()           \u002F\u002F []interface {}{1, 2} (random order)\n\tm.Remove(1)            \u002F\u002F 2->b\n\tm.Clear()              \u002F\u002F empty\n\tm.Empty()              \u002F\u002F true\n\tm.Size()               \u002F\u002F 0\n}\n```\n\n#### TreeBidiMap\n\nA [map](#maps) based on red-black tree. This map guarantees that the map will be in both ascending key and value order.  Other than key and value ordering, the goal with this structure is to avoid duplication of elements (unlike in [HashBidiMap](#hashbidimap)), which can be significant if contained elements are large.\n\nImplements [BidiMap](#maps), [ReverseIteratorWithIndex](#reverseiteratorwithindex), [EnumerableWithKey](#enumerablewithkey), [JSONSerializer](#jsonserializer) and [JSONDeserializer](#jsondeserializer) interfaces.\n\n```go\npackage main\n\nimport (\n\t\"github.com\u002Femirpasic\u002Fgods\u002Fmaps\u002Ftreebidimap\"\n\t\"github.com\u002Femirpasic\u002Fgods\u002Futils\"\n)\n\nfunc main() {\n\tm := treebidimap.NewWith(utils.IntComparator, utils.StringComparator)\n\tm.Put(1, \"x\")        \u002F\u002F 1->x\n\tm.Put(3, \"b\")        \u002F\u002F 1->x, 3->b (ordered)\n\tm.Put(1, \"a\")        \u002F\u002F 1->a, 3->b (ordered)\n\tm.Put(2, \"b\")        \u002F\u002F 1->a, 2->b (ordered)\n\t_, _ = m.GetKey(\"a\") \u002F\u002F 1, true\n\t_, _ = m.Get(2)      \u002F\u002F b, true\n\t_, _ = m.Get(3)      \u002F\u002F nil, false\n\t_ = m.Values()       \u002F\u002F []interface {}{\"a\", \"b\"} (ordered)\n\t_ = m.Keys()         \u002F\u002F []interface {}{1, 2} (ordered)\n\tm.Remove(1)          \u002F\u002F 2->b\n\tm.Clear()            \u002F\u002F empty\n\tm.Empty()            \u002F\u002F true\n\tm.Size()             \u002F\u002F 0\n}\n```\n\n### Trees\n\nA tree is a widely used data data structure that simulates a hierarchical tree structure, with a root value and subtrees of children, represented as a set of linked nodes; thus no cyclic links.\n\nImplements [Container](#containers) interface.\n\n```go\ntype Tree interface {\n\tcontainers.Container\n\t\u002F\u002F Empty() bool\n\t\u002F\u002F Size() int\n\t\u002F\u002F Clear()\n\t\u002F\u002F Values() []interface{}\n\t\u002F\u002F String() string\n}\n```\n\n#### RedBlackTree\n\nA red–black [tree](#trees) is a binary search tree with an extra bit of data per node, its color, which can be either red or black. The extra bit of storage ensures an approximately balanced tree by constraining how nodes are colored from any path from the root to the leaf. Thus, it is a data structure which is a type of self-balancing binary search tree.\n\nThe balancing of the tree is not perfect but it is good enough to allow it to guarantee searching in O(log n) time, where n is the total number of elements in the tree. The insertion and deletion operations, along with the tree rearrangement and recoloring, are also performed in O(log n) time. \u003Csub>\u003Csup>[Wikipedia](http:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FRed%E2%80%93black_tree)\u003C\u002Fsup>\u003C\u002Fsub>\n\nImplements [Tree](#trees), [ReverseIteratorWithKey](#reverseiteratorwithkey), [JSONSerializer](#jsonserializer) and [JSONDeserializer](#jsondeserializer) interfaces.\n\n\u003Cp align=\"center\">\u003Cimg src=\"http:\u002F\u002Fupload.wikimedia.org\u002Fwikipedia\u002Fcommons\u002Fthumb\u002F6\u002F66\u002FRed-black_tree_example.svg\u002F500px-Red-black_tree_example.svg.png\" width=\"400px\" height=\"200px\" \u002F>\u003C\u002Fp>\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\trbt \"github.com\u002Femirpasic\u002Fgods\u002Ftrees\u002Fredblacktree\"\n)\n\nfunc main() {\n\ttree := rbt.NewWithIntComparator() \u002F\u002F empty (keys are of type int)\n\n\ttree.Put(1, \"x\") \u002F\u002F 1->x\n\ttree.Put(2, \"b\") \u002F\u002F 1->x, 2->b (in order)\n\ttree.Put(1, \"a\") \u002F\u002F 1->a, 2->b (in order, replacement)\n\ttree.Put(3, \"c\") \u002F\u002F 1->a, 2->b, 3->c (in order)\n\ttree.Put(4, \"d\") \u002F\u002F 1->a, 2->b, 3->c, 4->d (in order)\n\ttree.Put(5, \"e\") \u002F\u002F 1->a, 2->b, 3->c, 4->d, 5->e (in order)\n\ttree.Put(6, \"f\") \u002F\u002F 1->a, 2->b, 3->c, 4->d, 5->e, 6->f (in order)\n\n\tfmt.Println(tree)\n\t\u002F\u002F\n\t\u002F\u002F  RedBlackTree\n\t\u002F\u002F  │           ┌── 6\n\t\u002F\u002F\t│       ┌── 5\n\t\u002F\u002F\t│   ┌── 4\n\t\u002F\u002F\t│   │   └── 3\n\t\u002F\u002F\t└── 2\n\t\u002F\u002F\t\t└── 1\n\n\t_ = tree.Values() \u002F\u002F []interface {}{\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"} (in order)\n\t_ = tree.Keys()   \u002F\u002F []interface {}{1, 2, 3, 4, 5, 6} (in order)\n\n\ttree.Remove(2) \u002F\u002F 1->a, 3->c, 4->d, 5->e, 6->f (in order)\n\tfmt.Println(tree)\n\t\u002F\u002F\n\t\u002F\u002F  RedBlackTree\n\t\u002F\u002F  │       ┌── 6\n\t\u002F\u002F  │   ┌── 5\n\t\u002F\u002F  └── 4\n\t\u002F\u002F      │   ┌── 3\n\t\u002F\u002F      └── 1\n\n\ttree.Clear() \u002F\u002F empty\n\ttree.Empty() \u002F\u002F true\n\ttree.Size()  \u002F\u002F 0\n\n\t\u002F\u002F Other:\n\ttree.Left() \u002F\u002F gets the left-most (min) node\n\ttree.Right() \u002F\u002F get the right-most (max) node\n\ttree.Floor(1) \u002F\u002F get the floor node\n\ttree.Ceiling(1) \u002F\u002F get the ceiling node\n}\n```\n\nExtending the red-black tree's functionality  has been demonstrated in the following [example](https:\u002F\u002Fgithub.com\u002Femirpasic\u002Fgods\u002Fblob\u002Fmaster\u002Fexamples\u002Fredblacktreeextended\u002Fredblacktreeextended.go).\n\n#### AVLTree\n\nAVL [tree](#trees) is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they differ by more than one, rebalancing is done to restore this property. Lookup, insertion, and deletion all take O(log n) time in both the average and worst cases, where n is the number of nodes in the tree prior to the operation. Insertions and deletions may require the tree to be rebalanced by one or more tree rotations.\n\nAVL trees are often compared with red–black trees because both support the same set of operations and take O(log n) time for the basic operations. For lookup-intensive applications, AVL trees are faster than red–black trees because they are more strictly balanced. \u003Csub>\u003Csup>[Wikipedia](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FAVL_tree)\u003C\u002Fsup>\u003C\u002Fsub>\n\nImplements [Tree](#trees), [ReverseIteratorWithKey](#reverseiteratorwithkey), [JSONSerializer](#jsonserializer) and [JSONDeserializer](#jsondeserializer) interfaces.\n\n\u003Cp align=\"center\">\u003Cimg src=\"https:\u002F\u002Fupload.wikimedia.org\u002Fwikipedia\u002Fcommons\u002Fthumb\u002Fa\u002Fad\u002FAVL-tree-wBalance_K.svg\u002F262px-AVL-tree-wBalance_K.svg.png\" width=\"300px\" height=\"180px\" \u002F>\u003Cbr\u002F>\u003Csub>AVL tree with balance factors (green)\u003C\u002Fsub>\u003C\u002Fp>\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\tavl \"github.com\u002Femirpasic\u002Fgods\u002Ftrees\u002Favltree\"\n)\n\nfunc main() {\n\ttree := avl.NewWithIntComparator() \u002F\u002F empty(keys are of type int)\n\n\ttree.Put(1, \"x\") \u002F\u002F 1->x\n\ttree.Put(2, \"b\") \u002F\u002F 1->x, 2->b (in order)\n\ttree.Put(1, \"a\") \u002F\u002F 1->a, 2->b (in order, replacement)\n\ttree.Put(3, \"c\") \u002F\u002F 1->a, 2->b, 3->c (in order)\n\ttree.Put(4, \"d\") \u002F\u002F 1->a, 2->b, 3->c, 4->d (in order)\n\ttree.Put(5, \"e\") \u002F\u002F 1->a, 2->b, 3->c, 4->d, 5->e (in order)\n\ttree.Put(6, \"f\") \u002F\u002F 1->a, 2->b, 3->c, 4->d, 5->e, 6->f (in order)\n\n\tfmt.Println(tree)\n\t\u002F\u002F\n\t\u002F\u002F  AVLTree\n\t\u002F\u002F  │       ┌── 6\n\t\u002F\u002F  │   ┌── 5\n\t\u002F\u002F  └── 4\n\t\u002F\u002F      │   ┌── 3\n\t\u002F\u002F      └── 2\n\t\u002F\u002F          └── 1\n\n\n\t_ = tree.Values() \u002F\u002F []interface {}{\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"} (in order)\n\t_ = tree.Keys()   \u002F\u002F []interface {}{1, 2, 3, 4, 5, 6} (in order)\n\n\ttree.Remove(2) \u002F\u002F 1->a, 3->c, 4->d, 5->e, 6->f (in order)\n\tfmt.Println(tree)\n\t\u002F\u002F\n\t\u002F\u002F  AVLTree\n\t\u002F\u002F  │       ┌── 6\n\t\u002F\u002F  │   ┌── 5\n\t\u002F\u002F  └── 4\n\t\u002F\u002F      └── 3\n\t\u002F\u002F          └── 1\n\n\ttree.Clear() \u002F\u002F empty\n\ttree.Empty() \u002F\u002F true\n\ttree.Size()  \u002F\u002F 0\n}\n```\n\n#### BTree\n\nB-tree is a self-balancing tree data structure that keeps data sorted and allows searches, sequential access, insertions, and deletions in logarithmic time. The B-tree is a generalization of a binary search tree in that a node can have more than two children.\n\nAccording to Knuth's definition, a B-tree of order m is a tree which satisfies the following properties:\n\n- Every node has at most m children.\n- Every non-leaf node (except root) has at least ⌈m\u002F2⌉ children.\n- The root has at least two children if it is not a leaf node.\n- A non-leaf node with k children contains k−1 keys.\n- All leaves appear in the same level\n\nEach internal node’s keys act as separation values which divide its subtrees. For example, if an internal node has 3 child nodes (or subtrees) then it must have 2 keys: a1 and a2. All values in the leftmost subtree will be less than a1, all values in the middle subtree will be between a1 and a2, and all values in the rightmost subtree will be greater than a2.\u003Csub>\u003Csup>[Wikipedia](http:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FRed%E2%80%93black_tree)\u003C\u002Fsub>\u003C\u002Fsup>\n\nImplements [Tree](#trees), [ReverseIteratorWithKey](#reverseiteratorwithkey), [JSONSerializer](#jsonserializer) and [JSONDeserializer](#jsondeserializer) interfaces.\n\n\u003Cp align=\"center\">\u003Cimg src=\"https:\u002F\u002Fupload.wikimedia.org\u002Fwikipedia\u002Fcommons\u002Fthumb\u002F6\u002F65\u002FB-tree.svg\u002F831px-B-tree.svg.png\" width=\"400px\" height=\"111px\" \u002F>\u003C\u002Fp>\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com\u002Femirpasic\u002Fgods\u002Ftrees\u002Fbtree\"\n)\n\nfunc main() {\n\ttree := btree.NewWithIntComparator(3) \u002F\u002F empty (keys are of type int)\n\n\ttree.Put(1, \"x\") \u002F\u002F 1->x\n\ttree.Put(2, \"b\") \u002F\u002F 1->x, 2->b (in order)\n\ttree.Put(1, \"a\") \u002F\u002F 1->a, 2->b (in order, replacement)\n\ttree.Put(3, \"c\") \u002F\u002F 1->a, 2->b, 3->c (in order)\n\ttree.Put(4, \"d\") \u002F\u002F 1->a, 2->b, 3->c, 4->d (in order)\n\ttree.Put(5, \"e\") \u002F\u002F 1->a, 2->b, 3->c, 4->d, 5->e (in order)\n\ttree.Put(6, \"f\") \u002F\u002F 1->a, 2->b, 3->c, 4->d, 5->e, 6->f (in order)\n\ttree.Put(7, \"g\") \u002F\u002F 1->a, 2->b, 3->c, 4->d, 5->e, 6->f, 7->g (in order)\n\n\tfmt.Println(tree)\n\t\u002F\u002F BTree\n\t\u002F\u002F         1\n\t\u002F\u002F     2\n\t\u002F\u002F         3\n\t\u002F\u002F 4\n\t\u002F\u002F         5\n\t\u002F\u002F     6\n\t\u002F\u002F         7\n\n\t_ = tree.Values() \u002F\u002F []interface {}{\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\"} (in order)\n\t_ = tree.Keys()   \u002F\u002F []interface {}{1, 2, 3, 4, 5, 6, 7} (in order)\n\n\ttree.Remove(2) \u002F\u002F 1->a, 3->c, 4->d, 5->e, 6->f, 7->g (in order)\n\tfmt.Println(tree)\n\t\u002F\u002F BTree\n\t\u002F\u002F     1\n\t\u002F\u002F     3\n\t\u002F\u002F 4\n\t\u002F\u002F     5\n\t\u002F\u002F 6\n\t\u002F\u002F     7\n\n\ttree.Clear() \u002F\u002F empty\n\ttree.Empty() \u002F\u002F true\n\ttree.Size()  \u002F\u002F 0\n\n\t\u002F\u002F Other:\n\ttree.Height() \u002F\u002F gets the height of the tree\n\ttree.Left() \u002F\u002F gets the left-most (min) node\n\ttree.LeftKey() \u002F\u002F get the left-most (min) node's key\n\ttree.LeftValue() \u002F\u002F get the left-most (min) node's value\n\ttree.Right() \u002F\u002F get the right-most (max) node\n\ttree.RightKey() \u002F\u002F get the right-most (max) node's key\n\ttree.RightValue() \u002F\u002F get the right-most (max) node's value\n}\n```\n\n#### BinaryHeap\n\nA binary heap is a [tree](#trees) created using a binary tree. It can be seen as a binary tree with two additional constraints:\n\n- Shape property:\n\n  A binary heap is a complete binary tree; that is, all levels of the tree, except possibly the last one (deepest) are fully filled, and, if the last level of the tree is not complete, the nodes of that level are filled from left to right.\n- Heap property:\n\n  All nodes are either greater than or equal to or less than or equal to each of its children, according to a comparison predicate defined for the heap. \u003Csub>\u003Csup>[Wikipedia](http:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FBinary_heap)\u003C\u002Fsub>\u003C\u002Fsup>\n\nImplements [Tree](#trees), [ReverseIteratorWithIndex](#reverseiteratorwithindex), [JSONSerializer](#jsonserializer) and [JSONDeserializer](#jsondeserializer) interfaces.\n\n\u003Cp align=\"center\">\u003Cimg src=\"http:\u002F\u002Fupload.wikimedia.org\u002Fwikipedia\u002Fcommons\u002Fthumb\u002F3\u002F38\u002FMax-Heap.svg\u002F501px-Max-Heap.svg.png\" width=\"300px\" height=\"200px\" \u002F>\u003C\u002Fp>\n\n```go\npackage main\n\nimport (\n\t\"github.com\u002Femirpasic\u002Fgods\u002Ftrees\u002Fbinaryheap\"\n\t\"github.com\u002Femirpasic\u002Fgods\u002Futils\"\n)\n\nfunc main() {\n\n\t\u002F\u002F Min-heap\n\theap := binaryheap.NewWithIntComparator() \u002F\u002F empty (min-heap)\n\theap.Push(2)                              \u002F\u002F 2\n\theap.Push(3)                              \u002F\u002F 2, 3\n\theap.Push(1)                              \u002F\u002F 1, 3, 2\n\theap.Values()                             \u002F\u002F 1, 3, 2\n\t_, _ = heap.Peek()                        \u002F\u002F 1,true\n\t_, _ = heap.Pop()                         \u002F\u002F 1, true\n\t_, _ = heap.Pop()                         \u002F\u002F 2, true\n\t_, _ = heap.Pop()                         \u002F\u002F 3, true\n\t_, _ = heap.Pop()                         \u002F\u002F nil, false (nothing to pop)\n\theap.Push(1)                              \u002F\u002F 1\n\theap.Clear()                              \u002F\u002F empty\n\theap.Empty()                              \u002F\u002F true\n\theap.Size()                               \u002F\u002F 0\n\n\t\u002F\u002F Max-heap\n\tinverseIntComparator := func(a, b interface{}) int {\n\t\treturn -utils.IntComparator(a, b)\n\t}\n\theap = binaryheap.NewWith(inverseIntComparator) \u002F\u002F empty (min-heap)\n\theap.Push(2, 3, 1)                              \u002F\u002F 3, 2, 1 (bulk optimized)\n\theap.Values()                                   \u002F\u002F 3, 2, 1\n}\n```\n\n### Queues\n\nA queue that represents a first-in-first-out (FIFO) data structure. The usual enqueue and dequeue operations are provided, as well as a method to peek at the first item in the queue.\n\n\u003Cp align=\"center\">\u003Cimg src=\"https:\u002F\u002Fupload.wikimedia.org\u002Fwikipedia\u002Fcommons\u002Fthumb\u002F5\u002F52\u002FData_Queue.svg\u002F300px-Data_Queue.svg.png\" width=\"200px\" height=\"120px\" \u002F>\u003C\u002Fp>\n\nImplements [Container](#containers) interface.\n\n```go\ntype Queue interface {\n\tEnqueue(value interface{})\n\tDequeue() (value interface{}, ok bool)\n\tPeek() (value interface{}, ok bool)\n\n\tcontainers.Container\n\t\u002F\u002F Empty() bool\n\t\u002F\u002F Size() int\n\t\u002F\u002F Clear()\n\t\u002F\u002F Values() []interface{}\n\t\u002F\u002F String() string\n}\n```\n\n#### LinkedListQueue\n\nA [queue](#queues) based on a [linked list](#singlylinkedlist).\n\nImplements [Queue](#queues), [IteratorWithIndex](#iteratorwithindex), [JSONSerializer](#jsonserializer) and [JSONDeserializer](#jsondeserializer) interfaces.\n\n```go\npackage main\n\nimport llq \"github.com\u002Femirpasic\u002Fgods\u002Fqueues\u002Flinkedlistqueue\"\n\n\u002F\u002F LinkedListQueueExample to demonstrate basic usage of LinkedListQueue\nfunc main() {\n    queue := llq.New()     \u002F\u002F empty\n    queue.Enqueue(1)       \u002F\u002F 1\n    queue.Enqueue(2)       \u002F\u002F 1, 2\n    _ = queue.Values()     \u002F\u002F 1, 2 (FIFO order)\n    _, _ = queue.Peek()    \u002F\u002F 1,true\n    _, _ = queue.Dequeue() \u002F\u002F 1, true\n    _, _ = queue.Dequeue() \u002F\u002F 2, true\n    _, _ = queue.Dequeue() \u002F\u002F nil, false (nothing to deque)\n    queue.Enqueue(1)       \u002F\u002F 1\n    queue.Clear()          \u002F\u002F empty\n    queue.Empty()          \u002F\u002F true\n    _ = queue.Size()       \u002F\u002F 0\n}\n```\n\n#### ArrayQueue\n\nA [queue](#queues) based on a [array list](#arraylist).\n\nImplements [Queue](#queues), [ReverseIteratorWithIndex](#iteratorwithindex), [JSONSerializer](#jsonserializer) and [JSONDeserializer](#jsondeserializer) interfaces.\n\n```go\npackage main\n\nimport aq \"github.com\u002Femirpasic\u002Fgods\u002Fqueues\u002Farrayqueue\"\n\n\u002F\u002F ArrayQueueExample to demonstrate basic usage of ArrayQueue\nfunc main() {\n    queue := aq.New()      \u002F\u002F empty\n    queue.Enqueue(1)       \u002F\u002F 1\n    queue.Enqueue(2)       \u002F\u002F 1, 2\n    _ = queue.Values()     \u002F\u002F 1, 2 (FIFO order)\n    _, _ = queue.Peek()    \u002F\u002F 1,true\n    _, _ = queue.Dequeue() \u002F\u002F 1, true\n    _, _ = queue.Dequeue() \u002F\u002F 2, true\n    _, _ = queue.Dequeue() \u002F\u002F nil, false (nothing to deque)\n    queue.Enqueue(1)       \u002F\u002F 1\n    queue.Clear()          \u002F\u002F empty\n    queue.Empty()          \u002F\u002F true\n    _ = queue.Size()       \u002F\u002F 0\n}\n```\n\n#### CircularBuffer\n\nA circular buffer, circular [queue](#queues), cyclic buffer or ring buffer is a data structure that uses a single, fixed-size buffer as if it were connected end-to-end. This structure lends itself easily to buffering data streams.\n\n\u003Cp align=\"center\">\u003Cimg src=\"https:\u002F\u002Fupload.wikimedia.org\u002Fwikipedia\u002Fcommons\u002Fthumb\u002Ff\u002Ffd\u002FCircular_Buffer_Animation.gif\u002F400px-Circular_Buffer_Animation.gif\" width=\"300px\" height=\"300px\" \u002F>\u003C\u002Fp>\n\nImplements [Queue](#queues), [ReverseIteratorWithIndex](#iteratorwithindex), [JSONSerializer](#jsonserializer) and [JSONDeserializer](#jsondeserializer) interfaces.\n\n```go\npackage main\n\nimport cb \"github.com\u002Femirpasic\u002Fgods\u002Fqueues\u002Fcircularbuffer\"\n\n\u002F\u002F CircularBufferExample to demonstrate basic usage of CircularBuffer\nfunc main() {\n    queue := cb.New(3)     \u002F\u002F empty (max size is 3)\n    queue.Enqueue(1)       \u002F\u002F 1\n    queue.Enqueue(2)       \u002F\u002F 1, 2\n    queue.Enqueue(3)       \u002F\u002F 1, 2, 3\n    _ = queue.Values()     \u002F\u002F 1, 2, 3\n    queue.Enqueue(3)       \u002F\u002F 4, 2, 3\n    _, _ = queue.Peek()    \u002F\u002F 4,true\n    _, _ = queue.Dequeue() \u002F\u002F 4, true\n    _, _ = queue.Dequeue() \u002F\u002F 2, true\n    _, _ = queue.Dequeue() \u002F\u002F 3, true\n    _, _ = queue.Dequeue() \u002F\u002F nil, false (nothing to deque)\n    queue.Enqueue(1)       \u002F\u002F 1\n    queue.Clear()          \u002F\u002F empty\n    queue.Empty()          \u002F\u002F true\n    _ = queue.Size()       \u002F\u002F 0\n}\n```\n\n#### PriorityQueue\n\nA priority queue is a special type of [queue](#queues) in which each element is associated with a priority value. And, elements are served on the basis of their priority. That is, higher priority elements are served first. However, if elements with the same priority occur, they are served according to their order in the queue.\n\nImplements [Queue](#queues), [ReverseIteratorWithIndex](#iteratorwithindex), [JSONSerializer](#jsonserializer) and [JSONDeserializer](#jsondeserializer) interfaces.\n\n```go\npackage main\n\nimport (\n  pq \"github.com\u002Femirpasic\u002Fgods\u002Fqueues\u002Fpriorityqueue\"\n  \"github.com\u002Femirpasic\u002Fgods\u002Futils\"\n)\n\n\u002F\u002F Element is an entry in the priority queue\ntype Element struct {\n    name     string\n    priority int\n}\n\n\u002F\u002F Comparator function (sort by element's priority value in descending order)\nfunc byPriority(a, b interface{}) int {\n    priorityA := a.(Element).priority\n    priorityB := b.(Element).priority\n    return -utils.IntComparator(priorityA, priorityB) \u002F\u002F \"-\" descending order\n}\n\n\u002F\u002F PriorityQueueExample to demonstrate basic usage of BinaryHeap\nfunc main() {\n    a := Element{name: \"a\", priority: 1}\n    b := Element{name: \"b\", priority: 2}\n    c := Element{name: \"c\", priority: 3}\n    \n    queue := pq.NewWith(byPriority) \u002F\u002F empty\n    queue.Enqueue(a)                \u002F\u002F {a 1}\n    queue.Enqueue(c)                \u002F\u002F {c 3}, {a 1}\n    queue.Enqueue(b)                \u002F\u002F {c 3}, {b 2}, {a 1}\n    _ = queue.Values()              \u002F\u002F [{c 3} {b 2} {a 1}]\n    _, _ = queue.Peek()             \u002F\u002F {c 3} true\n    _, _ = queue.Dequeue()          \u002F\u002F {c 3} true\n    _, _ = queue.Dequeue()          \u002F\u002F {b 2} true\n    _, _ = queue.Dequeue()          \u002F\u002F {a 1} true\n    _, _ = queue.Dequeue()          \u002F\u002F \u003Cnil> false (nothing to dequeue)\n    queue.Clear()                   \u002F\u002F empty\n    _ = queue.Empty()               \u002F\u002F true\n    _ = queue.Size()                \u002F\u002F 0\n}\n```\n\n## Functions\n\nVarious helper functions used throughout the library.\n\n### Comparator\n\nSome data structures (e.g. TreeMap, TreeSet) require a comparator function to automatically keep their elements sorted upon insertion. This comparator is necessary during the initalization.\n\nComparator is defined as:\n\nReturn values (int):\n\n```go\nnegative , if a \u003C b\nzero     , if a == b\npositive , if a > b\n```\n\nComparator signature:\n\n```go\ntype Comparator func(a, b interface{}) int\n```\n\nAll common comparators for builtin types are included in the library:\n\n```go\nfunc StringComparator(a, b interface{}) int\n\nfunc IntComparator(a, b interface{}) int\n\nfunc Int8Comparator(a, b interface{}) int\n\nfunc Int16Comparator(a, b interface{}) int\n\nfunc Int32Comparator(a, b interface{}) int\n\nfunc Int64Comparator(a, b interface{}) int\n\nfunc UIntComparator(a, b interface{}) int\n\nfunc UInt8Comparator(a, b interface{}) int\n\nfunc UInt16Comparator(a, b interface{}) int\n\nfunc UInt32Comparator(a, b interface{}) int\n\nfunc UInt64Comparator(a, b interface{}) int\n\nfunc Float32Comparator(a, b interface{}) int\n\nfunc Float64Comparator(a, b interface{}) int\n\nfunc ByteComparator(a, b interface{}) int\n\nfunc RuneComparator(a, b interface{}) int\n\nfunc TimeComparator(a, b interface{}) int\n```\n\nWriting custom comparators is easy:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com\u002Femirpasic\u002Fgods\u002Fsets\u002Ftreeset\"\n)\n\ntype User struct {\n\tid   int\n\tname string\n}\n\n\u002F\u002F Custom comparator (sort by IDs)\nfunc byID(a, b interface{}) int {\n\n\t\u002F\u002F Type assertion, program will panic if this is not respected\n\tc1 := a.(User)\n\tc2 := b.(User)\n\n\tswitch {\n\tcase c1.id > c2.id:\n\t\treturn 1\n\tcase c1.id \u003C c2.id:\n\t\treturn -1\n\tdefault:\n\t\treturn 0\n\t}\n}\n\nfunc main() {\n\tset := treeset.NewWith(byID)\n\n\tset.Add(User{2, \"Second\"})\n\tset.Add(User{3, \"Third\"})\n\tset.Add(User{1, \"First\"})\n\tset.Add(User{4, \"Fourth\"})\n\n\tfmt.Println(set) \u002F\u002F {1 First}, {2 Second}, {3 Third}, {4 Fourth}\n}\n```\n\n### Iterator\n\nAll ordered containers have stateful iterators. Typically an iterator is obtained by _Iterator()_ function of an ordered container. Once obtained, iterator's _Next()_ function moves the iterator to the next element and returns true if there was a next element. If there was an element, then element's can be obtained by iterator's _Value()_ function. Depending on the ordering type, it's position can be obtained by iterator's _Index()_ or _Key()_ functions. Some containers even provide reversible iterators, essentially the same, but provide another extra _Prev()_ function that moves the iterator to the previous element and returns true if there was a previous element.\n\nNote: it is unsafe to remove elements from container while iterating.\n\n#### IteratorWithIndex\n\nAn [iterator](#iterator) whose elements are referenced by an index.\n\nTypical usage:\n```go\nit := list.Iterator()\nfor it.Next() {\n\tindex, value := it.Index(), it.Value()\n\t...\n}\n```\n\nOther usages:\n```go\nif it.First() {\n\tfirstIndex, firstValue := it.Index(), it.Value()\n\t...\n}\n```\n\n```go\nfor it.Begin(); it.Next(); {\n\t...\n}\n```\n\nSeeking to a specific element:\n\n```go\n\u002F\u002F Seek function, i.e. find element starting with \"b\"\nseek := func(index int, value interface{}) bool {\n    return strings.HasSuffix(value.(string), \"b\")\n}\n\n\u002F\u002F Seek to the condition and continue traversal from that point (forward).\n\u002F\u002F assumes it.Begin() was called.\nfor found := it.NextTo(seek); found; found = it.Next() {\n    index, value := it.Index(), it.Value()\n    ...\n}\n```\n\n#### IteratorWithKey\n\nAn [iterator](#iterator) whose elements are referenced by a key.\n\nTypical usage:\n```go\nit := tree.Iterator()\nfor it.Next() {\n\tkey, value := it.Key(), it.Value()\n\t...\n}\n```\n\nOther usages:\n```go\nif it.First() {\n\tfirstKey, firstValue := it.Key(), it.Value()\n\t...\n}\n```\n\n```go\nfor it.Begin(); it.Next(); {\n\t...\n}\n```\n\nSeeking to a specific element from the current iterator position:\n\n```go\n\u002F\u002F Seek function, i.e. find element starting with \"b\"\nseek := func(key interface{}, value interface{}) bool {\n    return strings.HasSuffix(value.(string), \"b\")\n}\n\n\u002F\u002F Seek to the condition and continue traversal from that point (forward).\n\u002F\u002F assumes it.Begin() was called.\nfor found := it.NextTo(seek); found; found = it.Next() {\n    key, value := it.Key(), it.Value()\n    ...\n}\n```\n\n#### ReverseIteratorWithIndex\n\nAn [iterator](#iterator) whose elements are referenced by an index. Provides all functions as [IteratorWithIndex](#iteratorwithindex), but can also be used for reverse iteration.\n\nTypical usage of iteration in reverse:\n```go\nit := list.Iterator()\nfor it.End(); it.Prev(); {\n\tindex, value := it.Index(), it.Value()\n\t...\n}\n```\n\nOther usages:\n```go\nif it.Last() {\n\tlastIndex, lastValue := it.Index(), it.Value()\n\t...\n}\n```\n\nSeeking to a specific element:\n\n```go\n\u002F\u002F Seek function, i.e. find element starting with \"b\"\nseek := func(index int, value interface{}) bool {\n    return strings.HasSuffix(value.(string), \"b\")\n}\n\n\u002F\u002F Seek to the condition and continue traversal from that point (in reverse).\n\u002F\u002F assumes it.End() was called.\nfor found := it.PrevTo(seek); found; found = it.Prev() {\n    index, value := it.Index(), it.Value()\n\t...\n}\n```\n\n#### ReverseIteratorWithKey\n\nAn [iterator](#iterator) whose elements are referenced by a key. Provides all functions as [IteratorWithKey](#iteratorwithkey), but can also be used for reverse iteration.\n\nTypical usage of iteration in reverse:\n```go\nit := tree.Iterator()\nfor it.End(); it.Prev(); {\n\tkey, value := it.Key(), it.Value()\n\t...\n}\n```\n\nOther usages:\n```go\nif it.Last() {\n\tlastKey, lastValue := it.Key(), it.Value()\n\t...\n}\n```\n\n```go\n\u002F\u002F Seek function, i.e. find element starting with \"b\"\nseek := func(key interface{}, value interface{}) bool {\n    return strings.HasSuffix(value.(string), \"b\")\n}\n\n\u002F\u002F Seek to the condition and continue traversal from that point (in reverse).\n\u002F\u002F assumes it.End() was called.\nfor found := it.PrevTo(seek); found; found = it.Prev() {\n    key, value := it.Key(), it.Value()\n\t...\n}\n```\n\n### Enumerable\n\nEnumerable functions for ordered containers that implement [EnumerableWithIndex](#enumerablewithindex) or [EnumerableWithKey](#enumerablewithkey) interfaces.\n\n#### EnumerableWithIndex\n\n[Enumerable](#enumerable) functions for ordered containers whose values can be fetched by an index.\n\n**Each**\n\nCalls the given function once for each element, passing that element's index and value.\n\n```go\nEach(func(index int, value interface{}))\n```\n\n**Map**\n\nInvokes the given function once for each element and returns a container containing the values returned by the given function.\n\n```go\nMap(func(index int, value interface{}) interface{}) Container\n```\n\n**Select**\n\nReturns a new container containing all elements for which the given function returns a true value.\n\n```go\nSelect(func(index int, value interface{}) bool) Container\n```\n\n**Any**\n\nPasses each element of the container to the given function and returns true if the function ever returns true for any element.\n\n```go\nAny(func(index int, value interface{}) bool) bool\n```\n\n**All**\n\nPasses each element of the container to the given function and returns true if the function returns true for all elements.\n\n```go\nAll(func(index int, value interface{}) bool) bool\n```\n\n**Find**\n\nPasses each element of the container to the given function and returns the first (index,value) for which the function is true or -1,nil otherwise if no element matches the criteria.\n\n```go\nFind(func(index int, value interface{}) bool) (int, interface{})}\n```\n\n**Example:**\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com\u002Femirpasic\u002Fgods\u002Fsets\u002Ftreeset\"\n)\n\nfunc printSet(txt string, set *treeset.Set) {\n\tfmt.Print(txt, \"[ \")\n\tset.Each(func(index int, value interface{}) {\n\t\tfmt.Print(value, \" \")\n\t})\n\tfmt.Println(\"]\")\n}\n\nfunc main() {\n\tset := treeset.NewWithIntComparator()\n\tset.Add(2, 3, 4, 2, 5, 6, 7, 8)\n\tprintSet(\"Initial\", set) \u002F\u002F [ 2 3 4 5 6 7 8 ]\n\n\teven := set.Select(func(index int, value interface{}) bool {\n\t\treturn value.(int)%2 == 0\n\t})\n\tprintSet(\"Even numbers\", even) \u002F\u002F [ 2 4 6 8 ]\n\n\tfoundIndex, foundValue := set.Find(func(index int, value interface{}) bool {\n\t\treturn value.(int)%2 == 0 && value.(int)%3 == 0\n\t})\n\tif foundIndex != -1 {\n\t\tfmt.Println(\"Number divisible by 2 and 3 found is\", foundValue, \"at index\", foundIndex) \u002F\u002F value: 6, index: 4\n\t}\n\n\tsquare := set.Map(func(index int, value interface{}) interface{} {\n\t\treturn value.(int) * value.(int)\n\t})\n\tprintSet(\"Numbers squared\", square) \u002F\u002F [ 4 9 16 25 36 49 64 ]\n\n\tbigger := set.Any(func(index int, value interface{}) bool {\n\t\treturn value.(int) > 5\n\t})\n\tfmt.Println(\"Set contains a number bigger than 5 is \", bigger) \u002F\u002F true\n\n\tpositive := set.All(func(index int, value interface{}) bool {\n\t\treturn value.(int) > 0\n\t})\n\tfmt.Println(\"All numbers are positive is\", positive) \u002F\u002F true\n\n\tevenNumbersSquared := set.Select(func(index int, value interface{}) bool {\n\t\treturn value.(int)%2 == 0\n\t}).Map(func(index int, value interface{}) interface{} {\n\t\treturn value.(int) * value.(int)\n\t})\n\tprintSet(\"Chaining\", evenNumbersSquared) \u002F\u002F [ 4 16 36 64 ]\n}\n```\n\n#### EnumerableWithKey\n\nEnumerable functions for ordered containers whose values whose elements are key\u002Fvalue pairs.\n\n**Each**\n\nCalls the given function once for each element, passing that element's key and value.\n\n```go\nEach(func(key interface{}, value interface{}))\n```\n\n**Map**\n\nInvokes the given function once for each element and returns a container containing the values returned by the given function as key\u002Fvalue pairs.\n\n```go\nMap(func(key interface{}, value interface{}) (interface{}, interface{})) Container\n```\n\n**Select**\n\nReturns a new container containing all elements for which the given function returns a true value.\n\n```go\nSelect(func(key interface{}, value interface{}) bool) Container\n```\n\n**Any**\n\nPasses each element of the container to the given function and returns true if the function ever returns true for any element.\n\n```go\nAny(func(key interface{}, value interface{}) bool) bool\n```\n\n**All**\n\nPasses each element of the container to the given function and returns true if the function returns true for all elements.\n\n```go\nAll(func(key interface{}, value interface{}) bool) bool\n```\n\n**Find**\n\nPasses each element of the container to the given function and returns the first (key,value) for which the function is true or nil,nil otherwise if no element matches the criteria.\n\n```go\nFind(func(key interface{}, value interface{}) bool) (interface{}, interface{})\n```\n\n**Example:**\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com\u002Femirpasic\u002Fgods\u002Fmaps\u002Ftreemap\"\n)\n\nfunc printMap(txt string, m *treemap.Map) {\n\tfmt.Print(txt, \" { \")\n\tm.Each(func(key interface{}, value interface{}) {\n\t\tfmt.Print(key, \":\", value, \" \")\n\t})\n\tfmt.Println(\"}\")\n}\n\nfunc main() {\n\tm := treemap.NewWithStringComparator()\n\tm.Put(\"g\", 7)\n\tm.Put(\"f\", 6)\n\tm.Put(\"e\", 5)\n\tm.Put(\"d\", 4)\n\tm.Put(\"c\", 3)\n\tm.Put(\"b\", 2)\n\tm.Put(\"a\", 1)\n\tprintMap(\"Initial\", m) \u002F\u002F { a:1 b:2 c:3 d:4 e:5 f:6 g:7 }\n\n\teven := m.Select(func(key interface{}, value interface{}) bool {\n\t\treturn value.(int) % 2 == 0\n\t})\n\tprintMap(\"Elements with even values\", even) \u002F\u002F { b:2 d:4 f:6 }\n\n\tfoundKey, foundValue := m.Find(func(key interface{}, value interface{}) bool {\n\t\treturn value.(int) % 2 == 0 && value.(int) % 3 == 0\n\t})\n\tif foundKey != nil {\n\t\tfmt.Println(\"Element with value divisible by 2 and 3 found is\", foundValue, \"with key\", foundKey) \u002F\u002F value: 6, index: 4\n\t}\n\n\tsquare := m.Map(func(key interface{}, value interface{}) (interface{}, interface{}) {\n\t\treturn key.(string) + key.(string), value.(int) * value.(int)\n\t})\n\tprintMap(\"Elements' values squared and letters duplicated\", square) \u002F\u002F { aa:1 bb:4 cc:9 dd:16 ee:25 ff:36 gg:49 }\n\n\tbigger := m.Any(func(key interface{}, value interface{}) bool {\n\t\treturn value.(int) > 5\n\t})\n\tfmt.Println(\"Map contains element whose value is bigger than 5 is\", bigger) \u002F\u002F true\n\n\tpositive := m.All(func(key interface{}, value interface{}) bool {\n\t\treturn value.(int) > 0\n\t})\n\tfmt.Println(\"All map's elements have positive values is\", positive) \u002F\u002F true\n\n\tevenNumbersSquared := m.Select(func(key interface{}, value interface{}) bool {\n\t\treturn value.(int) % 2 == 0\n\t}).Map(func(key interface{}, value interface{}) (interface{}, interface{}) {\n\t\treturn key, value.(int) * value.(int)\n\t})\n\tprintMap(\"Chaining\", evenNumbersSquared) \u002F\u002F { b:4 d:16 f:36 }\n}\n```\n\n### Serialization\n\nAll data structures can be serialized (marshalled) and deserialized (unmarshalled). Currently, only JSON support is available.\n\n#### JSONSerializer\n\nOutputs the container into its JSON representation.\n\nTypical usage for key-value structures:\n\n```go\npackage main\n\nimport (\n\t\"encoding\u002Fjson\"\n\t\"fmt\"\n\t\"github.com\u002Femirpasic\u002Fgods\u002Fmaps\u002Fhashmap\"\n)\n\nfunc main() {\n\tm := hashmap.New()\n\tm.Put(\"a\", \"1\")\n\tm.Put(\"b\", \"2\")\n\tm.Put(\"c\", \"3\")\n\n\tbytes, err := json.Marshal(m) \u002F\u002F Same as \"m.ToJSON(m)\"\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n\tfmt.Println(string(bytes)) \u002F\u002F {\"a\":\"1\",\"b\":\"2\",\"c\":\"3\"}\n}\n```\n\nTypical usage for value-only structures:\n\n```go\npackage main\n\nimport (\n\t\"encoding\u002Fjson\"\n\t\"fmt\"\n\t\"github.com\u002Femirpasic\u002Fgods\u002Flists\u002Farraylist\"\n)\n\nfunc main() {\n\tlist := arraylist.New()\n\tlist.Add(\"a\", \"b\", \"c\")\n\n\tbytes, err := json.Marshal(list) \u002F\u002F Same as \"list.ToJSON(list)\"\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n\tfmt.Println(string(bytes)) \u002F\u002F [\"a\",\"b\",\"c\"]\n}\n```\n\n#### JSONDeserializer\n\nPopulates the container with elements from the input JSON representation.\n\nTypical usage for key-value structures:\n\n```go\npackage main\n\nimport (\n\t\"encoding\u002Fjson\"\n\t\"fmt\"\n\t\"github.com\u002Femirpasic\u002Fgods\u002Fmaps\u002Fhashmap\"\n)\n\nfunc main() {\n\thm := hashmap.New()\n\n\tbytes := []byte(`{\"a\":\"1\",\"b\":\"2\"}`)\n\terr := json.Unmarshal(bytes, &hm) \u002F\u002F Same as \"hm.FromJSON(bytes)\"\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n\tfmt.Println(hm) \u002F\u002F HashMap map[b:2 a:1]\n}\n```\n\nTypical usage for value-only structures:\n\n```go\npackage main\n\nimport (\n\t\"encoding\u002Fjson\"\n\t\"fmt\"\n\t\"github.com\u002Femirpasic\u002Fgods\u002Flists\u002Farraylist\"\n)\n\nfunc main() {\n\tlist := arraylist.New()\n\n\tbytes := []byte(`[\"a\",\"b\"]`)\n\terr := json.Unmarshal(bytes, &list) \u002F\u002F Same as \"list.FromJSON(bytes)\"\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n\tfmt.Println(list) \u002F\u002F ArrayList [\"a\",\"b\"]\n}\n```\n\n### Sort\n\nSort is a general purpose sort function.\n\nLists have an in-place _Sort()_ function and all containers can return their sorted elements via _containers.GetSortedValues()_ function.\n\nInternally these all use the _utils.Sort()_ method:\n\n```go\npackage main\n\nimport \"github.com\u002Femirpasic\u002Fgods\u002Futils\"\n\nfunc main() {\n\tstrings := []interface{}{}                  \u002F\u002F []\n\tstrings = append(strings, \"d\")              \u002F\u002F [\"d\"]\n\tstrings = append(strings, \"a\")              \u002F\u002F [\"d\",\"a\"]\n\tstrings = append(strings, \"b\")              \u002F\u002F [\"d\",\"a\",b\"\n\tstrings = append(strings, \"c\")              \u002F\u002F [\"d\",\"a\",b\",\"c\"]\n\tutils.Sort(strings, utils.StringComparator) \u002F\u002F [\"a\",\"b\",\"c\",\"d\"]\n}\n```\n\n### Container\n\nContainer specific operations:\n\n```go\n\u002F\u002F Returns sorted container''s elements with respect to the passed comparator.\n\u002F\u002F Does not affect the ordering of elements within the container.\nfunc GetSortedValues(container Container, comparator utils.Comparator) []interface{}\n```\n\nUsage:\n\n```go\npackage main\n\nimport (\n\t\"github.com\u002Femirpasic\u002Fgods\u002Flists\u002Farraylist\"\n\t\"github.com\u002Femirpasic\u002Fgods\u002Futils\"\n)\n\nfunc main() {\n\tlist := arraylist.New()\n\tlist.Add(2, 1, 3)\n\tvalues := GetSortedValues(container, utils.StringComparator) \u002F\u002F [1, 2, 3]\n}\n```\n\n## Appendix\n\n### Motivation\n\nCollections and data structures found in other languages: Java Collections, C++ Standard Template Library (STL) containers, Qt Containers, Ruby Enumerable etc.\n\n### Goals\n\n**Fast algorithms**:\n\n  - Based on decades of knowledge and experiences of other libraries mentioned above.\n\n**Memory efficient algorithms**:\n\n  - Avoiding to consume memory by using optimal algorithms and data structures for the given set of problems, e.g. red-black tree in case of TreeMap to avoid keeping redundant sorted array of keys in memory.\n\n**Easy to use library**:\n\n  - Well-structured library with minimalistic set of atomic operations from which more complex operations can be crafted.\n\n**Stable library**:\n\n  - Only additions are permitted keeping the library backward compatible.\n\n**Solid documentation and examples**:\n\n  - Learning by example.\n\n**Production ready**:\n\n  - Used in production.\n\n**No dependencies**:\n\n  - No external imports.\n\nThere is often a tug of war between speed and memory when crafting algorithms. We choose to optimize for speed in most cases within reasonable limits on memory consumption.\n\nThread safety is not a concern of this project, this should be handled at a higher level.\n\n### Testing and Benchmarking\n\nThis takes a while, so test within sub-packages:\n\n`go test -run=NO_TEST -bench . -benchmem  -benchtime 1s .\u002F...`\n\n\u003Cp align=\"center\">\u003Cimg src=\"https:\u002F\u002Fcloud.githubusercontent.com\u002Fassets\u002F3115942\u002F16892979\u002F5e698d46-4b27-11e6-864b-cb2b865327b6.png\" \u002F>\u003C\u002Fp>\n\n### Contributing\n\nBiggest contribution towards this library is to use it and give us feedback for further improvements and additions.\n\nFor direct contributions, _pull request_ into master branch or ask to become a contributor.\n\nCoding style:\n\n```shell\n# Install tooling and set path:\ngo install gotest.tools\u002Fgotestsum@latest\ngo install golang.org\u002Fx\u002Flint\u002Fgolint@latest\ngo install github.com\u002Fkisielk\u002Ferrcheck@latest\nexport PATH=$PATH:$GOPATH\u002Fbin\n\n# Fix errors and warnings:\ngo fmt .\u002F... &&\ngo test -v .\u002F... && \ngolint -set_exit_status .\u002F... && \n! go fmt .\u002F... 2>&1 | read &&\ngo vet -v .\u002F... &&\ngocyclo -avg -over 15 ..\u002Fgods &&\nerrcheck .\u002F...\n```\n\n### License\n\nThis library is distributed under the BSD-style license found in the [LICENSE](https:\u002F\u002Fgithub.com\u002Femirpasic\u002Fgods\u002Fblob\u002Fmaster\u002FLICENSE) file.\n\n### Sponsors\n\n## \u003Ca href=\"https:\u002F\u002Fwww.browserstack.com\u002F?ref=gods\">\u003Cimg src=\"http:\u002F\u002Fwww.hajdarevic.net\u002Fbrowserstack.svg\" alt=\"BrowserStack\" width=\"250\"\u002F>\u003C\u002Fa>\n[BrowserStack](https:\u002F\u002Fwww.browserstack.com\u002F?ref=webhook) is a cloud-based cross-browser testing tool that enables developers to test their websites across various browsers on different operating systems and mobile devices, without requiring users to install virtual machines, devices or emulators.\n","GoDS 是一个用 Go 语言实现的多种数据结构和算法库，包括集合、列表、栈、映射、树和队列等。该项目提供了丰富的数据结构选项，如 AVL 树、B 树、红黑树、二叉堆等，并且支持迭代器、枚举、序列化等功能，使得开发者能够灵活选择适合特定需求的数据结构。其核心功能在于为 Go 语言开发者提供了一个高效且易于使用的工具集，以处理复杂的数据操作任务。适用于需要高性能数据处理的应用场景，特别是在那些对内存使用效率有较高要求的项目中。",2,"2026-06-11 03:00:51","top_language"]