index

package
v0.0.0-...-47e3ba9 Latest Latest
Warning

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

Go to latest
Published: May 10, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Example
skl := NewSkipList()
val := []byte("test_val")

skl.Put([]byte("ec"), val)
skl.Put([]byte("dc"), val)
skl.Put([]byte("ac"), val)
skl.Put([]byte("ae"), val)
skl.Put([]byte("fe"), val)

ok := skl.Exist([]byte("ac"))
fmt.Println(ok)

skl.Remove([]byte("ec"))

ele := skl.Get([]byte("dc"))
fmt.Printf("%+v", ele)

pre := skl.FindPrefix([]byte("a"))
fmt.Printf("%+v", pre)
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Element

type Element struct {
	Node
	// contains filtered or unexported fields
}

Element element is the data stored.

func (*Element) Key

func (e *Element) Key() []byte

Key the key of the Element.

func (*Element) Next

func (e *Element) Next() *Element

Next the first-level index of the skip list is the original data, which is arranged in an orderly manner. A linked list of all data in series can be obtained according to the Next method.

func (*Element) SetValue

func (e *Element) SetValue(val interface{})

SetValue set the element value.

func (*Element) Value

func (e *Element) Value() interface{}

Value the value of the Element.

type Indexer

type Indexer struct {
	Meta   *storage.Meta // metadata info.
	FileId uint32        // the file id of storing the data.
	Offset int64         // entry data query start position.
}

Indexer the data index info, stored in skip list.

type Node

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

Node the skip list node.

type SkipList

type SkipList struct {
	Node

	Len int
	// contains filtered or unexported fields
}

SkipList define the skip list.

func NewSkipList

func NewSkipList() *SkipList

NewSkipList create a new skip list.

func (*SkipList) Exist

func (t *SkipList) Exist(key []byte) bool

Exist check if exists the key in skl.

func (*SkipList) FindPrefix

func (t *SkipList) FindPrefix(prefix []byte) *Element

FindPrefix find the first element that matches the prefix.

func (*SkipList) Foreach

func (t *SkipList) Foreach(fun handleEle)

Foreach iterate all elements in the skip list.

func (*SkipList) Front

func (t *SkipList) Front() *Element

Front first element. Get the head element of skl, and get all data by traversing backward.

e := list.Front()
for p := e; p != nil; p = p.Next() {
	//do something with Element p
}

func (*SkipList) Get

func (t *SkipList) Get(key []byte) *Element

Get find value by the key, returns nil if not found.

func (*SkipList) Put

func (t *SkipList) Put(key []byte, value interface{}) *Element

Put an element into skip list, replace the value if key already exists.

func (*SkipList) Remove

func (t *SkipList) Remove(key []byte) *Element

Remove element by the key.

Jump to

Keyboard shortcuts

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