MCPcopy
hub / github.com/etcd-io/bbolt / splitIndex

Method splitIndex

node.go:271–291  ·  view source on GitHub ↗

splitIndex finds the position where a page will fill a given threshold. It returns the index as well as the size of the first page. This is only be called from split().

(threshold int)

Source from the content-addressed store, hash-verified

269// It returns the index as well as the size of the first page.
270// This is only be called from split().
271func (n *node) splitIndex(threshold int) (index, sz uintptr) {
272 sz = common.PageHeaderSize
273
274 // Loop until we only have the minimum number of keys required for the second page.
275 for i := 0; i < len(n.inodes)-common.MinKeysPerPage; i++ {
276 index = uintptr(i)
277 inode := n.inodes[i]
278 elsize := n.pageElementSize() + uintptr(len(inode.Key())) + uintptr(len(inode.Value()))
279
280 // If we have at least the minimum number of keys and adding another
281 // node would put us over the threshold then exit and return.
282 if index >= common.MinKeysPerPage && sz+elsize > uintptr(threshold) {
283 break
284 }
285
286 // Add the element size to the total size.
287 sz += elsize
288 }
289
290 return
291}
292
293// spill writes the nodes to dirty pages and splits nodes as it goes.
294// Returns an error if dirty pages cannot be allocated.

Callers 1

splitTwoMethod · 0.95

Calls 3

pageElementSizeMethod · 0.95
KeyMethod · 0.45
ValueMethod · 0.45

Tested by

no test coverage detected