Documentation ¶
Index ¶
- func NewLinkedEntry(key string, payload interface{}) *linkedEntry
- type ArrayList
- func (list *ArrayList) Add(elem interface{}) bool
- func (list *ArrayList) AddAll(elemList ...interface{}) bool
- func (list *ArrayList) Clear()
- func (list *ArrayList) Contains(elem interface{}) bool
- func (list *ArrayList) ContainsAll(elemList ...interface{}) bool
- func (list *ArrayList) Get(idx int) (elem interface{}, err error)
- func (list *ArrayList) IndexOf(elem interface{}) int
- func (list *ArrayList) IsEmpty() bool
- func (list *ArrayList) LastIndexOf(elem interface{}) int
- func (list *ArrayList) Remove(elem interface{}) bool
- func (list *ArrayList) RemoveAll(elemList ...interface{}) bool
- func (list *ArrayList) RemoveAt(idx int) (interface{}, bool)
- func (list *ArrayList) Set(idx int, elem interface{}) error
- func (list *ArrayList) Size() (size int)
- func (list *ArrayList) SubList(from, to int) (List, error)
- func (list *ArrayList) ToArray() (arr []interface{})
- type Comparator
- type HashTable
- type Heap
- func (heap *Heap) BatchOffer(elemList ...interface{}) (ok bool)
- func (heap *Heap) BatchOfferWithArray(elemArr []interface{}) (ok bool)
- func (heap *Heap) Clear()
- func (heap *Heap) Clone() *Heap
- func (heap *Heap) IgnoredBatchOffer(elemList ...interface{}) (ok bool, invalidIdxList []int)
- func (heap *Heap) IgnoredBatchOfferWithArray(elemArr []interface{}) (ok bool, invalidIdxList []int)
- func (heap *Heap) IsEmpty() bool
- func (heap *Heap) IsTypeValid(elem interface{}) bool
- func (heap *Heap) Offer(elem interface{}) (ok bool)
- func (heap *Heap) Peek() interface{}
- func (heap *Heap) Poll() interface{}
- func (heap *Heap) Remove(target interface{}) (ok bool)
- func (heap *Heap) RemoveAt(idx int) interface{}
- func (heap *Heap) RemoveWithComparator(target interface{}, comparator Comparator, rmAll bool) (ok bool)
- func (heap *Heap) Size() int
- type LinkedList
- func (list *LinkedList) Add(interface{}) bool
- func (list *LinkedList) AddAll(...interface{}) bool
- func (list *LinkedList) AddFirst(data interface{}) bool
- func (list *LinkedList) AddLast(data interface{}) bool
- func (list *LinkedList) Clear()
- func (list *LinkedList) Contains(elem interface{}) bool
- func (list *LinkedList) ContainsAll(elemList ...interface{}) bool
- func (list *LinkedList) Get(idx int) (interface{}, error)
- func (list *LinkedList) GetFirst() (interface{}, error)
- func (list *LinkedList) GetLast() (interface{}, error)
- func (list *LinkedList) IndexOf(elem interface{}) (idx int)
- func (list *LinkedList) IsEmpty() bool
- func (list *LinkedList) LastIndexOf(elem interface{}) (idx int)
- func (list *LinkedList) Offer(data interface{})
- func (list *LinkedList) Poll() (interface{}, error)
- func (list *LinkedList) Pop() (interface{}, error)
- func (list *LinkedList) Push(data interface{})
- func (list *LinkedList) Remove(elem interface{}) (ok bool)
- func (list *LinkedList) RemoveAll(elemList ...interface{}) (ok bool)
- func (list *LinkedList) RemoveAt(idx int) (elem interface{}, ok bool)
- func (list *LinkedList) RemoveFirst() (interface{}, error)
- func (list *LinkedList) RemoveLast() (interface{}, error)
- func (list *LinkedList) Set(idx int, data interface{}) error
- func (list *LinkedList) Size() int
- func (list *LinkedList) SubList(from, to int) (List, error)
- func (list *LinkedList) ToArray() (arr []interface{})
- type LinkedMap
- type List
- type MetaData
- type MetaForest
- type MetaNode
- func (node *MetaNode[T]) ExpandKey() []string
- func (node *MetaNode[T]) ExpandVal() []T
- func (node *MetaNode[T]) GetChildren() []MetaData[T]
- func (node *MetaNode[T]) GetChildrenKeys() []string
- func (node *MetaNode[T]) GetKey() string
- func (node *MetaNode[T]) GetParent() MetaData[T]
- func (node *MetaNode[T]) GetParentKey() *string
- func (node *MetaNode[T]) GetVal() T
- func (node *MetaNode[T]) Nil(metaData MetaData[T]) bool
- func (node *MetaNode[T]) NoParent() bool
- func (node *MetaNode[T]) SearchNode(key string) *MetaNode[T]
- func (node *MetaNode[T]) SetKey(key string)
- func (node *MetaNode[T]) SetVal(val T)
- func (node *MetaNode[T]) Walk(cb func(*MetaNode[T]))
- type MetaTree
- type PriorityQueue
- func (pq *PriorityQueue) BatchOffer(elemList ...interface{}) (ok bool)
- func (pq *PriorityQueue) BatchOfferWithArray(elemList []interface{}) (ok bool)
- func (pq *PriorityQueue) Clear()
- func (pq *PriorityQueue) Clone() *PriorityQueue
- func (pq *PriorityQueue) IsElemTypeValid(elem interface{}) bool
- func (pq *PriorityQueue) IsEmpty() (isEmpty bool)
- func (pq *PriorityQueue) Offer(elem interface{}) (ok bool)
- func (pq *PriorityQueue) Peek() (head interface{})
- func (pq *PriorityQueue) Poll() (elem interface{})
- func (pq *PriorityQueue) Remove(target interface{}) (ok bool)
- func (pq *PriorityQueue) RemoveWithComparator(target interface{}, comparator Comparator, rmAll bool) (ok bool)
- func (pq *PriorityQueue) Size() (size int)
- type Trie
- type TypeChecker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewLinkedEntry ¶
func NewLinkedEntry(key string, payload interface{}) *linkedEntry
Types ¶
type ArrayList ¶
type ArrayList struct {
// contains filtered or unexported fields
}
func NewArrayList ¶
func NewArrayList(initCapacity int, typeChecker TypeChecker, comparator Comparator) *ArrayList
func (*ArrayList) ContainsAll ¶
func (*ArrayList) LastIndexOf ¶
type Comparator ¶
type Comparator func(a, b interface{}) int
type HashTable ¶
type HashTable struct {
// contains filtered or unexported fields
}
Deprecated use sync.Map instead
type Heap ¶
type Heap struct {
// contains filtered or unexported fields
}
Heap a thread-unsafe heap with customized comparator and type checker. * attention: nil element is not allowed.
func NewHeap ¶
func NewHeap(comparator Comparator, typeChecker TypeChecker) *Heap
func (*Heap) BatchOffer ¶
func (*Heap) BatchOfferWithArray ¶
func (*Heap) IgnoredBatchOffer ¶
func (*Heap) IgnoredBatchOfferWithArray ¶
IgnoredBatchOfferWithArray offer elem list and allow failure
func (*Heap) IsTypeValid ¶
func (*Heap) RemoveWithComparator ¶
func (heap *Heap) RemoveWithComparator(target interface{}, comparator Comparator, rmAll bool) (ok bool)
RemoveWithComparator remove elements with customized comparator. * 'target' is the first parameter of the comparator.
type LinkedList ¶
type LinkedList struct {
// contains filtered or unexported fields
}
LinkedList a thread-safe linked list
func NewLinkedList ¶
func NewLinkedList(comparator Comparator, typeChecker TypeChecker) *LinkedList
func (*LinkedList) Add ¶
func (list *LinkedList) Add(interface{}) bool
func (*LinkedList) AddAll ¶
func (list *LinkedList) AddAll(...interface{}) bool
func (*LinkedList) AddFirst ¶
func (list *LinkedList) AddFirst(data interface{}) bool
func (*LinkedList) AddLast ¶
func (list *LinkedList) AddLast(data interface{}) bool
func (*LinkedList) Clear ¶
func (list *LinkedList) Clear()
func (*LinkedList) Contains ¶
func (list *LinkedList) Contains(elem interface{}) bool
func (*LinkedList) ContainsAll ¶
func (list *LinkedList) ContainsAll(elemList ...interface{}) bool
func (*LinkedList) Get ¶
func (list *LinkedList) Get(idx int) (interface{}, error)
func (*LinkedList) GetFirst ¶
func (list *LinkedList) GetFirst() (interface{}, error)
func (*LinkedList) GetLast ¶
func (list *LinkedList) GetLast() (interface{}, error)
func (*LinkedList) IndexOf ¶
func (list *LinkedList) IndexOf(elem interface{}) (idx int)
func (*LinkedList) IsEmpty ¶
func (list *LinkedList) IsEmpty() bool
func (*LinkedList) LastIndexOf ¶
func (list *LinkedList) LastIndexOf(elem interface{}) (idx int)
func (*LinkedList) Offer ¶
func (list *LinkedList) Offer(data interface{})
func (*LinkedList) Poll ¶
func (list *LinkedList) Poll() (interface{}, error)
func (*LinkedList) Pop ¶
func (list *LinkedList) Pop() (interface{}, error)
func (*LinkedList) Push ¶
func (list *LinkedList) Push(data interface{})
func (*LinkedList) Remove ¶
func (list *LinkedList) Remove(elem interface{}) (ok bool)
func (*LinkedList) RemoveAll ¶
func (list *LinkedList) RemoveAll(elemList ...interface{}) (ok bool)
func (*LinkedList) RemoveAt ¶
func (list *LinkedList) RemoveAt(idx int) (elem interface{}, ok bool)
func (*LinkedList) RemoveFirst ¶
func (list *LinkedList) RemoveFirst() (interface{}, error)
func (*LinkedList) RemoveLast ¶
func (list *LinkedList) RemoveLast() (interface{}, error)
func (*LinkedList) Set ¶
func (list *LinkedList) Set(idx int, data interface{}) error
Set replaces the element at the specified position
func (*LinkedList) Size ¶
func (list *LinkedList) Size() int
func (*LinkedList) SubList ¶
func (list *LinkedList) SubList(from, to int) (List, error)
SubList returns List instead of LinkedList for implementing interface
func (*LinkedList) ToArray ¶
func (list *LinkedList) ToArray() (arr []interface{})
type LinkedMap ¶
type LinkedMap struct {
// contains filtered or unexported fields
}
LinkedMap 并发安全的 LRU 链式哈希表
func NewLinkedMap ¶
type List ¶
type List interface { Size() int IsEmpty() bool Contains(elem interface{}) bool ContainsAll(elemList ...interface{}) bool ToArray() []interface{} Add(elem interface{}) bool AddAll(elemList ...interface{}) bool Remove(elem interface{}) bool RemoveAll(elem ...interface{}) bool RemoveAt(idx int) (interface{}, bool) SubList(from, to int) (List, error) Get(idx int) (interface{}, error) Set(idx int, elem interface{}) error IndexOf(elem interface{}) int LastIndexOf(elem interface{}) int Clear() }
type MetaData ¶
type MetaData[T any] interface { SetKey(string) GetKey() string SetVal(T) GetVal() T GetParent() MetaData[T] GetChildren() []MetaData[T] GetParentKey() *string GetChildrenKeys() []string }
func ConvToMetaDataList ¶
func ConvToMetaDataList[T any](metaNodes []*MetaNode[T]) []MetaData[T]
type MetaForest ¶
type MetaForest[T any] struct { Children []*MetaTree[T] Extra any // contains filtered or unexported fields }
func BuildMetaForestBottomUp ¶
func BuildMetaForestBottomUp[T any](metaDataList []MetaData[T]) *MetaForest[T]
BuildMetaForestBottomUp builds a MetaForest from a list of MetaData. This function builds the forest bottom up, so each MetaData must have a 'parent key', which means you have to impl GetParentKey(), GetKey(), GetVal() methods. NOTE: use MetaNode instead of MetaData is recommended, because MetaNode has already impl these methods.
func ConvToMetaForest ¶
func ConvToMetaForest[T any](metaDataList []MetaData[T]) *MetaForest[T]
ConvToMetaForest builds a MetaForest from a list of MetaData. This function just conv a list of MetaData to a list of MetaTree, so you can use a list of functions provided by MetaTree and MetaForest.
func (*MetaForest[T]) DisableHashIndex ¶
func (f *MetaForest[T]) DisableHashIndex()
func (*MetaForest[T]) EnableHashIndex ¶
func (f *MetaForest[T]) EnableHashIndex()
EnableHashIndex enables hash index for MetaForest. This is useful when you want to search a node by key. NOTE: this function just init the index, it won't build the index, the index will be built when you call SearchNode.
func (*MetaForest[T]) RemoveHashIndex ¶
func (f *MetaForest[T]) RemoveHashIndex(key string)
func (*MetaForest[T]) ResetHashIndex ¶
func (f *MetaForest[T]) ResetHashIndex()
func (*MetaForest[T]) SearchNode ¶
func (f *MetaForest[T]) SearchNode(key string) *MetaNode[T]
type MetaNode ¶
type MetaNode[T any] struct { // This means a MetaNode is a MetaData MetaData[T] Key string Val T ParentKey *string Parent *MetaNode[T] Children []*MetaNode[T] }
func NewMetaNode ¶
func (*MetaNode[T]) GetChildren ¶
func (node *MetaNode[T]) GetChildren() []MetaData[T]
func (*MetaNode[T]) GetChildrenKeys ¶
func (node *MetaNode[T]) GetChildrenKeys() []string
func (*MetaNode[T]) GetParent ¶
func (node *MetaNode[T]) GetParent() MetaData[T]
GetParent returns the parent of the MetaData with type T. This method was only designed to impl MetaData interface. WARN: do not try to judge whether the parent is nil or not by node.GetParent() == nil, because this will always return false, even if the parent is nil. This is a imperfection of golang generic. If you want to check it, please use NoParent() or node.Parent == nil.
func (*MetaNode[T]) GetParentKey ¶
func (node *MetaNode[T]) GetParentKey() *string
func (*MetaNode[T]) SearchNode ¶
func (node *MetaNode[T]) SearchNode(key string) *MetaNode[T]
type MetaTree ¶
func ConvToMetaTree ¶
func ConvToMetaTree[T any](metaData MetaData[T]) *MetaTree[T]
func (*MetaTree[T]) SearchNode ¶
func (t *MetaTree[T]) SearchNode(key string) *MetaNode[T]
type PriorityQueue ¶
type PriorityQueue struct {
// contains filtered or unexported fields
}
func NewPriorityQueue ¶
func NewPriorityQueue(comparator Comparator, typeChecker TypeChecker) *PriorityQueue
func (*PriorityQueue) BatchOffer ¶
func (pq *PriorityQueue) BatchOffer(elemList ...interface{}) (ok bool)
func (*PriorityQueue) BatchOfferWithArray ¶
func (pq *PriorityQueue) BatchOfferWithArray(elemList []interface{}) (ok bool)
func (*PriorityQueue) Clear ¶
func (pq *PriorityQueue) Clear()
func (*PriorityQueue) Clone ¶
func (pq *PriorityQueue) Clone() *PriorityQueue
func (*PriorityQueue) IsElemTypeValid ¶
func (pq *PriorityQueue) IsElemTypeValid(elem interface{}) bool
func (*PriorityQueue) IsEmpty ¶
func (pq *PriorityQueue) IsEmpty() (isEmpty bool)
func (*PriorityQueue) Offer ¶
func (pq *PriorityQueue) Offer(elem interface{}) (ok bool)
func (*PriorityQueue) Peek ¶
func (pq *PriorityQueue) Peek() (head interface{})
func (*PriorityQueue) Poll ¶
func (pq *PriorityQueue) Poll() (elem interface{})
func (*PriorityQueue) Remove ¶
func (pq *PriorityQueue) Remove(target interface{}) (ok bool)
func (*PriorityQueue) RemoveWithComparator ¶
func (pq *PriorityQueue) RemoveWithComparator(target interface{}, comparator Comparator, rmAll bool) (ok bool)
RemoveWithComparator remove all targets, this method could cost much time and cause blocking
func (*PriorityQueue) Size ¶
func (pq *PriorityQueue) Size() (size int)
type Trie ¶
type Trie struct {
// contains filtered or unexported fields
}
func (*Trie) ContainsPrefix ¶
type TypeChecker ¶
type TypeChecker func(elem interface{}) bool