rocksutil

package
Version: v0.0.0-...-8ca8523 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2018 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinUint = uint(0)
	MaxUint = ^MinUint

	MaxInt = int(MaxUint >> 1)
	MinInt = ^MaxInt
)

MaxUint, MinUint 的类型总是 uint 类型. MinInt, MaxInt 总是 int 类型. 仅当 unsafe.Sizeof(int) == Sizeof(uint) 时下面才是正确的. 感谢 go spec 指定: int, same size as uint

View Source
const (
	UintLen32 = 4
)

Variables

This section is empty.

Functions

func FindLastIntLess

func FindLastIntLess(val int, vals []int) int

在 vals 中找到并返回最后一个 < val 的元素的下标. 若不存在, 则返回 -1.

此时假设 vals 增序排列.

func U32varint

func U32varint(buf []byte) (uint32, int)

语义等同于 binary.Uvarint(), 除了返回的是 uint32 类型.

Types

type Cache

type Cache interface {
	EraseAll()
	Insert(key string, val interface{},
		charge int, deler func(key string, val interface{})) CacheHandle
	Lookup(key string) CacheHandle
	Release(handle CacheHandle)
	Erase(key string)
	NewId() int
}

func NewLRUCache

func NewLRUCache(capacity int) Cache

type CacheHandle

type CacheHandle interface {
	Value() interface{}
}

type Comparator

type Comparator interface {
	Compare(a, b []byte) int
	Name() string
	// 注意返回值可能与 start 公用内存.
	FindShortestSeparator(start []byte, limit []byte) []byte
	// 注意返回值可能与 start 公用内存.
	FindShortSuccessor(start []byte) []byte
}

Comparator 的实现需要做到 goroutine 安全.

func NewBytewiseComparator

func NewBytewiseComparator() Comparator

type EmptyIterator

type EmptyIterator struct {
}

func NewEmptyIterator

func NewEmptyIterator() EmptyIterator

func (EmptyIterator) Close

func (this EmptyIterator) Close() error

func (EmptyIterator) Key

func (this EmptyIterator) Key() []byte

func (EmptyIterator) Next

func (this EmptyIterator) Next()

func (EmptyIterator) Prev

func (this EmptyIterator) Prev()

func (EmptyIterator) Seek

func (this EmptyIterator) Seek(key []byte)

func (EmptyIterator) SeekToFirst

func (this EmptyIterator) SeekToFirst()

func (EmptyIterator) SeekToLast

func (this EmptyIterator) SeekToLast()

func (EmptyIterator) Status

func (this EmptyIterator) Status() error

func (EmptyIterator) Valid

func (this EmptyIterator) Valid() bool

func (EmptyIterator) Value

func (this EmptyIterator) Value() []byte

type Iterator

type Iterator interface {
	Close() error
	Valid() bool
	SeekToFirst()
	SeekToLast()
	Seek(key []byte)
	Next()
	Prev()
	Status() error
	/* Key(), Value() 返回迭代器当前位置对应的 key/value.

	调用者不应该修改返回值.

	返回值会一直有效直至下一次移动迭代器的位置 */
	Key() []byte
	Value() []byte
}
Iterator, 其对应的底层数据模型类似与 std::map. 对 Key(), Value() 返回值的解释权由底层实现所有.

Iterator 并不是 goroutine 安全, 即不要在多个 goroutine 上不加任何同步的前提下并行访问 Iterator.

Iterator 在不需要的时候应该调用其 Close() 接口来释放资源.

当对 Iterator 的遍历结束之后, 应该通过 Status() 来判断结束的原因. 若 Status() 返回 nil, 则表明是因为没有多余 的数据了; 若 Status() 返回非 nil, 则表明是由于底层实现出了错导致遍历结束了.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL