types

package
v0.0.0-...-689788a Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ValueTypeList = iota
	ValueTypeString
	ValueTypeSet
	ValueTypeZSet
)
View Source
const (
	ValueTypeFancyList   = "list"
	ValueTypeFancyString = "string"
	ValueTypeFancySet    = "set"
	ValueTypeFancyZSet   = "zset"
)
View Source
const SKIPLIST_MAXLEVEL = 32 /* Should be enough for 2^64 elements */
View Source
const SKIPLIST_P = 0.25 /* Skiplist P = 1/4 */

Variables

This section is empty.

Functions

This section is empty.

Types

type GetRangeOptions

type GetRangeOptions struct {
	Reverse        bool // Start iterating from the back
	Offset         int  // How many nodes to skip
	Limit          int  // limit the max nodes to return
	StartExclusive bool // exclude start value, so it search in interval (start, end] or (start, end)
	StopExclusive  bool // exclude end value, so it search in interval [start, end) or (start, end)
}

TODO: Add reverse, offset

func DefaultRangeOptions

func DefaultRangeOptions() GetRangeOptions

type Item

type Item interface {
	// The pointer to the value.
	Value() interface{}

	// The id of the type of the Item.
	// This need to be constant for the type because it is
	// used when de-/serializing item from/to disk.
	Type() uint64
	TypeFancy() string
}

The item interface. An item is the value of a key.

type List

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

func ListUnmarshal

func ListUnmarshal(data []byte) (*List, bool)

func NewList

func NewList() *List

func NewListFromArr

func NewListFromArr(arr []string) *List

func (*List) ForEachF

func (list *List) ForEachF(f func(a string))

TODO: For now we only store strings so this should be enough.

func (*List) LIndex

func (l *List) LIndex(index int) (string, bool)

LIndex see redis doc

func (*List) LInsert

func (l *List) LInsert(isBefore bool, pivot, value string) int

LInsert see redis doc

func (*List) LPop

func (l *List) LPop() (string, bool)

RPop pops the front of the list and returns the value. Returns true if its valid, false otherwise.

func (*List) LPush

func (l *List) LPush(values ...string) int

LPush returns the length of the list after the push operation.

func (*List) LRange

func (l *List) LRange(start int, end int) []string

LRange see redis doc

func (*List) LRem

func (l *List) LRem(count int, value string) int

LRem see redis doc

func (*List) LSet

func (l *List) LSet(index int, value string) error

LSet see redis doc

func (*List) LTrim

func (l *List) LTrim(start int, end int) bool

LTrim see redis docs - returns true if list is now emptied so the key can be deleted.

func (*List) Len

func (l *List) Len() int

Len returns number of elements.

func (*List) Marshal

func (s *List) Marshal() ([]byte, error)

func (*List) RPop

func (l *List) RPop() (string, bool)

RPop pops the back of the list and returns the value. Returns true if its valid, false otherwise.

func (*List) RPush

func (l *List) RPush(values ...string) int

RPush returns the length of the list after the push operation.

func (List) Type

func (l List) Type() uint64

func (List) TypeFancy

func (l List) TypeFancy() string

func (*List) Value

func (l *List) Value() interface{}

type Score

type Score int // the type of score

type SerdeZSet

type SerdeZSet struct {
	Keys   []string  `json:"keys"`
	Scores []float64 `json:"scores"`
}

type Set

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

func NewSetEmpty

func NewSetEmpty() *Set

func NewSetFromMap

func NewSetFromMap(value map[string]struct{}) *Set

func SetUnmarshal

func SetUnmarshal(data []byte) (*Set, bool)

func (*Set) AddMember

func (s *Set) AddMember(keys ...string)

func (*Set) Diff

func (s *Set) Diff(o *Set) *Set

Diff returns a new Set that is a diff of both sets.

func (*Set) Exists

func (s *Set) Exists(key string) bool

