diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2014-01-29 19:12:49 -0500 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-01-29 19:12:49 -0500 |
commit | d38be1d25bcf0e2955d64e1a6e2ea6e5e260ddad (patch) | |
tree | b5a8772fa9373751868778b272f06fc635292c96 /leaf.go | |
parent | Add branch.put(). (diff) | |
download | dedo-d38be1d25bcf0e2955d64e1a6e2ea6e5e260ddad.tar.gz dedo-d38be1d25bcf0e2955d64e1a6e2ea6e5e260ddad.tar.xz |
Add branch.split()
Diffstat (limited to 'leaf.go')
-rw-r--r-- | leaf.go | 25 |
1 files changed, 12 insertions, 13 deletions
@@ -6,13 +6,21 @@ import ( "unsafe" ) -// leaf represents a temporary in-memory leaf page. -// It is deserialized from an memory-mapped page and is not restricted by page size. +// leaf represents an in-memory, deserialized leaf page. type leaf struct { parent *branch items leafItems } +// size returns the size of the leaf after serialization. +func (l *leaf) size() int { + var size int = pageHeaderSize + for _, item := range l.items { + size += lnodeSize + len(item.key) + len(item.value) + } + return size +} + // put inserts or replaces a key on a leaf page. func (l *leaf) put(key []byte, value []byte) { // Find insertion index. @@ -29,15 +37,6 @@ func (l *leaf) put(key []byte, value []byte) { l.items[index].value = value } -// size returns the size of the leaf after serialization. -func (l *leaf) size() int { - var size int = pageHeaderSize - for _, item := range l.items { - size += lnodeSize + len(item.key) + len(item.value) - } - return size -} - // read initializes the item data from an on-disk page. func (l *leaf) read(p *page) { ncount := int(p.count) @@ -83,8 +82,8 @@ func (l *leaf) split(pageSize int) []*leaf { return []*leaf{l} } - // Set fill threshold to 25%. - threshold := pageSize >> 4 + // Set fill threshold to 50%. + threshold := pageSize / 2 // Otherwise group into smaller pages and target a given fill size. size := 0 |