diskblock

package
v0.0.0-...-a9a9d8c Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDiskNodeService

func NewDiskNodeService(file *os.File) *diskNodeService

Types

type BlockService

type BlockService struct {
	BlockSize int // TODO be sure this can correspond to actual block size
	// contains filtered or unexported fields
}

func NewBlockService

func NewBlockService(file *os.File) *BlockService

func (*BlockService) ConvertBlockToDiskNode

func (bs *BlockService) ConvertBlockToDiskNode(block *DiskBlock) *DiskNode

func (*BlockService) ConvertDiskNodeToBlock

func (bs *BlockService) ConvertDiskNodeToBlock(node *DiskNode) *DiskBlock

func (*BlockService) GetBlockFromBuffer

func (bs *BlockService) GetBlockFromBuffer(blockBuffer []byte) *DiskBlock

func (*BlockService) GetBufferFromBlock

func (bs *BlockService) GetBufferFromBlock(block *DiskBlock) []byte

func (*BlockService) GetLatestBlockID

func (bs *BlockService) GetLatestBlockID() (int64, error)

func (*BlockService) GetMaxLeafSize

func (bs *BlockService) GetMaxLeafSize() int

* @Todo: Implement a function to : 1. Dynamicaly calculate blockSize 2. Then based on the blocksize, calculate the maxLeafSize

func (*BlockService) GetNodeAtBlockID

func (bs *BlockService) GetNodeAtBlockID(blockID uint64) (*DiskNode, error)

func (*BlockService) GetRootBlock

func (bs *BlockService) GetRootBlock() (*DiskBlock, error)

@Todo:Store current root block data somewhere else

func (*BlockService) SaveNewNodeToDisk

func (bs *BlockService) SaveNewNodeToDisk(n *DiskNode) error

NewBlockFromNode - Save a new node to disk block

func (*BlockService) UpdateNodeToDisk

func (bs *BlockService) UpdateNodeToDisk(n *DiskNode) error

func (*BlockService) UpdateRootNode

func (bs *BlockService) UpdateRootNode(n *DiskNode) error

func (*BlockService) WriteBlockToDisk

func (bs *BlockService) WriteBlockToDisk(block *DiskBlock) error

type DiskBlock

type DiskBlock struct {
	Id              uint64 // 4096 - 8 = 4088
	CurrentLeafSize uint64 // 4088 - 8 = 4080

	ChildrenBlockIds []uint64 // 352 - (8 * 30) =  112
	DataSet          []*Pairs // 4072 - (124 * 30) = 352
	// contains filtered or unexported fields
}

DiskBlock -- Make sure that it is accomodated in blockSize = 4096

func (*DiskBlock) SetChildren

func (b *DiskBlock) SetChildren(childrenBlockIds []uint64)

func (*DiskBlock) SetData

func (b *DiskBlock) SetData(data []*Pairs)

type DiskNode

type DiskNode struct {
	Keys             []*Pairs
	ChildrenBlockIDs []uint64
	BlockID          uint64
	BlockService     *BlockService
}

DiskNode - In memory node implementation

func NewLeafNode

func NewLeafNode(elements []*Pairs, bs *BlockService) (*DiskNode, error)

NewLeafNode - Create a new leaf node without children

func NewNodeWithChildren

func NewNodeWithChildren(elements []*Pairs, childrenBlockIDs []uint64, bs *BlockService) (*DiskNode, error)

NewNodeWithChildren - Create a non leaf node with children

func (*DiskNode) AddElement

func (n *DiskNode) AddElement(element *Pairs) int

* * Do a linear search and insert the element

func (*DiskNode) AddPoppedUpElementIntoCurrentNodeAndUpdateWithNewChildren

func (n *DiskNode) AddPoppedUpElementIntoCurrentNodeAndUpdateWithNewChildren(element *Pairs, leftNode *DiskNode, rightNode *DiskNode)

AddPoppedUpElementIntoCurrentNodeAndUpdateWithNewChildren - Insert element received as a reaction from insert operation at child nodes

func (*DiskNode) GetChildAtIndex

func (n *DiskNode) GetChildAtIndex(index int) (*DiskNode, error)

func (*DiskNode) GetChildNodes

func (n *DiskNode) GetChildNodes() ([]*DiskNode, error)

func (*DiskNode) GetChildOrSibling

func (n *DiskNode) GetChildOrSibling() (node, error)

func (*DiskNode) GetElementAtIndex

func (n *DiskNode) GetElementAtIndex(index int) *Pairs

func (*DiskNode) GetElements

func (n *DiskNode) GetElements() []*Pairs

func (*DiskNode) GetValue

func (n *DiskNode) GetValue(key string) (string, time.Time, error)

func (*DiskNode) HasOverFlown

func (n *DiskNode) HasOverFlown() bool

func (*DiskNode) InsertPair

func (n *DiskNode) InsertPair(value *Pairs, bt types.Tree) error

Insert - Insert value into Node

func (*DiskNode) IsLeaf

func (n *DiskNode) IsLeaf() bool

func (*DiskNode) PrintTree

func (n *DiskNode) PrintTree(level int)

PrintTree - Traverse and print the entire tree

func (*DiskNode) Size

func (n *DiskNode) Size() int

argh Size always returns the size of the full data set, not the current node, because I'm a lazy mf

func (*DiskNode) SplitLeafNode

func (n *DiskNode) SplitLeafNode() (*Pairs, *DiskNode, *DiskNode, error)

SplitLeafNode - Split leaf node

func (*DiskNode) SplitNonLeafNode

func (n *DiskNode) SplitNonLeafNode() (*Pairs, *DiskNode, *DiskNode, error)

SplitNonLeafNode - Split non leaf node

type Pairs

type Pairs = pair.Pairs

Jump to

Keyboard shortcuts

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