-
Notifications
You must be signed in to change notification settings - Fork 0
/
meta.go
39 lines (29 loc) · 779 Bytes
/
meta.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import "encoding/binary"
//meta will be stored at 0 pageNum and will have info about where freelist is stored
const (
metaPageNum = 0
)
type meta struct {
//to store root of B-Tree
root pgnum
freelistPage pgnum
}
func newEmptyMeta() *meta {
return &meta{}
}
//POS is just a cursor we move in order to read from disk.
func (m *meta) serialize(buf []byte) {
pos := 0
binary.LittleEndian.PutUint64(buf[pos:], uint64(m.root))
pos += pageNumSize
binary.LittleEndian.PutUint64(buf[pos:], uint64(m.freelistPage))
pos += pageNumSize
}
func (m *meta) deserialize(buf []byte) {
pos := 0
m.root = pgnum(binary.LittleEndian.Uint64(buf[pos:]))
pos += pageNumSize
m.freelistPage = pgnum(binary.LittleEndian.Uint64(buf[pos:]))
pos += pageNumSize
}