ds

package
v0.0.0-...-3bf81a3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

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) Add

func (list *ArrayList) Add(elem interface{}) bool

func (*ArrayList) AddAll

func (list *ArrayList) AddAll(elemList ...interface{}) bool

func (*ArrayList) Clear

func (list *ArrayList) Clear()

func (*ArrayList) Contains

func (list *ArrayList) Contains(elem interface{}) bool

func (*ArrayList) ContainsAll

func (list *ArrayList) ContainsAll(elemList ...interface{}) bool

func (*ArrayList) Get

func (list *ArrayList) Get(idx int) (elem interface{}, err error)

func (*ArrayList) IndexOf

func (list *ArrayList) IndexOf(elem interface{}) int

func (*ArrayList) IsEmpty

func (list *ArrayList) IsEmpty() bool

func (*ArrayList) LastIndexOf

func (list *ArrayList) LastIndexOf(elem interface{}) int

func (*ArrayList) Remove

func (list *ArrayList) Remove(elem interface{}) bool

func (*ArrayList) RemoveAll

func (list *ArrayList) RemoveAll(elemList ...interface{}) bool

func (*ArrayList) RemoveAt

func (list *ArrayList) RemoveAt(idx int) (interface{}, bool)

func (*ArrayList) Set

func (list *ArrayList) Set(idx int, elem interface{}) error

func (*ArrayList) Size

func (list *ArrayList) Size() (size int)

func (*ArrayList) SubList

func (list *ArrayList) SubList(from, to int) (List, error)

func (*ArrayList) ToArray

func (list *ArrayList) ToArray() (arr []interface{})

type Comparator

type Comparator func(a, b interface{}) int

type HashTable

type HashTable struct {
	// contains filtered or unexported fields
}

Deprecated use sync.Map instead

func NewHashTable

func NewHashTable(keyType, valType reflect.Type, initSize int) *HashTable

func (*HashTable) Get

func (ht *HashTable) Get(key interface{}) (val interface{})

func (*HashTable) Iterator

func (ht *HashTable) Iterator() (iter *reflect.MapIter)

func (*HashTable) Keys

func (ht *HashTable) Keys() (keys []interface{})

func (*HashTable) Set

func (ht *HashTable) Set(key, val interface{}) (ok bool)

func (*HashTable) Size

func (ht *HashTable) Size() (size int)

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 *Heap) BatchOffer(elemList ...interface{}) (ok bool)

func (*Heap) BatchOfferWithArray

func (heap *Heap) BatchOfferWithArray(elemArr []interface{}) (ok bool)

func (*Heap) Clear

func (heap *Heap) Clear()

func (*Heap) Clone

func (heap *Heap) Clone() *Heap

func (*Heap) IgnoredBatchOffer

func (heap *Heap) IgnoredBatchOffer(elemList ...interface{}) (ok bool, invalidIdxList []int)

func (*Heap) IgnoredBatchOfferWithArray

func (heap *Heap) IgnoredBatchOfferWithArray(elemArr []interface{}) (ok bool, invalidIdxList []int)

IgnoredBatchOfferWithArray offer elem list and allow failure

func (*Heap) IsEmpty

func (heap *Heap) IsEmpty() bool

func (*Heap) IsTypeValid

func (heap *Heap) IsTypeValid(elem interface{}) bool

func (*Heap) Offer

func (heap *Heap) Offer(elem interface{}) (ok bool)

func (*Heap) Peek

func (heap *Heap) Peek() interface{}

func (*Heap) Poll

func (heap *Heap) Poll() interface{}

func (*Heap) Remove

func (heap *Heap) Remove(target interface{}) (ok bool)

func (*Heap) RemoveAt

func (heap *Heap) RemoveAt(idx int) interface{}

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.

func (*Heap) Size

func (heap *Heap) Size() int

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

func NewLinkedMap(capacity int) *LinkedMap

func (*LinkedMap) Get

func (lm *LinkedMap) Get(key string) (result interface{})

func (*LinkedMap) Set

func (lm *LinkedMap) Set(key string, val interface{})

func (*LinkedMap) Size

func (lm *LinkedMap) Size() (size int)

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 NewMetaNode[T any](key string, val T, parentKey *string) *MetaNode[T]

func (*MetaNode[T]) ExpandKey

func (node *MetaNode[T]) ExpandKey() []string

func (*MetaNode[T]) ExpandVal

func (node *MetaNode[T]) ExpandVal() []T

func (*MetaNode[T]) GetChildren

func (node *MetaNode[T]) GetChildren() []MetaData[T]

func (*MetaNode[T]) GetChildrenKeys

func (node *MetaNode[T]) GetChildrenKeys() []string

func (*MetaNode[T]) GetKey

func (node *MetaNode[T]) GetKey() 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]) GetVal

func (node *MetaNode[T]) GetVal() T

func (*MetaNode[T]) Nil

func (node *MetaNode[T]) Nil(metaData MetaData[T]) bool

func (*MetaNode[T]) NoParent

func (node *MetaNode[T]) NoParent() bool

func (*MetaNode[T]) SearchNode

func (node *MetaNode[T]) SearchNode(key string) *MetaNode[T]

func (*MetaNode[T]) SetKey

func (node *MetaNode[T]) SetKey(key string)

func (*MetaNode[T]) SetVal

func (node *MetaNode[T]) SetVal(val T)

func (*MetaNode[T]) Walk

func (node *MetaNode[T]) Walk(cb func(*MetaNode[T]))

type MetaTree

type MetaTree[T any] struct {
	Root  *MetaNode[T]
	Extra any
}

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) Add

func (t *Trie) Add(s string)

func (*Trie) Contains

func (t *Trie) Contains(s string) bool

func (*Trie) ContainsPrefix

func (t *Trie) ContainsPrefix(s string) bool

func (*Trie) Delete

func (t *Trie) Delete(s string)

func (*Trie) Search

func (t *Trie) Search(s string) []string

type TypeChecker

type TypeChecker func(elem interface{}) bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL