|
|
|
|
@@ -27,10 +27,14 @@ func (n *tNode) String() string {
|
|
|
|
|
type vbTree struct {
|
|
|
|
|
root *tNode
|
|
|
|
|
Compare compare.Compare
|
|
|
|
|
|
|
|
|
|
top *tNode
|
|
|
|
|
|
|
|
|
|
iter *vbtIterator
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func newVBT(Compare compare.Compare) *vbTree {
|
|
|
|
|
return &vbTree{Compare: Compare}
|
|
|
|
|
return &vbTree{Compare: Compare, iter: NewIteratorWithCap(nil, 16)}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (tree *vbTree) String() string {
|
|
|
|
|
@@ -42,7 +46,7 @@ func (tree *vbTree) String() string {
|
|
|
|
|
return str
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (tree *vbTree) Iterator() *vbtIterator {
|
|
|
|
|
func (tree *vbTree) vbtIterator() *vbtIterator {
|
|
|
|
|
return initIterator(tree)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -263,7 +267,9 @@ func (tree *vbTree) GetRange(k1, k2 interface{}) (result []interface{}) {
|
|
|
|
|
|
|
|
|
|
result = make([]interface{}, 0, 16)
|
|
|
|
|
|
|
|
|
|
iter := NewIterator(min)
|
|
|
|
|
// iter := NewIterator(min)
|
|
|
|
|
tree.iter.SetNode(min)
|
|
|
|
|
iter := tree.iter
|
|
|
|
|
for iter.Next() {
|
|
|
|
|
result = append(result, iter.Value())
|
|
|
|
|
if iter.cur == max {
|
|
|
|
|
@@ -288,7 +294,9 @@ func (tree *vbTree) GetRange(k1, k2 interface{}) (result []interface{}) {
|
|
|
|
|
|
|
|
|
|
result = make([]interface{}, 0, 16)
|
|
|
|
|
|
|
|
|
|
iter := NewIterator(max)
|
|
|
|
|
// iter := NewIterator(max)
|
|
|
|
|
tree.iter.SetNode(max)
|
|
|
|
|
iter := tree.iter
|
|
|
|
|
for iter.Prev() {
|
|
|
|
|
result = append(result, iter.Value())
|
|
|
|
|
if iter.cur == min {
|
|
|
|
|
@@ -338,7 +346,9 @@ func (tree *vbTree) getArountNode(key interface{}) (result [3]*tNode) {
|
|
|
|
|
n = n.children[1]
|
|
|
|
|
lastc = c
|
|
|
|
|
case 0:
|
|
|
|
|
iter := NewIterator(n)
|
|
|
|
|
// iter := NewIterator(n)
|
|
|
|
|
tree.iter.SetNode(n)
|
|
|
|
|
iter := tree.iter
|
|
|
|
|
iter.Prev()
|
|
|
|
|
for iter.Prev() {
|
|
|
|
|
if tree.Compare(iter.cur.value, n.value) == 0 {
|
|
|
|
|
@@ -359,21 +369,21 @@ func (tree *vbTree) getArountNode(key interface{}) (result [3]*tNode) {
|
|
|
|
|
|
|
|
|
|
if result[1] != nil {
|
|
|
|
|
|
|
|
|
|
result[0] = getPrev(result[1], 1)
|
|
|
|
|
result[2] = getNext(result[1], 1)
|
|
|
|
|
result[0] = tree.iter.GetPrev(result[1], 1)
|
|
|
|
|
result[2] = tree.iter.GetNext(result[1], 1)
|
|
|
|
|
} else {
|
|
|
|
|
result[0] = last
|
|
|
|
|
result[2] = getNext(last, 1)
|
|
|
|
|
result[2] = tree.iter.GetNext(last, 1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case -1:
|
|
|
|
|
|
|
|
|
|
if result[1] != nil {
|
|
|
|
|
result[0] = getPrev(result[1], 1)
|
|
|
|
|
result[2] = getNext(result[1], 1)
|
|
|
|
|
result[0] = tree.iter.GetPrev(result[1], 1)
|
|
|
|
|
result[2] = tree.iter.GetNext(result[1], 1)
|
|
|
|
|
} else {
|
|
|
|
|
result[2] = last
|
|
|
|
|
result[0] = getPrev(last, 1)
|
|
|
|
|
result[0] = tree.iter.GetPrev(last, 1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
|
@@ -381,8 +391,8 @@ func (tree *vbTree) getArountNode(key interface{}) (result [3]*tNode) {
|
|
|
|
|
if result[1] == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
result[0] = getPrev(result[1], 1)
|
|
|
|
|
result[2] = getNext(result[1], 1)
|
|
|
|
|
result[0] = tree.iter.GetPrev(result[1], 1)
|
|
|
|
|
result[2] = tree.iter.GetNext(result[1], 1)
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
@@ -396,7 +406,10 @@ func (tree *vbTree) GetNode(value interface{}) (*tNode, bool) {
|
|
|
|
|
case 1:
|
|
|
|
|
n = n.children[1]
|
|
|
|
|
case 0:
|
|
|
|
|
iter := NewIterator(n)
|
|
|
|
|
// iter := NewIterator(n)
|
|
|
|
|
|
|
|
|
|
tree.iter.SetNode(n)
|
|
|
|
|
iter := tree.iter
|
|
|
|
|
iter.Prev()
|
|
|
|
|
for iter.Prev() {
|
|
|
|
|
if tree.Compare(iter.cur.value, n.value) == 0 {
|
|
|
|
|
@@ -413,46 +426,56 @@ func (tree *vbTree) GetNode(value interface{}) (*tNode, bool) {
|
|
|
|
|
return nil, false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (tree *vbTree) Put(key interface{}) *tNode {
|
|
|
|
|
func (tree *vbTree) Put(key interface{}) {
|
|
|
|
|
|
|
|
|
|
node := &tNode{value: key, size: 1}
|
|
|
|
|
tNode := &tNode{value: key, size: 1}
|
|
|
|
|
if tree.root == nil {
|
|
|
|
|
tree.root = node
|
|
|
|
|
return node
|
|
|
|
|
tree.root = tNode
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cur := tree.root
|
|
|
|
|
parent := cur.parent
|
|
|
|
|
child := -1
|
|
|
|
|
|
|
|
|
|
for {
|
|
|
|
|
|
|
|
|
|
if cur == nil {
|
|
|
|
|
parent.children[child] = node
|
|
|
|
|
node.parent = parent
|
|
|
|
|
|
|
|
|
|
fixed := parent.parent
|
|
|
|
|
fsize := getSize(fixed)
|
|
|
|
|
if fsize == 3 {
|
|
|
|
|
lefts, rigths := getChildrenSize(fixed)
|
|
|
|
|
tree.fix3Size(fixed, lefts, rigths)
|
|
|
|
|
}
|
|
|
|
|
return node
|
|
|
|
|
}
|
|
|
|
|
for cur := tree.root; ; {
|
|
|
|
|
|
|
|
|
|
if cur.size > 8 {
|
|
|
|
|
ls, rs := cur.children[0].size, cur.children[1].size
|
|
|
|
|
factor := cur.size / 10 // or factor = 1
|
|
|
|
|
if rs >= ls*2+factor || ls >= rs*2+factor {
|
|
|
|
|
tree.fixSize(cur, ls, rs)
|
|
|
|
|
if cur.children[1].size >= cur.children[0].size*2+factor || cur.children[0].size >= cur.children[1].size*2+factor {
|
|
|
|
|
tree.fixSize(cur)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cur.size++
|
|
|
|
|
parent = cur
|
|
|
|
|
c := tree.Compare(key, cur.value)
|
|
|
|
|
child = (c + 2) / 2
|
|
|
|
|
cur = cur.children[child]
|
|
|
|
|
if c < 0 {
|
|
|
|
|
if cur.children[0] == nil {
|
|
|
|
|
cur.children[0] = tNode
|
|
|
|
|
tNode.parent = cur
|
|
|
|
|
|
|
|
|
|
if cur.parent != nil && cur.parent.size == 3 {
|
|
|
|
|
if cur.parent.children[0] == nil {
|
|
|
|
|
tree.lrrotate3(cur.parent)
|
|
|
|
|
} else {
|
|
|
|
|
tree.rrotate3(cur.parent)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
cur = cur.children[0]
|
|
|
|
|
} else {
|
|
|
|
|
if cur.children[1] == nil {
|
|
|
|
|
cur.children[1] = tNode
|
|
|
|
|
tNode.parent = cur
|
|
|
|
|
|
|
|
|
|
if cur.parent != nil && cur.parent.size == 3 {
|
|
|
|
|
if cur.parent.children[1] == nil {
|
|
|
|
|
tree.rlrotate3(cur.parent)
|
|
|
|
|
} else {
|
|
|
|
|
tree.lrotate3(cur.parent)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
cur = cur.children[1]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -601,27 +624,38 @@ func (tree *vbTree) Traversal(every func(v interface{}) bool, traversalMethod ..
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (tree *vbTree) lrrotate3(cur *tNode) {
|
|
|
|
|
func (tree *vbTree) lrrotate3(cur *tNode) *tNode {
|
|
|
|
|
const l = 1
|
|
|
|
|
const r = 0
|
|
|
|
|
|
|
|
|
|
movparent := cur.children[l]
|
|
|
|
|
mov := movparent.children[r]
|
|
|
|
|
ln := cur.children[l]
|
|
|
|
|
lrn := ln.children[r]
|
|
|
|
|
ln.children[r] = nil
|
|
|
|
|
|
|
|
|
|
mov.value, cur.value = cur.value, mov.value //交换值达到, 相对位移
|
|
|
|
|
if cur.parent == nil {
|
|
|
|
|
tree.root = lrn
|
|
|
|
|
} else {
|
|
|
|
|
if cur.parent.children[1] == cur {
|
|
|
|
|
cur.parent.children[1] = lrn
|
|
|
|
|
} else {
|
|
|
|
|
cur.parent.children[0] = lrn
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
lrn.parent = cur.parent
|
|
|
|
|
|
|
|
|
|
cur.children[r] = mov
|
|
|
|
|
mov.parent = cur
|
|
|
|
|
lrn.children[l] = cur.children[l]
|
|
|
|
|
lrn.children[l].parent = lrn
|
|
|
|
|
|
|
|
|
|
cur.children[l] = movparent
|
|
|
|
|
movparent.children[r] = nil
|
|
|
|
|
lrn.children[r] = cur
|
|
|
|
|
lrn.children[r].parent = lrn
|
|
|
|
|
|
|
|
|
|
cur.children[r] = mov
|
|
|
|
|
mov.parent = cur
|
|
|
|
|
cur.children[l] = nil
|
|
|
|
|
|
|
|
|
|
// cur.size = 3
|
|
|
|
|
// cur.children[r].size = 1
|
|
|
|
|
cur.children[l].size = 1
|
|
|
|
|
lrn.size = 3
|
|
|
|
|
lrn.children[l].size = 1
|
|
|
|
|
lrn.children[r].size = 1
|
|
|
|
|
|
|
|
|
|
return lrn
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (tree *vbTree) lrrotate(cur *tNode) {
|
|
|
|
|
@@ -664,27 +698,38 @@ func (tree *vbTree) lrrotate(cur *tNode) {
|
|
|
|
|
cur.size = getChildrenSumSize(cur) + 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (tree *vbTree) rlrotate3(cur *tNode) {
|
|
|
|
|
func (tree *vbTree) rlrotate3(cur *tNode) *tNode {
|
|
|
|
|
const l = 0
|
|
|
|
|
const r = 1
|
|
|
|
|
|
|
|
|
|
movparent := cur.children[l]
|
|
|
|
|
mov := movparent.children[r]
|
|
|
|
|
ln := cur.children[l]
|
|
|
|
|
lrn := ln.children[r]
|
|
|
|
|
ln.children[r] = nil
|
|
|
|
|
|
|
|
|
|
mov.value, cur.value = cur.value, mov.value //交换值达到, 相对位移
|
|
|
|
|
if cur.parent == nil {
|
|
|
|
|
tree.root = lrn
|
|
|
|
|
} else {
|
|
|
|
|
if cur.parent.children[1] == cur {
|
|
|
|
|
cur.parent.children[1] = lrn
|
|
|
|
|
} else {
|
|
|
|
|
cur.parent.children[0] = lrn
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
lrn.parent = cur.parent
|
|
|
|
|
|
|
|
|
|
cur.children[r] = mov
|
|
|
|
|
mov.parent = cur
|
|
|
|
|
lrn.children[l] = cur.children[l]
|
|
|
|
|
lrn.children[l].parent = lrn
|
|
|
|
|
|
|
|
|
|
cur.children[l] = movparent
|
|
|
|
|
movparent.children[r] = nil
|
|
|
|
|
lrn.children[r] = cur
|
|
|
|
|
lrn.children[r].parent = lrn
|
|
|
|
|
|
|
|
|
|
cur.children[r] = mov
|
|
|
|
|
mov.parent = cur
|
|
|
|
|
cur.children[l] = nil
|
|
|
|
|
|
|
|
|
|
// cur.size = 3
|
|
|
|
|
// cur.children[r].size = 1
|
|
|
|
|
cur.children[l].size = 1
|
|
|
|
|
lrn.size = 3
|
|
|
|
|
lrn.children[l].size = 1
|
|
|
|
|
lrn.children[r].size = 1
|
|
|
|
|
|
|
|
|
|
return lrn
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (tree *vbTree) rlrotate(cur *tNode) {
|
|
|
|
|
@@ -725,23 +770,60 @@ func (tree *vbTree) rlrotate(cur *tNode) {
|
|
|
|
|
cur.size = getChildrenSumSize(cur) + 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (tree *vbTree) rrotate3(cur *tNode) {
|
|
|
|
|
func (tree *vbTree) replaceNotRoot(old, new *tNode) {
|
|
|
|
|
|
|
|
|
|
new.children[0] = old.children[0]
|
|
|
|
|
new.children[1] = old.children[1]
|
|
|
|
|
|
|
|
|
|
if old.parent.children[1] == old {
|
|
|
|
|
old.parent.children[1] = new
|
|
|
|
|
} else {
|
|
|
|
|
old.parent.children[0] = new
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (tree *vbTree) replace(old, new *tNode) {
|
|
|
|
|
|
|
|
|
|
new.children[0] = old.children[0]
|
|
|
|
|
new.children[1] = old.children[1]
|
|
|
|
|
|
|
|
|
|
if old.parent == nil {
|
|
|
|
|
tree.root = new
|
|
|
|
|
} else {
|
|
|
|
|
if old.parent.children[1] == old {
|
|
|
|
|
old.parent.children[1] = new
|
|
|
|
|
} else {
|
|
|
|
|
old.parent.children[0] = new
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (tree *vbTree) rrotate3(cur *tNode) *tNode {
|
|
|
|
|
const l = 0
|
|
|
|
|
const r = 1
|
|
|
|
|
// 1 right 0 left
|
|
|
|
|
mov := cur.children[l]
|
|
|
|
|
|
|
|
|
|
mov.value, cur.value = cur.value, mov.value //交换值达到, 相对位移
|
|
|
|
|
if cur.parent == nil {
|
|
|
|
|
tree.root = mov
|
|
|
|
|
} else {
|
|
|
|
|
if cur.parent.children[1] == cur {
|
|
|
|
|
cur.parent.children[1] = mov
|
|
|
|
|
} else {
|
|
|
|
|
cur.parent.children[0] = mov
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mov.parent = cur.parent
|
|
|
|
|
|
|
|
|
|
cur.children[r] = mov
|
|
|
|
|
mov.size = 1
|
|
|
|
|
mov.children[r] = cur
|
|
|
|
|
mov.children[r].parent = mov
|
|
|
|
|
|
|
|
|
|
cur.children[l] = mov.children[l]
|
|
|
|
|
cur.children[l].parent = cur
|
|
|
|
|
cur.children[l] = nil
|
|
|
|
|
|
|
|
|
|
mov.children[l] = nil
|
|
|
|
|
|
|
|
|
|
mov.size = 1
|
|
|
|
|
mov.size = 3
|
|
|
|
|
cur.size = 1
|
|
|
|
|
return mov
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (tree *vbTree) rrotate(cur *tNode) {
|
|
|
|
|
@@ -778,23 +860,32 @@ func (tree *vbTree) rrotate(cur *tNode) {
|
|
|
|
|
cur.size = getChildrenSumSize(cur) + 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (tree *vbTree) lrotate3(cur *tNode) {
|
|
|
|
|
func (tree *vbTree) lrotate3(cur *tNode) *tNode {
|
|
|
|
|
const l = 1
|
|
|
|
|
const r = 0
|
|
|
|
|
|
|
|
|
|
// 1 right 0 left
|
|
|
|
|
mov := cur.children[l]
|
|
|
|
|
|
|
|
|
|
mov.value, cur.value = cur.value, mov.value //交换值达到, 相对位移
|
|
|
|
|
if cur.parent == nil {
|
|
|
|
|
tree.root = mov
|
|
|
|
|
} else {
|
|
|
|
|
if cur.parent.children[1] == cur {
|
|
|
|
|
cur.parent.children[1] = mov
|
|
|
|
|
} else {
|
|
|
|
|
cur.parent.children[0] = mov
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mov.parent = cur.parent
|
|
|
|
|
|
|
|
|
|
cur.children[r] = mov
|
|
|
|
|
mov.size = 1
|
|
|
|
|
mov.children[r] = cur
|
|
|
|
|
mov.children[r].parent = mov
|
|
|
|
|
|
|
|
|
|
cur.children[l] = mov.children[l]
|
|
|
|
|
cur.children[l].parent = cur
|
|
|
|
|
cur.children[l] = nil
|
|
|
|
|
|
|
|
|
|
mov.children[l] = nil
|
|
|
|
|
|
|
|
|
|
mov.size = 1
|
|
|
|
|
mov.size = 3
|
|
|
|
|
cur.size = 1
|
|
|
|
|
return mov
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (tree *vbTree) lrotate(cur *tNode) {
|
|
|
|
|
@@ -850,48 +941,25 @@ func (tree *vbTree) fixSizeWithRemove(cur *tNode) {
|
|
|
|
|
for cur != nil {
|
|
|
|
|
cur.size--
|
|
|
|
|
if cur.size > 8 {
|
|
|
|
|
ls, rs := getChildrenSize(cur)
|
|
|
|
|
factor := cur.size / 10 // or factor = 1
|
|
|
|
|
if rs >= ls*2+factor || ls >= rs*2+factor {
|
|
|
|
|
tree.fixSize(cur, ls, rs)
|
|
|
|
|
if cur.children[1].size >= cur.children[0].size*2+factor || cur.children[0].size >= cur.children[1].size*2+factor {
|
|
|
|
|
tree.fixSize(cur)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
cur = cur.parent
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (tree *vbTree) fix3Size(cur *tNode, lefts, rigths int) {
|
|
|
|
|
if lefts > rigths {
|
|
|
|
|
l := cur.children[0]
|
|
|
|
|
llsize, lrsize := getChildrenSize(l)
|
|
|
|
|
if lrsize > llsize {
|
|
|
|
|
tree.rlrotate3(cur)
|
|
|
|
|
} else {
|
|
|
|
|
tree.rrotate3(cur)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
r := cur.children[1]
|
|
|
|
|
rlsize, rrsize := getChildrenSize(r)
|
|
|
|
|
if rlsize > rrsize {
|
|
|
|
|
tree.lrrotate3(cur)
|
|
|
|
|
} else {
|
|
|
|
|
tree.lrotate3(cur)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (tree *vbTree) fixSize(cur *tNode, lefts, rigths int) {
|
|
|
|
|
if lefts > rigths {
|
|
|
|
|
l := cur.children[0]
|
|
|
|
|
llsize, lrsize := getChildrenSize(l)
|
|
|
|
|
func (tree *vbTree) fixSize(cur *tNode) {
|
|
|
|
|
if cur.children[0].size > cur.children[1].size {
|
|
|
|
|
llsize, lrsize := getChildrenSize(cur.children[0])
|
|
|
|
|
if lrsize > llsize {
|
|
|
|
|
tree.rlrotate(cur)
|
|
|
|
|
} else {
|
|
|
|
|
tree.rrotate(cur)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
r := cur.children[1]
|
|
|
|
|
rlsize, rrsize := getChildrenSize(r)
|
|
|
|
|
rlsize, rrsize := getChildrenSize(cur.children[1])
|
|
|
|
|
if rlsize > rrsize {
|
|
|
|
|
tree.lrrotate(cur)
|
|
|
|
|
} else {
|
|
|
|
|
@@ -900,16 +968,16 @@ func (tree *vbTree) fixSize(cur *tNode, lefts, rigths int) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func output(node *tNode, prefix string, isTail bool, str *string) {
|
|
|
|
|
func output(tNode *tNode, prefix string, isTail bool, str *string) {
|
|
|
|
|
|
|
|
|
|
if node.children[1] != nil {
|
|
|
|
|
if tNode.children[1] != nil {
|
|
|
|
|
newPrefix := prefix
|
|
|
|
|
if isTail {
|
|
|
|
|
newPrefix += "│ "
|
|
|
|
|
} else {
|
|
|
|
|
newPrefix += " "
|
|
|
|
|
}
|
|
|
|
|
output(node.children[1], newPrefix, false, str)
|
|
|
|
|
output(tNode.children[1], newPrefix, false, str)
|
|
|
|
|
}
|
|
|
|
|
*str += prefix
|
|
|
|
|
if isTail {
|
|
|
|
|
@@ -918,30 +986,30 @@ func output(node *tNode, prefix string, isTail bool, str *string) {
|
|
|
|
|
*str += "┌── "
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*str += spew.Sprint(node.value) + "\n"
|
|
|
|
|
*str += spew.Sprint(tNode.value) + "\n"
|
|
|
|
|
|
|
|
|
|
if node.children[0] != nil {
|
|
|
|
|
if tNode.children[0] != nil {
|
|
|
|
|
newPrefix := prefix
|
|
|
|
|
if isTail {
|
|
|
|
|
newPrefix += " "
|
|
|
|
|
} else {
|
|
|
|
|
newPrefix += "│ "
|
|
|
|
|
}
|
|
|
|
|
output(node.children[0], newPrefix, true, str)
|
|
|
|
|
output(tNode.children[0], newPrefix, true, str)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func outputfordebug(node *tNode, prefix string, isTail bool, str *string) {
|
|
|
|
|
func outputfordebug(tNode *tNode, prefix string, isTail bool, str *string) {
|
|
|
|
|
|
|
|
|
|
if node.children[1] != nil {
|
|
|
|
|
if tNode.children[1] != nil {
|
|
|
|
|
newPrefix := prefix
|
|
|
|
|
if isTail {
|
|
|
|
|
newPrefix += "│ "
|
|
|
|
|
} else {
|
|
|
|
|
newPrefix += " "
|
|
|
|
|
}
|
|
|
|
|
outputfordebug(node.children[1], newPrefix, false, str)
|
|
|
|
|
outputfordebug(tNode.children[1], newPrefix, false, str)
|
|
|
|
|
}
|
|
|
|
|
*str += prefix
|
|
|
|
|
if isTail {
|
|
|
|
|
@@ -952,22 +1020,22 @@ func outputfordebug(node *tNode, prefix string, isTail bool, str *string) {
|
|
|
|
|
|
|
|
|
|
suffix := "("
|
|
|
|
|
parentv := ""
|
|
|
|
|
if node.parent == nil {
|
|
|
|
|
if tNode.parent == nil {
|
|
|
|
|
parentv = "nil"
|
|
|
|
|
} else {
|
|
|
|
|
parentv = spew.Sprint(node.parent.value)
|
|
|
|
|
parentv = spew.Sprint(tNode.parent.value)
|
|
|
|
|
}
|
|
|
|
|
suffix += parentv + "|" + spew.Sprint(node.size) + ")"
|
|
|
|
|
*str += spew.Sprint(node.value) + suffix + "\n"
|
|
|
|
|
suffix += parentv + "|" + spew.Sprint(tNode.size) + ")"
|
|
|
|
|
*str += spew.Sprint(tNode.value) + suffix + "\n"
|
|
|
|
|
|
|
|
|
|
if node.children[0] != nil {
|
|
|
|
|
if tNode.children[0] != nil {
|
|
|
|
|
newPrefix := prefix
|
|
|
|
|
if isTail {
|
|
|
|
|
newPrefix += " "
|
|
|
|
|
} else {
|
|
|
|
|
newPrefix += "│ "
|
|
|
|
|
}
|
|
|
|
|
outputfordebug(node.children[0], newPrefix, true, str)
|
|
|
|
|
outputfordebug(tNode.children[0], newPrefix, true, str)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|