sortedset

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2025 License: GPL-3.0 Imports: 4 Imported by: 2

README

SortedSet

Algorithm to effectively work with ordered data set. Make possible to get result by rank. Work much effectively versus orderedmap in case of large dataset. Thread-safe implementation.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dump

type Dump struct {
	Data    map[string]interface{}
	KeyType string
}

type GetByKeyRangeOptions

type GetByKeyRangeOptions struct {
	Limit        int  // limit the max nodes to return
	ExcludeStart bool // exclude start value, so it search in interval (start, end] or (start, end)
	ExcludeEnd   bool // exclude end value, so it search in interval [start, end) or (start, end)
	Remove       bool
}

type Level

type Level[K comparable, V comparable] struct {
	// contains filtered or unexported fields
}

type Node

type Node[K comparable, V comparable] struct {
	// contains filtered or unexported fields
}

func (*Node[K, V]) Key

func (s *Node[K, V]) Key() K

func (*Node[K, V]) Value

func (s *Node[K, V]) Value() V

type SortedSet

type SortedSet[K comparable, V comparable] struct {
	// contains filtered or unexported fields
}

func NewSortedSet

func NewSortedSet[K comparable, V comparable](c comparator.Comparator) *SortedSet[K, V]

func (*SortedSet[K, V]) Contains

func (s *SortedSet[K, V]) Contains(value V) bool

func (*SortedSet[K, V]) Dump

func (s *SortedSet[K, V]) Dump(makeDump func(key K, value V) (string, string, error)) (string, error)

func (*SortedSet[K, V]) FindRank

func (s *SortedSet[K, V]) FindRank(value V) int

FindRank find the rank of the node specified by key Note that the rank is 1-based integer. Rank 1 means the first node If the node is not found, 0 is returned. Otherwise rank(> 0) is returned Time complexity of this method is : O(log(N))

func (*SortedSet[K, V]) GetByKeyRange

func (s *SortedSet[K, V]) GetByKeyRange(start K, end K, options *GetByKeyRangeOptions) []*Node[K, V]

GetByKeyRange get the nodes whose key within the specific range If options is nil, it `searches` in interval [start, end] without any limit by default Time complexity of this method is : O(log(N))

func (*SortedSet[K, V]) GetByRank

func (s *SortedSet[K, V]) GetByRank(rank int, remove bool) *Node[K, V]

GetByRank get node by rank. Note that the rank is 1-based integer. Rank 1 means the first node; Rank -1 means the last node; If remove is true, the returned nodes are removed If node is not found at specific rank, nil is returned Time complexity of this method is : O(log(N))

func (*SortedSet[K, V]) GetByRankRange

func (s *SortedSet[K, V]) GetByRankRange(start int, end int, remove bool) []*Node[K, V]

GetByRankRange get nodes within specific rank range [start, end] Note that the rank is 1-based integer. Rank 1 means the first node; Rank -1 means the last node; If start is greater than end, the returned array is in reserved order If remove is true, the returned nodes are removed Time complexity of this method is : O(log(N))

func (*SortedSet[K, V]) GetByValue

func (s *SortedSet[K, V]) GetByValue(value V) *Node[K, V]

GetByValue get node by value If node is not found, nil is returned Time complexity : O(1)

func (*SortedSet[K, V]) GetCount

func (s *SortedSet[K, V]) GetCount() int

func (*SortedSet[K, V]) GetRTop

func (s *SortedSet[K, V]) GetRTop(count int, remove bool) (result []*Node[K, V])

GetRTop return top from end data

func (*SortedSet[K, V]) GetTop

func (s *SortedSet[K, V]) GetTop(count int, remove bool) (result []*Node[K, V])

GetTop return top data

func (*SortedSet[K, V]) GetUntilKey

func (s *SortedSet[K, V]) GetUntilKey(untilKey K, remove bool) []any

GetUntilKey get all values until given key

func (*SortedSet[K, V]) PeekMax

func (s *SortedSet[K, V]) PeekMax() *Node[K, V]

PeekMax get the element with maximum key, nil if the set is empty Time Complexity : O(1)

func (*SortedSet[K, V]) PeekMin

func (s *SortedSet[K, V]) PeekMin() *Node[K, V]

PeekMin get the element with minimum key, nil if the set is empty Time complexity of this method is : O(log(N))

func (*SortedSet[K, V]) PopMax

func (s *SortedSet[K, V]) PopMax() *Node[K, V]

PopMax get and remove the element with maximum key, nil if the set is empty Time complexity of this method is : O(log(N))

func (*SortedSet[K, V]) PopMin

func (s *SortedSet[K, V]) PopMin() *Node[K, V]

PopMin get and remove the element with minimal key, nil if the set is empty Time complexity of this method is : O(log(N))

func (*SortedSet[K, V]) Remove

func (s *SortedSet[K, V]) Remove(value V) *Node[K, V]

Remove delete element specified by key Time complexity of this method is : O(log(N))

func (*SortedSet[K, V]) Restore

func (s *SortedSet[K, V]) Restore(keyRestore func(key string, values []string) (K, []V, error), dump string) error

func (*SortedSet[K, V]) Upsert

func (s *SortedSet[K, V]) Upsert(key K, value V) bool

Upsert add an element into the sorted set with specific key / value / key. if the element is added, this method returns true; otherwise false means updated Time complexity of this method is : O(log(N))

Jump to

Keyboard shortcuts

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