Add LinkedHashSet documentation

pull/90/head
Emir Pasic 7 years ago committed by GitHub
parent ff6d2a7c34
commit 555738833b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -14,6 +14,7 @@ Implementation of various data structures and algorithms in Go.
- [Sets](#sets) - [Sets](#sets)
- [HashSet](#hashset) - [HashSet](#hashset)
- [TreeSet](#treeset) - [TreeSet](#treeset)
- [LinkedHashSet](#linkedhashset)
- [Stacks](#stacks) - [Stacks](#stacks)
- [LinkedListStack](#linkedliststack) - [LinkedListStack](#linkedliststack)
- [ArrayStack](#arraystack) - [ArrayStack](#arraystack)
@ -60,24 +61,30 @@ type Container interface {
Containers are either ordered or unordered. All ordered containers provide [stateful iterators](#iterator) and some of them allow [enumerable functions](#enumerable). Containers are either ordered or unordered. All ordered containers provide [stateful iterators](#iterator) and some of them allow [enumerable functions](#enumerable).
| Container | Ordered | [Iterator](#iterator) | [Enumerable](#enumerable) | Referenced by | | **Data** | **Structure** | **Ordered** | **[Iterator](#iterator)** | **[Enumerable](#enumerable)** | **Referenced by** |
| :--- | :---: | :---: | :---: | :---: | | :--- | :--- | :---: | :---: | :---: | :---: |
| [ArrayList](#arraylist) | yes | yes* | yes | index | | **[Lists](#lists)** |
| [SinglyLinkedList](#singlylinkedlist) | yes | yes | yes | index | | | [ArrayList](#arraylist) | yes | yes* | yes | index |
| [DoublyLinkedList](#doublylinkedlist) | yes | yes* | yes | index | | | [SinglyLinkedList](#singlylinkedlist) | yes | yes | yes | index |
| [HashSet](#hashset) | no | no | no | index | | | [DoublyLinkedList](#doublylinkedlist) | yes | yes* | yes | index |
| [TreeSet](#treeset) | yes | yes* | yes | index | | **[Sets](#sets)** |
| [LinkedListStack](#linkedliststack) | yes | yes | no | index | | | [HashSet](#hashset) | no | no | no | index |
| [ArrayStack](#arraystack) | yes | yes* | no | index | | | [TreeSet](#treeset) | yes | yes* | yes | index |
| [HashMap](#hashmap) | no | no | no | key | | | [LinkedHashSet](#linkedhashset) | yes | yes* | yes | index |
| [TreeMap](#treemap) | yes | yes* | yes | key | | **[Stacks](#stacks)** |
| [HashBidiMap](#hashbidimap) | no | no | no | key* | | | [LinkedListStack](#linkedliststack) | yes | yes | no | index |
| [TreeBidiMap](#treebidimap) | yes | yes* | yes | key* | | | [ArrayStack](#arraystack) | yes | yes* | no | index |
| [RedBlackTree](#redblacktree) | yes | yes* | no | key | | **[Maps](#maps)** |
| [AVLTree](#avltree) | yes | yes* | no | key | | | [HashMap](#hashmap) | no | no | no | key |
| [BTree](#btree) | yes | yes* | no | key | | | [TreeMap](#treemap) | yes | yes* | yes | key |
| [BinaryHeap](#binaryheap) | yes | yes* | no | index | | | [HashBidiMap](#hashbidimap) | no | no | no | key* |
| | | <sub><sup>*reversible</sup></sub> | | <sub><sup>*bidirectional</sup></sub> | | **[Trees](#trees)** |
| | [TreeBidiMap](#treebidimap) | yes | yes* | yes | key* |
| | [RedBlackTree](#redblacktree) | yes | yes* | no | key |
| | [AVLTree](#avltree) | yes | yes* | no | key |
| | [BTree](#btree) | yes | yes* | no | key |
| | [BinaryHeap](#binaryheap) | yes | yes* | no | index |
| | | | <sub><sup>*reversible</sup></sub> | | <sub><sup>*bidirectional</sup></sub> |
### Lists ### Lists
@ -289,6 +296,34 @@ func main() {
} }
``` ```
#### LinkedHashSet
A [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.
Implements [Set](#sets), [IteratorWithIndex](#iteratorwithindex), [EnumerableWithIndex](#enumerablewithindex), [JSONSerializer](#jsonserializer) and [JSONDeserializer](#jsondeserializer) interfaces.
```go
package main
import "github.com/emirpasic/gods/sets/linkedhashset"
func main() {
set := linkedhashset.New() // empty
set.Add(5) // 5
set.Add(4, 4, 3, 2, 1) // 5, 4, 3, 2, 1 (in insertion-order, duplicates ignored)
set.Add(4) // 5, 4, 3, 2, 1 (duplicates ignored, insertion-order unchanged)
set.Remove(4) // 5, 3, 2, 1 (in insertion-order)
set.Remove(2, 3) // 5, 1 (in insertion-order)
set.Contains(1) // true
set.Contains(1, 5) // true
set.Contains(1, 6) // false
_ = set.Values() // []int{5, 1} (in insertion-order)
set.Clear() // empty
set.Empty() // true
set.Size() // 0
}
```
### Stacks ### Stacks
A 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. A 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.

Loading…
Cancel
Save