MCPcopy Create free account
hub / github.com/ByteStorage/FlyDB / Fold

Method Fold

engine/db.go:293–318  ·  view source on GitHub ↗

Fold get all the data and perform the operation specified by the user. The function returns false to exit

(f func(key []byte, value []byte) bool)

Source from the content-addressed store, hash-verified

291// Fold get all the data and perform the operation specified by the user.
292// The function returns false to exit
293func (db *DB) Fold(f func(key []byte, value []byte) bool) error {
294 // Acquire a read lock to ensure data consistency
295 db.lock.RLock()
296 defer db.lock.RUnlock()
297
298 // Retrieve an iterator for the index
299 iterator := db.index.Iterator(false)
300
301 // Iterate over the index
302 for iterator.Rewind(); iterator.Valid(); iterator.Next() {
303 // Retrieve the value associated with the current key
304 value, err := db.getValueByPosition(iterator.Value())
305 if err != nil {
306 return err
307 }
308
309 // Invoke the provided function with the key and value
310 // If the function returns false, stop folding and exit the loop
311 if !f(iterator.Key(), value) {
312 break
313 }
314 }
315
316 // Return nil to indicate successful folding
317 return nil
318}
319
320// getValueByPosition Get the corresponding value based on the location index information
321func (db *DB) getValueByPosition(logRecordPst *data2.LogRecordPst) ([]byte, error) {

Callers 1

TestDB_FoldFunction · 0.95

Calls 7

getValueByPositionMethod · 0.95
IteratorMethod · 0.65
RewindMethod · 0.65
ValidMethod · 0.65
NextMethod · 0.65
ValueMethod · 0.65
KeyMethod · 0.65

Tested by 1

TestDB_FoldFunction · 0.76