db

package
v0.0.0-...-50680d5 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package db string 类型命令实现

Index

Constants

View Source
const (
	OPT_ADD uint16 = iota
	OPT_DEL

	// 日志记录的请求头大小
	LOG_ENTRY_HEADER_SIZE = 10
)
View Source
const (
	STR_TYPE logType = iota
	LIST_TYPE
	// 日志文件的权限 111
	LOG_FILE_PERM = 0644
	// LOG_FILE_PREFIX 日志文件的前缀
	LOG_FILE_PREFIX = "kv.data"
)
View Source
const (
	DB_HOME_DIR_NAME  = "kvdb"
	LOG_FILE_MAX_SIZE = 512 << 20
)

DB_HOME_DIR_NAME 数据库存在的目录

Variables

View Source
var (
	// ErrWriteSizeNotEqual 写入数据大小不一致错误
	ErrWriteSizeNotEqual = errors.New("logfile: write size is not equal to entry size")

	LogType2FileName = map[logType]string{
		STR_TYPE: "string",
	}

	FileName2LogType = map[string]logType{
		"string": STR_TYPE,
	}
)

定义错误信息

View Source
var (
	ErrKeyNotFound = errors.New("key not found")
)

Functions

func Decode

func Decode(buf []byte) (*logEntry, error)

Decode 解码 buf 字节数组,返回 Entry

func DecodeHeader

func DecodeHeader(buf []byte) (*logEntry, error)

DecodeHeader 解码日志记录的头

func DefaultBitCaskDB

func DefaultBitCaskDB() *bitCaskDB

DefaultBitCaskDB 创建一个 bitCaskDB 实例

func NewBitCaskDB

func NewBitCaskDB(options *Options) *bitCaskDB

NewBitCaskDB 根据 Options 配置创建 bitCaskDB 实列

func NewLogEntry

func NewLogEntry(key, value string, optType uint16) *logEntry

NewLogEntry 创建一个日志记录

func NewLogFile

func NewLogFile(filePath string, logType logType) (lf *logFile, err error)

NewLogFile 根据目录和日志类型创建日志文件

func NewStrIndex

func NewStrIndex() *strIndex

NewStrIndex 实例化一个 strIndex

Types

type Options

type Options struct {
	// 数据库数据存放的目录
	DBDirPath string
	// 日志文件最大值 默认 512 MB
	LogFileMaxSize uint64
}

func DefaultOptions

func DefaultOptions() *Options

DefaultOptions 获取默认的配置选项

type RadixTree

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

RadixTree 基数树 所有数据存放的地方

func NewRadixTree

func NewRadixTree() *RadixTree

func (*RadixTree) Delete

func (art *RadixTree) Delete(key string) (val interface{}, updated bool)

func (*RadixTree) Get

func (art *RadixTree) Get(key string) interface{}

func (*RadixTree) Iterator

func (art *RadixTree) Iterator() rt.Iterator

func (*RadixTree) PrefixScan

func (art *RadixTree) PrefixScan(prefix string, count int) (keys [][]byte)

func (*RadixTree) Put

func (node *RadixTree) Put(key string, v Value) (oldVal interface{}, updated bool)

func (*RadixTree) Size

func (art *RadixTree) Size() int

type Value

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

Value 基数树 key 对应的 value

Jump to

Keyboard shortcuts

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