last moves the cursor to the last leaf element under the last page in the stack.
()
| 188 | |
| 189 | // last moves the cursor to the last leaf element under the last page in the stack. |
| 190 | func (c *Cursor) last() { |
| 191 | for { |
| 192 | // Exit when we hit a leaf page. |
| 193 | ref := &c.stack[len(c.stack)-1] |
| 194 | if ref.isLeaf() { |
| 195 | break |
| 196 | } |
| 197 | |
| 198 | // Keep adding pages pointing to the last element in the stack. |
| 199 | var pgId common.Pgid |
| 200 | if ref.node != nil { |
| 201 | pgId = ref.node.inodes[ref.index].Pgid() |
| 202 | } else { |
| 203 | pgId = ref.page.BranchPageElement(uint16(ref.index)).Pgid() |
| 204 | } |
| 205 | p, n := c.bucket.pageNode(pgId) |
| 206 | |
| 207 | var nextRef = elemRef{page: p, node: n} |
| 208 | nextRef.index = nextRef.count() - 1 |
| 209 | c.stack = append(c.stack, nextRef) |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | // next moves to the next leaf element and returns the key and value. |
| 214 | // If the cursor is at the last leaf element then it stays there and returns nil. |