MCPcopy Create free account
hub / github.com/bobg/hashsplit / Seek

Function Seek

hashsplit.go:364–385  ·  view source on GitHub ↗

Seek finds the level-0 node representing the given byte position (i.e., the one where Offset <= pos < Offset+Size).

(n *TreeNode, pos uint64)

Source from the content-addressed store, hash-verified

362// Seek finds the level-0 node representing the given byte position
363// (i.e., the one where Offset <= pos < Offset+Size).
364func Seek(n *TreeNode, pos uint64) (*TreeNode, error) {
365 if pos < n.Offset || pos >= (n.Offset+n.Size) {
366 return nil, ErrNotFound
367 }
368
369 num := len(n.Children)
370 if num == 0 {
371 return n, nil
372 }
373
374 // TODO: if a Node kept track of its children's offsets,
375 // this loop could be replaced with a sort.Search call.
376 for _, child := range n.Children {
377 if pos >= (child.Offset + child.Size) {
378 continue
379 }
380 return Seek(child, pos)
381 }
382
383 // With a properly formed tree of nodes this will not be reached.
384 return nil, ErrNotFound
385}

Callers 1

TestSeekFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestSeekFunction · 0.68