func (*Set) ForEachF

func (s *Set) ForEachF(f func(a string) bool)

ForEachF loops over the set calling f on each elements until it returns false.

func (*Set) GetMembers

func (s *Set) GetMembers() []string

func (*Set) GetRandomMember

func (s *Set) GetRandomMember() *string

GetRandomMeber returns a random member from the set.

func (*Set) Intersect

func (s *Set) Intersect(o *Set) *Set

Intersect returns a new Set that is an intersection of both sets. TODO: Better intersection algorithm?

func (*Set) Len

func (s *Set) Len() int

func (*Set) Marshal

func (s *Set) Marshal() ([]byte, error)

func (*Set) Pop

func (s *Set) Pop() *string

Pop removes a random key from the set.

func (*Set) RemoveMember

func (s *Set) RemoveMember(key string) bool

RemoveMember removes the given member from the set. Returns true if the key exists. False otherwise.

func (*Set) ToZSet

func (s *Set) ToZSet() *ZSet

func (*Set) Type

func (l *Set) Type() uint64

func (*Set) TypeFancy

func (l *Set) TypeFancy() string

func (*Set) Union

func (s *Set) Union(o *Set) *Set

Union returns a new Set that is a union of both sets.

func (*Set) Value

func (s *Set) Value() interface{}

type SortedSet

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

func NewSortedSet

func NewSortedSet() *SortedSet

NewSortedSet returns a new empty sorted set

func (*SortedSet) AddOrUpdate

func (ss *SortedSet) AddOrUpdate(key string, score float64) bool

Add an element into the sorted set with specific key / value / score. If the element is added, this method returns true; otherwise false means updated.

Time complexity: O(log(N)) with high probability

func (*SortedSet) FindNodeByLex

func (ss *SortedSet) FindNodeByLex(key string) (*SortedSetNode, int)

FindNodeByLex returns the node with the requested key

Time complexity: O(log(N)) with high probability

func (*SortedSet) FindRankOfKey

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

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: O(log(N)) with high probability

func (*SortedSet) GetByIndex

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

Get node by index.

If remove is true, the returned nodes are removed If node is not found at specific rank, nil is returned

Time complexity: O(log(N))

func (*SortedSet) GetByKey

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

Get node by key

If node is not found, nil is returned Time complexity: O(1)

func (*SortedSet) GetRangeByIndex

func (ss *SortedSet) GetRangeByIndex(start int, end int, options GetRangeOptions) []*SortedSetNode

GetRangeByIndex returns array of nodes within specific index range [start, end]. The given start and end must be a valid rank-based index which can be obtained from 'SanitizeRank'.

If start is greater than end, the returned array is in reserved order.

Time complexity: O(log(N)) with high probability

func (*SortedSet) GetRangeByLex

func (ss *SortedSet) GetRangeByLex(start string, end string, options GetRangeOptions) []*SortedSetNode

GetRangeByLex returns an array of nodes that satisfy the given score range.

Time complexity: O(log(N))

func (*SortedSet) GetRangeByRank

func (ss *SortedSet) GetRangeByRank(start int, end int, options GetRangeOptions) []*SortedSetNode

GetRangeByRank returns array of nodes within specific rank range [start, end]. If start is greater than end, returns an empty array.

Time complexity: O(log(N)) with high probability

func (*SortedSet) GetRangeByScore

func (ss *SortedSet) GetRangeByScore(start float64, end float64, options GetRangeOptions) []*SortedSetNode

GetRangeByScore returns an array of nodes that satisfy the given score range.

Time complexity: O(log(N))

func (*SortedSet) Len

func (ss *SortedSet) Len() int

Get the number of elements

func (*SortedSet) PeekMax

func (ss *SortedSet) PeekMax() *SortedSetNode

PeekMax returns the element with the highest score if it exists.

Time Complexity : O(1)

func (*SortedSet) PeekMin

