mirror of
https://github.com/taigrr/bitcask
synced 2025-01-18 04:03:17 -08:00
Makefile setup & key/value coherent datatypes & refactoring (#98)
* internal/data: comment exported functions * internal/data: make smaller codec exported api surface * make key and value sizes serializing bubble up to everything * Makefile setup & go mod tidy
This commit is contained in:
@@ -24,7 +24,7 @@ const (
|
||||
sizeSize = int64Size
|
||||
)
|
||||
|
||||
func readKeyBytes(r io.Reader, maxKeySize int) ([]byte, error) {
|
||||
func readKeyBytes(r io.Reader, maxKeySize uint32) ([]byte, error) {
|
||||
s := make([]byte, int32Size)
|
||||
_, err := io.ReadFull(r, s)
|
||||
if err != nil {
|
||||
@@ -87,7 +87,7 @@ func writeItem(item internal.Item, w io.Writer) error {
|
||||
}
|
||||
|
||||
// ReadIndex reads a persisted from a io.Reader into a Tree
|
||||
func readIndex(r io.Reader, t art.Tree, maxKeySize int) error {
|
||||
func readIndex(r io.Reader, t art.Tree, maxKeySize uint32) error {
|
||||
for {
|
||||
key, err := readKeyBytes(r, maxKeySize)
|
||||
if err != nil {
|
||||
|
||||
@@ -94,7 +94,7 @@ func TestReadCorruptedData(t *testing.T) {
|
||||
table := []struct {
|
||||
name string
|
||||
err error
|
||||
maxKeySize int
|
||||
maxKeySize uint32
|
||||
data []byte
|
||||
}{
|
||||
{name: "key-data-overflow", err: errKeySizeTooLarge, maxKeySize: 1024, data: overflowKeySize},
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type Indexer interface {
|
||||
Load(path string, maxkeySize int) (art.Tree, bool, error)
|
||||
Load(path string, maxkeySize uint32) (art.Tree, bool, error)
|
||||
Save(t art.Tree, path string) error
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ func NewIndexer() Indexer {
|
||||
|
||||
type indexer struct{}
|
||||
|
||||
func (i *indexer) Load(path string, maxKeySize int) (art.Tree, bool, error) {
|
||||
func (i *indexer) Load(path string, maxKeySize uint32) (art.Tree, bool, error) {
|
||||
t := art.New()
|
||||
|
||||
if !internal.Exists(path) {
|
||||
|
||||
Reference in New Issue
Block a user