memdb

package
v0.0.0-...-354a747 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMaxLevel = 32

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

in-memory key/value database

func (*DB) Get

func (db *DB) Get(key []byte) (value []byte, err error)

func (*DB) Put

func (db *DB) Put(key, value []byte) error

type Iterator

type Iterator interface {
	// Next returns true if the iterator contains subsequent elements
	// and advances its state to the next element if that is possible.
	Next() (ok bool)

	// Previous returns true if the iterator contains previous elements
	// and rewinds its state to the previous element if that is possible.
	Previous() (ok bool)

	// Key returns the current key.
	Key() interface{}

	// Value returns the current value.
	Value() interface{}

	// Seek reduces iterative seek costs for searching forward into the Skip List
	// by remarking the range of keys over which it has scanned before. If the
	// requested key occurs prior to the point, the Skip List will start searching
	// as a safeguard.  It returns true if the key is within the known range of the list.
	Seek(key interface{}) (ok bool)

	// Close this iterator to reap resources associated with it.  While not
	// strictly required, it will provide extra hints for the garbage collector.
	Close()
}

Iterator is an interface that you can use to iterate through the skip list (in its entirety or fragments).

type Ordered

type Ordered interface {
	LessThan(other Ordered) bool
}

Ordered is an interface which can be linearly ordered by the LessThan method, whereby this instance is deemed to be less than other. Additionally, Ordered instances should behave properly when compared using == and !=.

type SkipList

type SkipList struct {

	// max level
	MaxLevel int
	// contains filtered or unexported fields
}

Skip list that maintains an ordered collection of key-value pairs

func New

func New() *SkipList

New returns a new SkipList. Its keys must implement the Ordered interface.

func NewCustomSkipList

func NewCustomSkipList(lessThan func(l, r interface{}) bool) *SkipList

---

func NewIntSkipList

func NewIntSkipList() *SkipList

returns a SkipList that accepts int keys.

func NewStringSkipList

func NewStringSkipList() *SkipList

returns a SkipList that accepts string keys.

func (*SkipList) Delete

func (s *SkipList) Delete(key interface{}) (interface{}, bool)

Delete

func (*SkipList) Get

func (s *SkipList) Get(key interface{}) (interface{}, bool)

Get get the the value associated with key in s. if not exists, return nil

func (*SkipList) Iterator

func (s *SkipList) Iterator() Iterator

Iterator returns an Iterator that will go through all elements s.

func (*SkipList) Put

func (s *SkipList) Put(key, value interface{})

Put put the value associated with key in s.

func (*SkipList) Seek

func (s *SkipList) Seek(key interface{}) Iterator

Seek

Jump to

Keyboard shortcuts

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