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

Function NewARTreeIterator

engine/index/art.go:72–111  ·  view source on GitHub ↗
(tree art.Tree, reverse bool)

Source from the content-addressed store, hash-verified

70}
71
72func NewARTreeIterator(tree art.Tree, reverse bool) *ARTreeIterator {
73 // Estimate the expected slice capacity based on tree size
74 expectedSize := tree.Size()
75
76 // Use a mutex for concurrent access to values array
77 var mutex sync.Mutex
78
79 // Initialize with empty slice and expected capacity
80 values := make([]*Item, 0, expectedSize)
81
82 // Store all the data in an array
83 saveToValues := func(node art.Node) bool {
84 item := &Item{
85 key: node.Key(),
86 pst: node.Value().(*data.LogRecordPst),
87 }
88 mutex.Lock()
89
90 // Append item to values slice
91 values = append(values, item)
92
93 mutex.Unlock()
94
95 return true
96 }
97 tree.ForEach(saveToValues)
98
99 // Reverse the values slice if reverse is true
100 if reverse {
101 for i, j := 0, len(values)-1; i < j; i, j = i+1, j-1 {
102 values[i], values[j] = values[j], values[i]
103 }
104 }
105
106 return &ARTreeIterator{
107 currIndex: 0,
108 reverse: reverse,
109 values: values,
110 }
111}
112
113func (artree *ARTreeIterator) Rewind() {
114 artree.currIndex = 0

Callers 1

IteratorMethod · 0.85

Calls 3

SizeMethod · 0.65
KeyMethod · 0.65
ValueMethod · 0.65

Tested by

no test coverage detected