headers

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMaxIndexKeyLen uint32 = 3
View Source
const DefaultMaxKeys uint64 = 1_000_000
View Source
const DefaultRedundantBlocks uint16 = 1
View Source
const HeaderSizeInBytes uint64 = 100
View Source
const IndexEntrySizeInBytes uint64 = 8

Variables

This section is empty.

Functions

func GetIndexOffset

func GetIndexOffset(h Header, key []byte) uint64

GetIndexOffset computes the offset for the given key in the first index block. It uses the meta data in the header i.e. number of items per block and the `IndexEntrySizeInBytes`

func GetIndexOffsetInNthBlock

func GetIndexOffsetInNthBlock(h Header, initialOffset uint64, n uint64) (uint64, error)

GetIndexOffsetInNthBlock returns the index offset for the nth index block if `initialOffset` is the offset in the top most index block `n` starts at zero where zero is the top most index block

func InitializeFile

func InitializeFile(file *os.File, header Header) (int64, error)

InitializeFile initializes the database/index file, giving it the header and the index placeholders and truncating it.

It returns the new file size

Types

type DbFileHeader

type DbFileHeader struct {
	Title               []byte
	BlockSize           uint32
	MaxKeys             uint64
	RedundantBlocks     uint16
	ItemsPerIndexBlock  uint64
	NumberOfIndexBlocks uint64
	KeyValuesStartPoint uint64
	NetBlockSize        uint64
}

func ExtractDbFileHeaderFromByteArray

func ExtractDbFileHeaderFromByteArray(data []byte) (*DbFileHeader, error)

ExtractDbFileHeaderFromByteArray extracts the header from the data byte array

func ExtractDbFileHeaderFromFile

func ExtractDbFileHeaderFromFile(file *os.File) (*DbFileHeader, error)

ExtractDbFileHeaderFromFile extracts the header from a database file

func NewDbFileHeader

func NewDbFileHeader(maxKeys *uint64, redundantBlocks *uint16, blockSize *uint32) *DbFileHeader

NewDbFileHeader Creates a new DbFileHeader

func (*DbFileHeader) AsBytes

func (h *DbFileHeader) AsBytes() []byte

func (*DbFileHeader) GetBlockSize

func (h *DbFileHeader) GetBlockSize() uint32

func (*DbFileHeader) GetItemsPerIndexBlock

func (h *DbFileHeader) GetItemsPerIndexBlock() uint64

func (*DbFileHeader) GetMaxKeys

func (h *DbFileHeader) GetMaxKeys() uint64

func (*DbFileHeader) GetNetBlockSize

func (h *DbFileHeader) GetNetBlockSize() uint64

func (*DbFileHeader) GetNumberOfIndexBlocks

func (h *DbFileHeader) GetNumberOfIndexBlocks() uint64

func (*DbFileHeader) GetRedundantBlocks

func (h *DbFileHeader) GetRedundantBlocks() uint16

func (*DbFileHeader) SetItemsPerIndexBlock

func (h *DbFileHeader) SetItemsPerIndexBlock(u uint64)

func (*DbFileHeader) SetNetBlockSize

func (h *DbFileHeader) SetNetBlockSize(u uint64)

func (*DbFileHeader) SetNumberOfIndexBlocks

func (h *DbFileHeader) SetNumberOfIndexBlocks(u uint64)

func (*DbFileHeader) SetValuesStartPoint

func (h *DbFileHeader) SetValuesStartPoint(u uint64)
type Header interface {
	// GetItemsPerIndexBlock gets the number of items per index block
	GetItemsPerIndexBlock() uint64

	// GetNumberOfIndexBlocks gets the number of index blocks for given header
	GetNumberOfIndexBlocks() uint64

	// GetNetBlockSize gets the net size of each index block
	GetNetBlockSize() uint64

	// GetBlockSize gets the raw block size used for the file
	GetBlockSize() uint32

	// GetMaxKeys gets the maximum number of keys permitted for the given file-based map
	GetMaxKeys() uint64

	// GetRedundantBlocks gets the redundant blocks to add to the index blocks to reduce hash collisions
	// as the file of the file-based map gets full
	GetRedundantBlocks() uint16

	// AsBytes retrieves the byte array that represents the header.
	AsBytes() []byte

	// SetItemsPerIndexBlock sets the number of items per index block of the header
	SetItemsPerIndexBlock(u uint64)

	// SetNumberOfIndexBlocks sets the number of index blocks
	SetNumberOfIndexBlocks(u uint64)

	// SetNetBlockSize sets the net block size
	SetNetBlockSize(u uint64)

	// SetValuesStartPoint sets the values(or key-values) starting address in the file
	SetValuesStartPoint(u uint64)
}

type InvertedIndexHeader

type InvertedIndexHeader struct {
	Title               []byte
	BlockSize           uint32
	MaxKeys             uint64
	RedundantBlocks     uint16
	ItemsPerIndexBlock  uint64
	NumberOfIndexBlocks uint64
	ValuesStartPoint    uint64
	NetBlockSize        uint64
	MaxIndexKeyLen      uint32
}

func ExtractInvertedIndexHeaderFromByteArray

func ExtractInvertedIndexHeaderFromByteArray(data []byte) (*InvertedIndexHeader, error)

ExtractInvertedIndexHeaderFromByteArray extracts the inverted index header from the data byte array

func ExtractInvertedIndexHeaderFromFile

func ExtractInvertedIndexHeaderFromFile(file *os.File) (*InvertedIndexHeader, error)

ExtractInvertedIndexHeaderFromFile extracts the header from an index file

func NewInvertedIndexHeader

func NewInvertedIndexHeader(maxKeys *uint64, redundantBlocks *uint16, blockSize *uint32, maxIndexKeyLen *uint32) *InvertedIndexHeader

NewInvertedIndexHeader creates a new InvertedIndexHeader

func (*InvertedIndexHeader) AsBytes

func (h *InvertedIndexHeader) AsBytes() []byte

func (*InvertedIndexHeader) GetBlockSize

func (h *InvertedIndexHeader) GetBlockSize() uint32

func (*InvertedIndexHeader) GetItemsPerIndexBlock

func (h *InvertedIndexHeader) GetItemsPerIndexBlock() uint64

func (*InvertedIndexHeader) GetMaxKeys

func (h *InvertedIndexHeader) GetMaxKeys() uint64

func (*InvertedIndexHeader) GetNetBlockSize

func (h *InvertedIndexHeader) GetNetBlockSize() uint64

func (*InvertedIndexHeader) GetNumberOfIndexBlocks

func (h *InvertedIndexHeader) GetNumberOfIndexBlocks() uint64

func (*InvertedIndexHeader) GetRedundantBlocks

func (h *InvertedIndexHeader) GetRedundantBlocks() uint16

func (*InvertedIndexHeader) SetItemsPerIndexBlock

func (h *InvertedIndexHeader) SetItemsPerIndexBlock(u uint64)

func (*InvertedIndexHeader) SetNetBlockSize

func (h *InvertedIndexHeader) SetNetBlockSize(u uint64)

func (*InvertedIndexHeader) SetNumberOfIndexBlocks

func (h *InvertedIndexHeader) SetNumberOfIndexBlocks(u uint64)

func (*InvertedIndexHeader) SetValuesStartPoint

func (h *InvertedIndexHeader) SetValuesStartPoint(u uint64)

Jump to

Keyboard shortcuts

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