MCPcopy
hub / github.com/canopy-network/canopy / commit

Method commit

store/smt.go:239–273  ·  view source on GitHub ↗

commit(): executes the deferred operations in order (left-to-right), minimizing the amount of traversals, IOPS, and hash operations

(subTree bool)

Source from the content-addressed store, hash-verified

237// commit(): executes the deferred operations in order (left-to-right),
238// minimizing the amount of traversals, IOPS, and hash operations
239func (s *SMT) commit(subTree bool) (err lib.ErrorI) {
240 for {
241 // if no operations and at root - exit
242 if len(s.operations) == 0 && len(s.traversed.Nodes) == 0 {
243 return
244 }
245 // pop head into target
246 s.target, s.operations = s.operations[0], s.operations[1:]
247 // reset path variables
248 s.resetGCP()
249 // if not at main tree root
250 if subTree || len(s.traversed.Nodes) != 0 {
251 // update the greatest common prefix and the bit position based on the new current key
252 s.target.Key.greatestCommonPrefix(&s.bitPos, s.gcp, s.current.Key)
253 }
254 // traverse to target
255 if err = s.traverse(); err != nil {
256 return
257 }
258 // execute operation
259 if !s.target.delete {
260 if err = s.set(); err != nil {
261 return
262 }
263 } else {
264 if err = s.delete(); err != nil {
265 return
266 }
267 }
268 // rehash
269 if err = s.rehash(); err != nil {
270 return
271 }
272 }
273}
274
275// set() executes the 'set' logic after traversal
276func (s *SMT) set() lib.ErrorI {

Callers 3

CommitMethod · 0.95
addSyntheticBordersMethod · 0.95
CommitParallelMethod · 0.80

Calls 6

resetGCPMethod · 0.95
traverseMethod · 0.95
setMethod · 0.95
deleteMethod · 0.95
rehashMethod · 0.95
greatestCommonPrefixMethod · 0.80

Tested by

no test coverage detected