From 26f6fefeadf1b3e38b86a0a12ba8d1cbb7f347d3 Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Thu, 30 Jan 2014 18:22:02 -0500 Subject: Add RWTransaction.write(). --- branch.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'branch.go') diff --git a/branch.go b/branch.go index d752ac6..c4f0b1f 100644 --- a/branch.go +++ b/branch.go @@ -7,6 +7,8 @@ import ( // branch represents a temporary in-memory branch page. type branch struct { + pgid pgid + depth int parent *branch items branchItems } @@ -42,11 +44,11 @@ func (b *branch) put(id pgid, newid pgid, key []byte, replace bool) { } // read initializes the item data from an on-disk page. -func (b *branch) read(page *page) { - ncount := int(page.count) - b.items = make(branchItems, ncount) - bnodes := (*[maxNodesPerPage]bnode)(unsafe.Pointer(&page.ptr)) - for i := 0; i < ncount; i++ { +func (b *branch) read(p *page) { + b.pgid = p.id + b.items = make(branchItems, int(p.count)) + bnodes := (*[maxNodesPerPage]bnode)(unsafe.Pointer(&p.ptr)) + for i := 0; i < int(p.count); i++ { bnode := &bnodes[i] item := &b.items[i] item.pgid = bnode.pgid @@ -109,6 +111,12 @@ func (b *branch) split(pageSize int) []*branch { return branches } +type branches []*branch + +func (s branches) Len() int { return len(s) } +func (s branches) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +func (s branches) Less(i, j int) bool { return s[i].depth < s[j].depth } + type branchItems []branchItem type branchItem struct { -- cgit v1.2.3