-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbnode.go
63 lines (55 loc) · 1.11 KB
/
dbnode.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
package hdb
import (
"github.com/intdxdt/mbr"
"github.com/TopoSimplify/node"
)
//dbNode type for internal dbNode
type dbNode struct {
children []dbNode
item *node.Node
height int
leaf bool
bbox mbr.MBR
}
//createDBNode creates a new dbNode
func createDBNode(item *node.Node, height int, leaf bool, children []dbNode) dbNode {
var box mbr.MBR
if item == nil {
box = emptyMBR()
} else {
box = item.MBR
}
return dbNode{
children: children,
item: item,
height: height,
leaf: leaf,
bbox: box,
}
}
//dbNode type for internal dbNode
func newLeafNode(item *node.Node) dbNode {
return dbNode{
children: []dbNode{},
item: item,
height: 1,
leaf: true,
bbox: item.MBR,
}
}
//MBR returns bbox property
func (nd *dbNode) BBox() *mbr.MBR {
return &nd.bbox
}
//add child
func (nd *dbNode) addChild(child dbNode) {
nd.children = append(nd.children, child)
}
//Constructs children of dbNode
func makeChildren(items []*node.Node) []dbNode {
var chs = make([]dbNode, 0, len(items))
for i := range items {
chs = append(chs, newLeafNode(items[i]))
}
return chs
}