-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtree.go
87 lines (75 loc) · 2.01 KB
/
tree.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
package godata
type DataTree interface {
PersistChanges(string) error
ImportDataVersion(string, []byte)
InsertDataAt(string, any, int64)
GetData(string) any
GetDataAt(string, int64) any
GetDataRange(string, int64, int64) *DataVersionLinkedSortedList
GetDataRangeInterval(string, int64, int64, int64) *DataVersionLinkedSortedList
DeleteVersionsAt(int64)
}
type DataTreeRBT struct {
root *DataNodeRBT
}
func CreateDataTree() *DataTreeRBT {
return &DataTreeRBT{nil}
}
func (dt *DataTreeRBT) ImportDataVersion(name string, raw []byte) {
if dt.root == nil {
dt.root = ImportDataNode(name, raw, BLACK, nil, nil, nil)
return
}
node := dt.root.ImportDataVersion(name, raw)
dt.root = Balance(dt.root, node)
}
func (dt *DataTreeRBT) InsertDataAt(name string, data any, timestamp int64) {
if dt.root == nil {
dt.root = CreateDataNode(name, data, timestamp, BLACK, nil, nil, nil)
return
}
node := dt.root.InsertDataAt(name, data, timestamp)
dt.root = Balance(dt.root, node)
}
func (dt *DataTreeRBT) GetData(name string) any {
if dt.root == nil {
return nil
}
return dt.root.GetData(name)
}
func (dt *DataTreeRBT) GetDataAt(name string, timestamp int64) any {
if dt.root == nil {
return nil
}
return dt.root.GetDataAt(name, timestamp)
}
func (dt *DataTreeRBT) GetDataRange(name string, start int64, end int64) *DataVersionLinkedSortedList {
if dt.root == nil {
return nil
}
return dt.root.GetDataRange(name, start, end)
}
func (dt *DataTreeRBT) GetDataRangeInterval(name string, start int64, end int64, interval int64) *DataVersionLinkedSortedList {
if dt.root == nil {
return nil
}
return dt.root.GetDataRangeInterval(name, start, end, interval)
}
func (dt *DataTreeRBT) DeleteVersionsAt(timestamp int64) {
if dt.root == nil {
return
}
dt.root.DeleteVersionsAt(timestamp)
}
func (dt *DataTreeRBT) Height() uint {
if dt.root == nil {
return 0
}
return dt.root.Height()
}
func (dt *DataTreeRBT) PersistChanges(dir string) error {
if dt.root == nil {
return nil
}
return dt.root.PersistChanges(dir)
}