stkvbuffer

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderSize int = 16 // 0xFEDCBA98 chunkSize4 dataSize8
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BufferStat

type BufferStat struct {
	FreeChunkNum  int
	UsedChunkNum  int
	FreeDataSize  int
	UsedDataSize  int
	CanotUseSize  int //浪费的空间
	KVCount       int
	AvgKVUseChunk int     //kv平均占用块数
	AvgKVUseSize  int     //kv平均占用空间大小
	AvalidUsePer  float64 //空间有效利用率
}

type Chunk

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

type EvictCallback

type EvictCallback func(key interface{}, value interface{})

EvictCallback is used to get a callback when a cache entry is evicted

type FuncLruDel

type FuncLruDel func(key string, val string)

type KVBuffer

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

Buffer implements a kv buffer.

func NewKVBuffer

func NewKVBuffer(data []byte, chunkSize int) (*KVBuffer, error)

func NewLRUKVBuffer

func NewLRUKVBuffer(data []byte, chunkSize int, onLruDel FuncLruDel) (*KVBuffer, error)

NewBuffer constructs a Buffer.

func (*KVBuffer) Del

func (b *KVBuffer) Del(k string) bool

func (*KVBuffer) Get

func (b *KVBuffer) Get(k string) (string, bool)

func (*KVBuffer) Keys

func (b *KVBuffer) Keys() []interface{}

func (*KVBuffer) Set

func (b *KVBuffer) Set(key, val string) error

func (*KVBuffer) Stat

func (b *KVBuffer) Stat() BufferStat

type LRU

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

LRU implements a non-thread safe fixed size LRU cache

func NewLRU

func NewLRU(size int, onEvict EvictCallback) (*LRU, error)

NewLRU constructs an LRU of the given size

func (*LRU) Add

func (c *LRU) Add(key, value interface{}) (evicted bool)

Add adds a value to the cache. Returns true if an eviction occurred.

func (*LRU) Contains

func (c *LRU) Contains(key interface{}) (ok bool)

Contains checks if a key is in the cache, without updating the recent-ness or deleting it for being stale.

func (*LRU) Get

func (c *LRU) Get(key interface{}) (value interface{}, ok bool)

Get looks up a key's value from the cache.

func (*LRU) GetOldest

func (c *LRU) GetOldest() (key, value interface{}, ok bool)

GetOldest returns the oldest entry

func (*LRU) Keys

func (c *LRU) Keys() []interface{}

Keys returns a slice of the keys in the cache, from oldest to newest.

func (*LRU) Len

func (c *LRU) Len() int

Len returns the number of items in the cache.

func (*LRU) Peek

func (c *LRU) Peek(key interface{}) (value interface{}, ok bool)

Peek returns the key value (or undefined if not found) without updating the "recently used"-ness of the key.

func (*LRU) Purge

func (c *LRU) Purge()

Purge is used to completely clear the cache.

func (*LRU) Remove

func (c *LRU) Remove(key interface{}) (present bool)

Remove removes the provided key from the cache, returning if the key was contained.

func (*LRU) RemoveOldest

func (c *LRU) RemoveOldest() (key, value interface{}, ok bool)

RemoveOldest removes the oldest item from the cache.

func (*LRU) Resize

func (c *LRU) Resize(size int) (evicted int)

Resize changes the cache size.

type Node

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

func (*Node) GetKey

func (n *Node) GetKey() []byte

func (*Node) GetVal

func (n *Node) GetVal() []byte

Jump to

Keyboard shortcuts

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