hashtree

package
v0.0.0-...-e5dd51c Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FetchLeafConcurrent

func FetchLeafConcurrent(db *leveldb.DB, key string) ([]byte, error)

FetchLeafConcurrent retrieves a leaf node from LevelDB while ensuring it handles concurrent access safely. In this example, concurrency is handled implicitly by the LevelDB API, which can manage simultaneous read operations.

func FetchLeafFromDB

func FetchLeafFromDB(db *leveldb.DB, key string) ([]byte, error)

Fetch leaf from LevelDB

func GenerateRandomData

func GenerateRandomData(size int) ([]byte, error)

Generate random data of specified length

func LoadRootHashFromFile

func LoadRootHashFromFile(filename string) ([]byte, error)

Load root hash from file

func MemoryMapFile

func MemoryMapFile(filename string) ([]byte, error)

MemoryMapFile maps a file into memory with size checks

func PrintRootHash

func PrintRootHash(root *HashTreeNode)

Print the root hash of the hash tree

func PruneOldLeaves

func PruneOldLeaves(db *leveldb.DB, numLeaves int) error

PruneOldLeaves removes old leaf nodes from the LevelDB. It takes a specified number of leaves (numLeaves) and deletes them by key from the database.

func SafeMemoryMapFile

func SafeMemoryMapFile(filename string) ([]byte, error)

SafeMemoryMapFile safely memory-maps a file by ensuring exclusive access using a mutex lock

func SafeUnmapFile

func SafeUnmapFile(data []byte) error

SafeUnmapFile safely unmaps a file by ensuring exclusive access using a mutex lock

func SaveLeavesBatchToDB

func SaveLeavesBatchToDB(db *leveldb.DB, leaves [][]byte) error

SaveLeavesBatchToDB performs batch operations for LevelDB to save leaf nodes efficiently. Using a batch operation improves performance by reducing the number of write calls to the database.

func SaveLeavesToDB

func SaveLeavesToDB(db *leveldb.DB, leaves [][]byte) error

SaveLeavesToDB saves leaf node data to LevelDB. The function takes a slice of leaf data (leaves) and stores each leaf in the database (db).

func SaveRootHashToFile

func SaveRootHashToFile(root *HashTreeNode, filename string) error

Save root hash to file

func UnmapFile

func UnmapFile(data []byte) error

UnmapFile unmaps a file from memory with error handling

Types

type HashTreeNode

type HashTreeNode struct {
	Hash  []byte        `json:"hash"`            // Hash of the node's data
	Left  *HashTreeNode `json:"left,omitempty"`  // Left child node
	Right *HashTreeNode `json:"right,omitempty"` // Right child node
}

HashTreeNode represents a node in the hash tree

func BuildHashTree

func BuildHashTree(leaves [][]byte) *HashTreeNode

BuildHashTree builds a Merkle hash tree from leaf nodes. It returns the root node of the hash tree, which is computed by repeatedly combining and hashing pairs of leaf nodes and intermediate nodes.

Jump to

Keyboard shortcuts

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