func (ss *SortedSet) PeekMin() *SortedSetNode

PeekMin returns the element with the lowest score if it exists. Otherwise it returns nil.

Time complexity: O(1)

func (*SortedSet) PopMax

func (ss *SortedSet) PopMax() *SortedSetNode

PopMin returns the element with the highest score if it exists and removes it. Otherwise it returns nil.

Time complexity: O(log(N)) with high probability

func (*SortedSet) PopMin

func (ss *SortedSet) PopMin() *SortedSetNode

PopMin returns the element with the lowest score if it exists and removes it. Otherwise it returns nil.

Time complexity: O(log(N)) with high probability

func (*SortedSet) Remove

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

Delete element specified by key

Time complexity: O(log(N)) with high probability

func (*SortedSet) RemoveByRank

func (ss *SortedSet) RemoveByRank(rank int) *SortedSetNode

Delete element specified by rank

Time complexity: O(log(N)) with high probability

func (*SortedSet) SanitizeIndex

func (ss *SortedSet) SanitizeIndex(start int, end int, reverse bool) (int, int)

SanitizeIndex sanitizes the given 0-based range. Returns (1,-1) if its an empty range. TODO: This is such a hack. Reimplement so we don't even need this whole mess.

type SortedSetLevel

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

type SortedSetNode

type SortedSetNode struct {
	Key   string  // unique key of this node
	Score float64 // score to determine the order of this node in the set
	// contains filtered or unexported fields
}

Node in skip list

type String

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

func NewString

func NewString(value string) *String

func StringUnmarshal

func StringUnmarshal(data []byte) (*String, bool)

func (*String) AsBytes

func (s *String) AsBytes() []byte

func (*String) AsString

func (s *String) AsString() string

func (*String) Get

func (s *String) Get(idx int) byte

func (*String) Len

func (s *String) Len() int

func (*String) Marshal

func (s *String) Marshal() ([]byte, error)

func (*String) SubString

func (s *String) SubString(start, end int) string

func (*String) Type

func (l *String) Type() uint64

func (*String) TypeFancy

func (l *String) TypeFancy() string

func (*String) Value

func (s *String) Value() interface{}

type ZSet

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

func NewZSet

func NewZSet() *ZSet

func NewZSetFromSs

func NewZSetFromSs(value *SortedSet) *ZSet

func ZSetUnmarshal

func ZSetUnmarshal(data []byte) (*ZSet, bool)

func (*ZSet) AddOrUpdate

func (ss *ZSet) AddOrUpdate(key string, score float64) bool

func (*ZSet) Diff

func (s *ZSet) Diff(o *ZSet) *ZSet

Diff returns a new Set that is a union of both sets.

func (*ZSet) FindNodeByLex

func (ss *ZSet) FindNodeByLex(key string) (*SortedSetNode, int)

func (*ZSet) GetByKey

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

func (*ZSet) GetRangeByRank

func (ss *ZSet) GetRangeByRank(start int, end int, options GetRangeOptions) []*SortedSetNode

func (*ZSet) Intersect

func (s *ZSet) Intersect(o *ZSet, mode int, weight float64) *ZSet

Intersect returns a new Set that is a intersection of both sets.

func (ZSet) Len

func (s ZSet) Len() int

func (*ZSet) Marshal

func (s *ZSet) Marshal() ([]byte, error)

func (*ZSet) Remove

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

func (*ZSet) ToSet

func (s *ZSet) ToSet() *Set

Converts a ZSet to a Set.

func (ZSet) Type

func (l ZSet) Type() uint64

func (ZSet) TypeFancy

func (l ZSet) TypeFancy() string

func (*ZSet) Union

func (s *ZSet) Union(o *ZSet, mode int, weight float64) *ZSet

Union returns a new ZSet that is a union of both sets.

func (*ZSet) Value

func (s *ZSet) Value() interface{}

Jump to

Keyboard shortcuts

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