FindPathsToKey finds all paths from root to the page that contains the given key. As it traverses multiple buckets, so in theory there might be multiple keys with the given name. Note: For simplicity it's currently implemented as traversing of the whole reachable tree. If key is a bucket name, a pag
(key []byte)
| 81 | // Note: For simplicity it's currently implemented as traversing of the whole reachable tree. |
| 82 | // If key is a bucket name, a page-path referencing the key will be returned as well. |
| 83 | func (n XRay) FindPathsToKey(key []byte) ([][]common.Pgid, error) { |
| 84 | var found [][]common.Pgid |
| 85 | |
| 86 | rootPage, _, err := guts_cli.GetRootPage(n.path) |
| 87 | if err != nil { |
| 88 | return nil, err |
| 89 | } |
| 90 | err = n.traverse([]common.Pgid{rootPage}, map[common.Pgid]struct{}{}, |
| 91 | func(page *common.Page, stack []common.Pgid) error { |
| 92 | if page.Typ() == "leaf" { |
| 93 | for i := uint16(0); i < page.Count(); i++ { |
| 94 | if bytes.Equal(page.LeafPageElement(i).Key(), key) { |
| 95 | var copyPath []common.Pgid |
| 96 | copyPath = append(copyPath, stack...) |
| 97 | found = append(found, copyPath) |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | return nil |
| 102 | }) |
| 103 | if err != nil { |
| 104 | return nil, err |
| 105 | } else { |
| 106 | return found, nil |
| 107 | } |
| 108 | } |