zset

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2022 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SkipListMaxLevel represents the skipList max level number.
	SkipListMaxLevel = 32

	// SkipListP represents the p parameter of the skipList.
	SkipListP = 0.25
)

Variables

This section is empty.

Functions

This section is empty.

Types

type GetByScoreRangeOptions

type GetByScoreRangeOptions 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)
}

GetByScoreRangeOptions represents the options of the GetByScoreRange function.

type SCORE

type SCORE float64

SCORE represents the score type.

type SortedSet

type SortedSet struct {
	Dict map[string]*SortedSetNode
	// contains filtered or unexported fields
}

SortedSet represents the sorted set.

func New

func New() *SortedSet

New returns a newly initialized SortedSet Object that implements the SortedSet.

func (*SortedSet) FindRank

func (ss *SortedSet) FindRank(key string) int

FindRank Returns the rank of member in the sorted set stored at key, with the scores ordered from low to high. 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) FindRevRank

func (ss *SortedSet) FindRevRank(key string) int

FindRevRank Returns the rank of member in the sorted set stored at key, with the scores ordered from high to low.

func (*SortedSet) GetByKey

func (ss *SortedSet) GetByKey(key string) *SortedSetNode

GetByKey returns the node at given key. If node is not found, nil is returned

Time complexity : O(1).

func (*SortedSet) GetByRank

func (ss *SortedSet) GetByRank(rank int, remove bool) *SortedSetNode

GetByRank returns the node at given 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) GetByRankRange

func (ss *SortedSet) GetByRankRange(start, end int, remove bool) []*SortedSetNode

GetByRankRange returns 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) GetByScoreRange

func (ss *SortedSet) GetByScoreRange(start SCORE, end SCORE, options *GetByScoreRangeOptions) []*SortedSetNode

GetByScoreRange returns the nodes whose score 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) PeekMax

func (ss *SortedSet) PeekMax() *SortedSetNode

PeekMax returns the element with maximum score, nil if the set is empty.

Time Complexity : O(1).

func (*SortedSet) PeekMin

func (ss *SortedSet) PeekMin() *SortedSetNode

PeekMin returns the element with minimum score, nil if the set is empty.

Time complexity of this method is : O(log(N)).

func (*SortedSet) PopMax

func (ss *SortedSet) PopMax() *SortedSetNode

PopMax returns and remove the element with maximum score, nil if the set is empty.

Time complexity of this method is : O(log(N)).

func (*SortedSet) PopMin

func (ss *SortedSet) PopMin() *SortedSetNode

PopMin returns and remove the element with minimal score, nil if the set is empty.

Time complexity of this method is : O(log(N)).

func (*SortedSet) Put

func (ss *SortedSet) Put(key string, score SCORE, value []byte) error

Put puts an element into the sorted set with specific key / value / score.

Time complexity of this method is : O(log(N)).

func (*SortedSet) Remove

func (ss *SortedSet) Remove(key string) *SortedSetNode

Remove removes element specified at given key.

Time complexity of this method is : O(log(N)).

func (*SortedSet) Size

func (ss *SortedSet) Size() int

Size returns the number of elements in the SortedSet.

type SortedSetLevel

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

SortedSetLevel records forward and span.

type SortedSetNode

type SortedSetNode struct {
	Value []byte // associated data
	// contains filtered or unexported fields
}

SortedSetNode represents a node in the SortedSet.

func (*SortedSetNode) Key

func (ssn *SortedSetNode) Key() string

Key returns the key of the node.

func (*SortedSetNode) Score

func (ssn *SortedSetNode) Score() SCORE

Score returns the score of the node.

Jump to

Keyboard shortcuts

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