Documentation ¶
Index ¶
- func FetchLeafConcurrent(db *leveldb.DB, key string) ([]byte, error)
- func FetchLeafFromDB(db *leveldb.DB, key string) ([]byte, error)
- func GenerateRandomData(size int) ([]byte, error)
- func LoadRootHashFromFile(filename string) ([]byte, error)
- func MemoryMapFile(filename string) ([]byte, error)
- func PrintRootHash(root *HashTreeNode)
- func PruneOldLeaves(db *leveldb.DB, numLeaves int) error
- func SafeMemoryMapFile(filename string) ([]byte, error)
- func SafeUnmapFile(data []byte) error
- func SaveLeavesBatchToDB(db *leveldb.DB, leaves [][]byte) error
- func SaveLeavesToDB(db *leveldb.DB, leaves [][]byte) error
- func SaveRootHashToFile(root *HashTreeNode, filename string) error
- func UnmapFile(data []byte) error
- type HashTreeNode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FetchLeafConcurrent ¶
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 ¶
Fetch leaf from LevelDB
func GenerateRandomData ¶
Generate random data of specified length
func LoadRootHashFromFile ¶
Load root hash from file
func MemoryMapFile ¶
MemoryMapFile maps a file into memory with size checks
func PruneOldLeaves ¶
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 ¶
SafeMemoryMapFile safely memory-maps a file by ensuring exclusive access using a mutex lock
func SafeUnmapFile ¶
SafeUnmapFile safely unmaps a file by ensuring exclusive access using a mutex lock
func SaveLeavesBatchToDB ¶
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 ¶
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
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.