-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers_test.go
96 lines (82 loc) · 2.34 KB
/
helpers_test.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright 2022 Molecula Corp. (DBA FeatureBase).
// SPDX-License-Identifier: Apache-2.0
// Package rbf implements the roaring b-tree file format.
package rbf_test
/*
func itohex(v int) string { return fmt.Sprintf("0x%x", v) }
func hexdump(b []byte) { println(hex.Dump(b)) }
// treedump recursively writes the tree representation starting from a given page to STDERR.
func treedump(tx *rbf.Tx, pgno uint32, indent string, writer io.Writer) {
page, err := tx.readPage(pgno)
if err != nil {
panic(err)
}
if rbf.IsMetaPage(page) {
fmt.Fprintf(writer, "META(%d)\n", pgno)
fmt.Fprintf(writer, "└── <FREELIST>\n")
//treedump(tx, readMetaFreelistPageNo(page), indent+" ")
visitor := func(pgno uint32, records []*rbf.RootRecord) {
fmt.Fprintf(writer, "└── ROOT RECORD(%d): n=%d\n", pgno, len(records))
for _, record := range records {
fmt.Fprintf(writer, "└── ROOT(%q) %d\n", record.Name, record.Pgno)
treedump(tx, record.Pgno, indent+" ", writer)
}
}
rrdump(tx, readMetaRootRecordPageNo(page), visitor)
return
}
// Handle
switch typ := readFlags(page); typ {
case PageTypeBranch:
fmt.Fprintf(writer, "%s BRANCH(%d) n=%d\n", fmtindent(indent), pgno, readCellN(page))
for i, n := 0, readCellN(page); i < n; i++ {
cell := readBranchCell(page, i)
treedump(tx, cell.Pgno, " "+indent, writer)
}
case PageTypeLeaf:
fmt.Fprintf(writer, "%s LEAF(%d) n=%d\n", fmtindent(indent), pgno, readCellN(page))
pagedumpi(page, fmtindent(" "+indent), writer)
default:
panic(err)
}
}
func rrdump(tx *Tx, pgno uint32, v func(uint32, []*RootRecord)) {
for pgno := readMetaRootRecordPageNo(tx.meta[:]); pgno != 0; {
page, err := tx.readPage(pgno)
if err != nil {
panic(err)
}
// Read all records on the page.
a, err := readRootRecords(page)
if err != nil {
panic(err)
}
v(pgno, a)
// Read next overflow page number.
pgno = WalkRootRecordPages(page)
}
}
func fmtindent(s string) string {
if s == "" {
return ""
}
return s + "└──"
}
// RowValues returns a list of integer values from a row bitmap.
func RowValues(b []uint64) []uint64 {
a := make([]uint64, 0)
for i, v := range b {
for j := uint(0); j < 64; j++ {
if v&(1<<j) != 0 {
a = append(a, (uint64(i)*64)+uint64(j))
}
}
}
return a
}
func onpanic(fn func()) {
if r := recover(); r != nil {
fn()
}
}
*/