shs

package module
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PageSize        = 4096
	PageHeaderSize  = 16
	FileTrailerSize = 8
)

Variables

View Source
var (
	ErrKeyNotFound    = fmt.Errorf("key not found")
	ErrKeyEmpty       = fmt.Errorf("key cannot be empty")
	ErrRecordTooLarge = fmt.Errorf("key or value is too large, the size cannot exceed 4056")
)

Functions

This section is empty.

Types

type BTreeIndex added in v0.0.5

type BTreeIndex btree.Map[string, uint64]

func NewBTreeIndex added in v0.0.5

func NewBTreeIndex() *BTreeIndex

func (*BTreeIndex) Delete added in v0.0.5

func (B *BTreeIndex) Delete(key []byte) error

func (*BTreeIndex) Get added in v0.0.5

func (B *BTreeIndex) Get(key []byte) (uint64, error)

func (*BTreeIndex) Iterator added in v0.0.5

func (B *BTreeIndex) Iterator() iter.Seq2[[]byte, uint64]

func (*BTreeIndex) Set added in v0.0.5

func (B *BTreeIndex) Set(key []byte, value uint64) error

type DataPage

type DataPage struct {
	PageID          uint64   // 页号,页号是PageHeader的一部分
	UserRecordsSize uint64   // 用户记录总大小,是PageHeader的一部分
	UserRecords     []Record // 用户记录
	FileTrailer     [8]byte  // crc
}

DataPage 表示一个数据页

type DefaultIndex

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

func NewDefaultIndex added in v0.0.6

func NewDefaultIndex() *DefaultIndex

func (*DefaultIndex) Delete

func (d *DefaultIndex) Delete(key []byte) error

func (*DefaultIndex) Get

func (d *DefaultIndex) Get(key []byte) (uint64, error)

func (*DefaultIndex) Iterator

func (d *DefaultIndex) Iterator() iter.Seq2[[]byte, uint64]

func (*DefaultIndex) Set

func (d *DefaultIndex) Set(key []byte, value uint64) error

type Index

type Index interface {
	Get(key []byte) (uint64, error)
	Set(key []byte, value uint64) error
	Delete(key []byte) error
	Iterator() iter.Seq2[[]byte, uint64]
}

type Options

type Options struct {
	DirPath   string
	DataIndex Index
}

type RBTreeIndex added in v0.0.6

type RBTreeIndex rbtree.RbTree[string, uint64]

func NewRBTreeIndex added in v0.0.6

func NewRBTreeIndex() *RBTreeIndex

func (*RBTreeIndex) Delete added in v0.0.6

func (R *RBTreeIndex) Delete(key []byte) error

func (*RBTreeIndex) Get added in v0.0.6

func (R *RBTreeIndex) Get(key []byte) (uint64, error)

func (*RBTreeIndex) Iterator added in v0.0.6

func (R *RBTreeIndex) Iterator() iter.Seq2[[]byte, uint64]

func (*RBTreeIndex) Set added in v0.0.6

func (R *RBTreeIndex) Set(key []byte, value uint64) error

type Record

type Record struct {
	Key   []byte
	Value []byte
}

Record 表示一个记录

type SkipListIndex added in v0.0.6

type SkipListIndex skiplist.Skiplist[string, uint64]

func NewSkipListIndex added in v0.0.6

func NewSkipListIndex() *SkipListIndex

func (*SkipListIndex) Delete added in v0.0.6

func (s *SkipListIndex) Delete(key []byte) error

func (*SkipListIndex) Get added in v0.0.6

func (s *SkipListIndex) Get(key []byte) (uint64, error)

func (*SkipListIndex) Iterator added in v0.0.6

func (s *SkipListIndex) Iterator() iter.Seq2[[]byte, uint64]

func (*SkipListIndex) Set added in v0.0.6

func (s *SkipListIndex) Set(key []byte, value uint64) error

type SortUserRecordByKey added in v0.0.3

type SortUserRecordByKey []Record

func (SortUserRecordByKey) Len added in v0.0.3

func (s SortUserRecordByKey) Len() int

func (SortUserRecordByKey) Less added in v0.0.3

func (s SortUserRecordByKey) Less(i, j int) bool

func (SortUserRecordByKey) Swap added in v0.0.3

func (s SortUserRecordByKey) Swap(i, j int)

type StorageEngine

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

func NewStorageEngine

func NewStorageEngine(opt Options) (*StorageEngine, error)

NewStorageEngine 创建一个新的存储引擎实例,并从磁盘加载数据

func (*StorageEngine) Close

func (se *StorageEngine) Close() error

func (*StorageEngine) Delete

func (se *StorageEngine) Delete(key []byte) error

Delete 删除一个键值对,并保存到磁盘

func (*StorageEngine) Get

func (se *StorageEngine) Get(key []byte) ([]byte, error)

Get 获取一个键对应的值

func (*StorageEngine) Insert

func (se *StorageEngine) Insert(key, value []byte) error

Insert 插入一个键值对,并保存到磁盘

func (*StorageEngine) Modify

func (se *StorageEngine) Modify(key, value []byte) error

Modify 修改一个键值对

type WalRecord

type WalRecord struct {
	Type   WalRecordType
	Key    []byte
	PageID uint64
}

type WalRecordType

type WalRecordType uint8
const (
	WalOpInsert WalRecordType = iota
	WalOpDelete
)

Jump to

Keyboard shortcuts

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