aboutsummaryrefslogtreecommitdiff
path: root/branch.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-01-30 19:26:10 -0800
committerBen Johnson <benbjohnson@yahoo.com>2014-01-30 19:26:10 -0800
commitd05191d164dbab56adbb3a17a62f66a62695c6d3 (patch)
tree3f270655af94ff2dbbce62f6065d4f1c24030c71 /branch.go
parentMerge pull request #2 from benbjohnson/master (diff)
parentAdd RWTransaction.write(). (diff)
downloaddedo-d05191d164dbab56adbb3a17a62f66a62695c6d3.tar.gz
dedo-d05191d164dbab56adbb3a17a62f66a62695c6d3.tar.xz
Merge pull request #3 from benbjohnson/spill
Spill to dirty pages, write to disk
Diffstat (limited to 'branch.go')
-rw-r--r--branch.go18
1 files changed, 13 insertions, 5 deletions
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 {