heapstore

package
v0.0.0-...-6cecc6f Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const HeapBlockDataSize = 64 // Bytes
View Source
const HeapBlockSize = 64 + 8 // Bytes

Variables

View Source
var LOGGER = logger.New()

Functions

This section is empty.

Types

type HeapBlock

type HeapBlock struct {
	Data [HeapBlockDataSize]byte
	Next ID
}

HeapBlock represents a block in the heap file. This block stores 64 bytes of data with a pointer to the next block. This pointer is the position of the block in the file.

type HeapStore

type HeapStore struct {
	File     *os.File
	Position int64
}

HeapStore is an abstraction over the binary file that holds dynamically sized data in the database

func (*HeapStore) Close

func (h *HeapStore) Close() error

Close closes the file held by the HeapStore

func (*HeapStore) Init

func (h *HeapStore) Init(file *os.File, position int64)

Init initialises a HeapStore

func (*HeapStore) Read

func (h *HeapStore) Read(id ID) ([]byte, error)

Read starts reading blocks from id does so till it reaches the end of the linked list (id == -1). All the data in the blocks is appended and returned as a []byte.

func (*HeapStore) Update

func (h *HeapStore) Update(id ID, newStr string) error

Update will update data of a given ID

func (*HeapStore) Write

func (h *HeapStore) Write(data []byte) (ID, error)

Write divides the input data into chunks of HeapBlockDataSize and creates n HeapBlock instances and writes them as a linked list on the disk. HeapBlocks with < HeapBlockDataSize bytes of data are padded with zeros

type ID

type ID int64

Jump to

Keyboard shortcuts

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