commit(): executes the deferred operations in order (left-to-right), minimizing the amount of traversals, IOPS, and hash operations
(subTree bool)
| 237 | // commit(): executes the deferred operations in order (left-to-right), |
| 238 | // minimizing the amount of traversals, IOPS, and hash operations |
| 239 | func (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 |
| 276 | func (s *SMT) set() lib.ErrorI { |