search recursively performs a binary search against a given page/node until it finds a given key.
(key []byte, pgId common.Pgid)
| 281 | |
| 282 | // search recursively performs a binary search against a given page/node until it finds a given key. |
| 283 | func (c *Cursor) search(key []byte, pgId common.Pgid) { |
| 284 | p, n := c.bucket.pageNode(pgId) |
| 285 | if p != nil && !p.IsBranchPage() && !p.IsLeafPage() { |
| 286 | panic(fmt.Sprintf("invalid page type: %d: %x", p.Id(), p.Flags())) |
| 287 | } |
| 288 | e := elemRef{page: p, node: n} |
| 289 | c.stack = append(c.stack, e) |
| 290 | |
| 291 | // If we're on a leaf page/node then find the specific node. |
| 292 | if e.isLeaf() { |
| 293 | c.nsearch(key) |
| 294 | return |
| 295 | } |
| 296 | |
| 297 | if n != nil { |
| 298 | c.searchNode(key, n) |
| 299 | return |
| 300 | } |
| 301 | c.searchPage(key, p) |
| 302 | } |
| 303 | |
| 304 | func (c *Cursor) searchNode(key []byte, n *node) { |
| 305 | var exact bool |
no test coverage detected