sortedset

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2025 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Item

type Item struct {
	btree.Item
	Score  float64
	Member string
}

Item represents a member of a sorted set. It includes a score and a member.

func (*Item) Less

func (a *Item) Less(b btree.Item) bool

Less compares two Items. Required by the btree.Item interface.

type Set

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

is a sorted set data structure that stores members with associated scores.

func DeserializeSortedSet

func DeserializeSortedSet(buf *bytes.Reader) (*Set, error)

func FromObject

func FromObject(obj *object.Obj) (value *Set, err []byte)

func New

func New() *Set

New creates a new .

func (*Set) CountInRange

func (ss *Set) CountInRange(minVal, maxVal float64) int

Iterate over elements in the B-Tree with scores in the [min, max] range

func (*Set) Get

func (ss *Set) Get(member string) (float64, bool)

func (*Set) GetMin

func (ss *Set) GetMin(count int) []string

GetMin returns the first 'count' key-value pairs (member and score) with the minimum scores and removes those items from the sorted set.

func (*Set) GetRange

func (ss *Set) GetRange(
	start, stop int,
	withScores bool,
	reverse bool,
) []string

GetRange returns a slice of members with scores between min and max, inclusive. it returns the members in ascending order if reverse is false, and descending order if reverse is true. If withScores is true, the members will be returned with their scores.

func (*Set) Len

func (ss *Set) Len() int

func (*Set) PopMax

func (ss *Set) PopMax(count int) []string

This func is used to remove the maximum element from the sortedset. It takes count as an argument which tells the number of elements to be removed from the sortedset.

func (*Set) PopMin added in v1.0.6

func (ss *Set) PopMin(count int) []string

This func is used to remove the minimum element from the sortedset. It takes count as an argument which tells the number of elements to be removed from the sortedset.

func (*Set) RankWithScore

func (ss *Set) RankWithScore(member string, reverse bool) (rank int64, score float64)

func (*Set) Remove

func (ss *Set) Remove(member string) bool

Remove removes a member from the and returns true if the member was removed, false if it did not exist.

func (*Set) Serialize

func (ss *Set) Serialize(buf *bytes.Buffer) error

func (*Set) Upsert

func (ss *Set) Upsert(score float64, member string) bool

Add adds a member with a score to the and returns true if the member was added, false if it already existed.

Jump to

Keyboard shortcuts

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