diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2014-01-30 19:26:10 -0800 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-01-30 19:26:10 -0800 |
commit | d05191d164dbab56adbb3a17a62f66a62695c6d3 (patch) | |
tree | 3f270655af94ff2dbbce62f6065d4f1c24030c71 /branch.go | |
parent | Merge pull request #2 from benbjohnson/master (diff) | |
parent | Add RWTransaction.write(). (diff) | |
download | dedo-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.go | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -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 { |