完善了rotate 还差3的特殊旋转
This commit is contained in:
parent
6f6a64ed08
commit
45ef1aca6c
|
@ -440,7 +440,7 @@ func (tree *vbTree) Put(key interface{}) *tNode {
|
|||
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)
|
||||
cur = tree.fixSize(cur, ls, rs)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -640,13 +640,16 @@ func (tree *vbTree) lrrotate(cur *tNode) *tNode {
|
|||
} else {
|
||||
cur.parent.children[r] = lrn
|
||||
}
|
||||
} else {
|
||||
tree.root = lrn
|
||||
}
|
||||
lrn.parent = cur.parent
|
||||
|
||||
lrn.children[l] = cur.children[l]
|
||||
lrn.children[l].parent = lrn
|
||||
|
||||
lrn.children[l] = cur
|
||||
lrn.children[l].parent = lrn
|
||||
lrn.children[r] = cur
|
||||
lrn.children[r].parent = lrn
|
||||
|
||||
cur.children[l] = lrrn
|
||||
cur.children[l].parent = cur
|
||||
|
@ -701,13 +704,16 @@ func (tree *vbTree) rlrotate(cur *tNode) *tNode {
|
|||
} else {
|
||||
cur.parent.children[r] = lrn
|
||||
}
|
||||
} else {
|
||||
tree.root = lrn
|
||||
}
|
||||
lrn.parent = cur.parent
|
||||
|
||||
lrn.children[l] = cur.children[l]
|
||||
lrn.children[l].parent = lrn
|
||||
|
||||
lrn.children[l] = cur
|
||||
lrn.children[l].parent = lrn
|
||||
lrn.children[r] = cur
|
||||
lrn.children[r].parent = lrn
|
||||
|
||||
cur.children[l] = lrrn
|
||||
cur.children[l].parent = cur
|
||||
|
@ -752,6 +758,8 @@ func (tree *vbTree) rrotate(cur *tNode) *tNode {
|
|||
} else {
|
||||
cur.parent.children[r] = ln
|
||||
}
|
||||
} else {
|
||||
tree.root = ln
|
||||
}
|
||||
ln.parent = cur.parent
|
||||
|
||||
|
@ -802,6 +810,8 @@ func (tree *vbTree) lrotate(cur *tNode) *tNode {
|
|||
} else {
|
||||
cur.parent.children[r] = ln
|
||||
}
|
||||
} else {
|
||||
tree.root = ln
|
||||
}
|
||||
ln.parent = cur.parent
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user