bolt/page.go

43 lines
819 B
Go
Raw Normal View History

2014-01-08 15:06:17 +00:00
package bolt
import (
"unsafe"
)
2014-01-27 15:11:54 +00:00
const pageHeaderSize = int(unsafe.Offsetof(((*page)(nil)).ptr))
2014-01-10 14:32:12 +00:00
2014-01-28 21:18:16 +00:00
const maxAllocSize = 0xFFFFFFF
2014-01-27 15:11:54 +00:00
const minKeysPerPage = 2
const maxNodesPerPage = 65535
2014-01-08 15:06:17 +00:00
const (
2014-01-24 23:32:18 +00:00
p_branch = 0x01
p_leaf = 0x02
p_meta = 0x04
2014-01-13 17:35:04 +00:00
)
2014-01-09 16:07:10 +00:00
2014-01-24 23:32:18 +00:00
type pgid uint64
2014-01-09 16:07:10 +00:00
2014-01-08 15:06:17 +00:00
type page struct {
2014-01-27 15:11:54 +00:00
id pgid
flags uint16
count uint16
overflow uint32
ptr uintptr
2014-01-09 16:07:10 +00:00
}
2014-01-10 14:32:12 +00:00
// meta returns a pointer to the metadata section of the page.
2014-01-30 03:35:58 +00:00
func (p *page) meta() *meta {
return (*meta)(unsafe.Pointer(&p.ptr))
2014-01-27 15:11:54 +00:00
}
// lnode retrieves the leaf node by index
func (p *page) lnode(index int) *lnode {
return &((*[maxNodesPerPage]lnode)(unsafe.Pointer(&p.ptr)))[index]
}
2014-01-30 03:35:58 +00:00
// bnode retrieves the branch node by index
func (p *page) bnode(index int) *bnode {
return &((*[maxNodesPerPage]bnode)(unsafe.Pointer(&p.ptr)))[index]
}