rankdb

package module
v0.0.0-...-d94db1a Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

README

rankdb

fast rank k-v db like redis sortSet embedded in go.

Documentation

Index

Constants

View Source
const (
	IndexTypeHash = iota
	IndexTypeRedBlackTree
)
View Source
const (
	P        = 0.25
	MaxLevel = 32
)
View Source
const (
	OperationAnd = iota
	OperationOr
)
View Source
const (
	Red   = true
	Black = false
)
View Source
const (
	EQ = iota
	LIKE
)
View Source
const (
	INT = iota
	FLOAT
	STRING
	TIME
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AddIndex

type AddIndex struct {
	ColumnName  string
	ColumnValue interface{}
}

type CompareAble

type CompareAble interface {
	CompareTo(CompareAble) (int, error)
}

type Ele

type Ele struct {
	Score CompareAble
	Value interface{}
	// 根?
	RootEl bool
	// 到下一个的节点数量
	Span int
	// 记录属于哪一个节点的
	Node    *Node
	NextEle *Ele
	PreEle  *Ele
}

Ele 设计为双向链表

func NewEle

func NewEle(score CompareAble, val interface{}, node *Node, span int) *Ele

NewEle 创建一个新的Ele

func NewRootEle

func NewRootEle(node *Node) *Ele

NewRootEle 创建根Ele

type F64CompareAble

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

func NewF64CompareAble

func NewF64CompareAble(f64 float64) F64CompareAble

func (F64CompareAble) CompareTo

func (f F64CompareAble) CompareTo(f64 CompareAble) (int, error)

type Indexer

type Indexer struct {
	// 字段的名称
	ColumnValue interface{}
	// 字段所对应的 结构体的指针
	Pointers []*PointersIndex
}

Indexer 实现了从sort set value中提取字段作为索引

type IndexerHash

type IndexerHash struct {
	IdxHash map[string]*OneIndexer
}

func NewIndexerHash

func NewIndexerHash() *IndexerHash

type M

type M struct {
	Score      CompareAble
	Member     interface{}
	AddIndexes []*AddIndex
}

type Node

type Node struct {
	RootEle *Ele
	EleNum  int
	Level   int
	// 记录走过的上层的元素,方便插入后更改
	PreviewNodes []*Ele
}

func NewRootNode

func NewRootNode(level int) *Node

NewRootNode 创建根Node

func (*Node) HasEle

func (n *Node) HasEle() bool

HasEle 是否有节点

type OneIndexer

type OneIndexer struct {
	IndexType int

	FullIndexer []*Indexer
	// contains filtered or unexported fields
}

OneIndexer 一条索引的全部记录

func NewOneIndexer

func NewOneIndexer() *OneIndexer

func (*OneIndexer) GetMemberLikeByStr

func (o *OneIndexer) GetMemberLikeByStr(likeStr string) canCompareRanElements

GetMemberLikeByStr 模糊搜索

func (*OneIndexer) StoreColumnValueExit

func (o *OneIndexer) StoreColumnValueExit(check interface{}) int

func (*OneIndexer) ZipperAdd

func (o *OneIndexer) ZipperAdd(columnValues, pointer interface{}, rank int64)

type Operation

type Operation struct {
	ConnectionSymbol int // 连接符号 AND, OR
}

type PointersIndex

type PointersIndex struct {
	Pointer interface{}
	Rank    int64 // 再sortSet中的排序
}

PointersIndex 索引的Pointers的再sortSet中的排名

type QueryBuilder

type QueryBuilder struct {
	filter.Filter
	Level         int // 层级
	InnerBuilders []*QueryBuilder
	FatherBuilder *QueryBuilder // 上级节点
}

QueryBuilder 构建一颗查询的多叉树

type QueryBuilders

type QueryBuilders struct {
	QueryBuilders []*QueryBuilder
	MaxLevel      int // 当前树有几层
}

func (*QueryBuilders) LevelBfs

func (q *QueryBuilders) LevelBfs() [][]*QueryBuilder

type Queue

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

Queue represents a single instance of the queue data structure.

func NewQueue

func NewQueue() *Queue

New constructs and returns a new Queue.

func (*Queue) Add

func (q *Queue) Add(elem *QueryBuilder)

Add puts an element on the end of the queue.

func (*Queue) Get

func (q *Queue) Get(i int) *QueryBuilder

Get returns the element at index i in the queue. If the index is invalid, the call will panic. This method accepts both positive and negative index values. Index 0 refers to the first element, and index -1 refers to the last.

func (*Queue) Length

func (q *Queue) Length() int

Length returns the number of elements currently stored in the queue.

func (*Queue) Peek

func (q *Queue) Peek() *QueryBuilder

Peek returns the element at the head of the queue. This call panics if the queue is empty.

func (*Queue) Remove

func (q *Queue) Remove() *QueryBuilder

Remove removes and returns the element from the front of the queue. If the queue is empty, the call will panic.

type RdbNode

type RdbNode struct {
	Key         int
	Value       interface{}
	Left, Right *RdbNode
	N           int
	Color       bool
}

func NewRdbNode

func NewRdbNode(key int, value interface{}, color bool) *RdbNode

func (*RdbNode) Size

func (r *RdbNode) Size() int

type SelectIndex

type SelectIndex struct {
	ColumnName string      // 列名称
	Operation  int         // 操作 EQ LIKE ...
	SearchVal  interface{} // 查找的列的值
	ColumnType int         // 列的值的类型 支持 INT FLOAT STRING TIME
}

SelectIndex 搜索索引条件

func NewSelectIndex

func NewSelectIndex() *SelectIndex

type SkipList

type SkipList struct {
	Nodes []*Node
	// contains filtered or unexported fields
}

func NewSkl

func NewSkl() *SkipList

NewSkl 新建skl

func (SkipList) Get

func (s SkipList) Get(score CompareAble) interface{}

func (*SkipList) Insert

func (s *SkipList) Insert(score CompareAble, value interface{}) *Ele

func (*SkipList) Print

func (s *SkipList) Print()

type SortedSet

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

SortedSet sorted set struct

func New

func New() *SortedSet

New create a new sorted set.

func (*SortedSet) ZAdd

func (z *SortedSet) ZAdd(key string, score CompareAble, member string)

ZAdd Adds the specified member with the specified score to the sorted set stored at key.

func (*SortedSet) ZCard

func (z *SortedSet) ZCard(key string) int

ZCard returns the sorted set cardinality (number of elements) of the sorted set stored at key.

func (*SortedSet) ZClear

func (z *SortedSet) ZClear(key string)

ZClear clear the key in zset.

func (*SortedSet) ZGetByRank

func (z *SortedSet) ZGetByRank(key string, rank int) (val []interface{})

ZGetByRank 根据排名获取member及分值信息,从小到大排列遍历,即分值最低排名为0,依次类推 Get the member at key by rank, the rank is ordered from lowest to highest. The rank of lowest is 0 and so on.

func (*SortedSet) ZKeyExists

func (z *SortedSet) ZKeyExists(key string) bool

ZKeyExists check if the key exists in zset.

func (*SortedSet) ZRange

func (z *SortedSet) ZRange(key string, start, stop int) []interface{}

ZRange returns the specified range of elements in the sorted set stored at <key>.

func (*SortedSet) ZRangeWithScores

func (z *SortedSet) ZRangeWithScores(key string, start, stop int) []interface{}

ZRangeWithScores returns the specified range of elements in the sorted set stored at <key>.

func (*SortedSet) ZRank

func (z *SortedSet) ZRank(key, member string) int64

ZRank returns the rank of member in the sorted set stored at key, with the scores ordered from low to high. The rank (or index) is 0-based, which means that the member with the lowest score has rank 0.

func (*SortedSet) ZRem

func (z *SortedSet) ZRem(key, member string) bool

ZRem removes the specified members from the sorted set stored at key. Non existing members are ignored. An error is returned when key exists and does not hold a sorted set.

func (*SortedSet) ZRevGetByRank

func (z *SortedSet) ZRevGetByRank(key string, rank int) (val []interface{})

ZRevGetByRank get the member at key by rank, the rank is ordered from highest to lowest. The rank of highest is 0 and so on.

func (*SortedSet) ZRevRange

func (z *SortedSet) ZRevRange(key string, start, stop int) []interface{}

ZRevRange returns the specified range of elements in the sorted set stored at key. The elements are considered to be ordered from the highest to the lowest score. Descending lexicographical order is used for elements with equal score.

func (*SortedSet) ZRevRangeWithScores

func (z *SortedSet) ZRevRangeWithScores(key string, start, stop int) []interface{}

ZRevRange returns the specified range of elements in the sorted set stored at key. The elements are considered to be ordered from the highest to the lowest score. Descending lexicographical order is used for elements with equal score.

func (*SortedSet) ZRevRank

func (z *SortedSet) ZRevRank(key, member string) int64

ZRevRank returns the rank of member in the sorted set stored at key, with the scores ordered from high to low. The rank (or index) is 0-based, which means that the member with the highest score has rank 0.

func (*SortedSet) ZRevScoreRange

func (z *SortedSet) ZRevScoreRange(key string, max, min CompareAble) (val []interface{})

ZRevScoreRange returns all the elements in the sorted set at key with a score between max and min (including elements with score equal to max or min). In contrary to the default ordering of sorted sets, for this command the elements are considered to be ordered from high to low scores.

func (*SortedSet) ZScore

func (z *SortedSet) ZScore(key string, member string) (ok bool, score CompareAble)

ZScore returns the score of member in the sorted set at key.

func (*SortedSet) ZScoreRange

func (z *SortedSet) ZScoreRange(key string, min, max CompareAble) (val []interface{})

ZScoreRange returns all the elements in the sorted set at key with a score between min and max (including elements with score equal to min or max). The elements are considered to be ordered from low to high scores.

type SortedSetNode

type SortedSetNode struct {
	Lock     sync.Mutex
	Indexers *IndexerHash
	// contains filtered or unexported fields
}

SortedSetNode node of sorted set

func NewSortSet

func NewSortSet() *SortedSetNode

func (*SortedSetNode) Add

func (s *SortedSetNode) Add(score CompareAble, value interface{}, indexers []*AddIndex)

Add score 分值,value 保存的对象, indexers map 的key 保存的列名称,也就是value对象里面的某个字段的名称 map 的 value 保存的value对象里面 key 对应的值。 这里让用户手动添加indexers 而不是利用反射是为了提高性能。减少反射所耗费的性能。 TODO: 提供一个自动检查的方法。利用Tag标记。

func (*SortedSetNode) GetByIndex

func (s *SortedSetNode) GetByIndex(selectIndexers []*SelectIndex, start, stop int64) []interface{}

GetByIndex 传入搜索条件,查询指定key的结果。返回顺序按照此key的 score 排列

type StrCompareAble

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

func NewStrCompareAble

func NewStrCompareAble(str string) StrCompareAble

func (StrCompareAble) CompareTo

func (s StrCompareAble) CompareTo(str CompareAble) (int, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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