把一些运算优化为位运算.
This commit is contained in:
parent
b5576f18ef
commit
ef6c52294b
|
@ -451,9 +451,9 @@ func (tree *vbTree) Put(key interface{}) {
|
||||||
for cur := tree.root; ; {
|
for cur := tree.root; ; {
|
||||||
|
|
||||||
if cur.size > 8 {
|
if cur.size > 8 {
|
||||||
factor := cur.size / 10 // or factor = 1
|
factor := cur.size >> 3 // or factor = 1
|
||||||
ls, rs := cur.children[0].size, cur.children[1].size
|
ls, rs := cur.children[0].size, cur.children[1].size
|
||||||
if rs >= ls*2+factor || ls >= rs*2+factor {
|
if rs >= (ls<<1)+factor || ls >= (rs<<1)+factor {
|
||||||
cur = tree.fixSize(cur, ls, rs)
|
cur = tree.fixSize(cur, ls, rs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -861,9 +861,9 @@ func (tree *vbTree) fixSizeWithRemove(cur *Node) {
|
||||||
for cur != nil {
|
for cur != nil {
|
||||||
cur.size--
|
cur.size--
|
||||||
if cur.size > 8 {
|
if cur.size > 8 {
|
||||||
factor := cur.size / 10 // or factor = 1
|
factor := cur.size >> 3 // or factor = 1
|
||||||
ls, rs := getChildrenSize(cur)
|
ls, rs := getChildrenSize(cur)
|
||||||
if rs >= ls*2+factor || ls >= rs*2+factor {
|
if rs >= (ls<<1)+factor || ls >= (rs<<1)+factor {
|
||||||
cur = tree.fixSize(cur, ls, rs)
|
cur = tree.fixSize(cur, ls, rs)
|
||||||
}
|
}
|
||||||
} else if cur.size == 3 {
|
} else if cur.size == 3 {
|
||||||
|
|
|
@ -451,9 +451,9 @@ func (tree *vbTree) Put(key, value interface{}) {
|
||||||
for cur := tree.root; ; {
|
for cur := tree.root; ; {
|
||||||
|
|
||||||
if cur.size > 8 {
|
if cur.size > 8 {
|
||||||
factor := cur.size / 10 // or factor = 1
|
factor := cur.size >> 3 // or factor = 1
|
||||||
ls, rs := cur.children[0].size, cur.children[1].size
|
ls, rs := cur.children[0].size, cur.children[1].size
|
||||||
if rs >= ls*2+factor || ls >= rs*2+factor {
|
if rs >= (ls<<1)+factor || ls >= (rs<<1)+factor {
|
||||||
cur = tree.fixSize(cur, ls, rs)
|
cur = tree.fixSize(cur, ls, rs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -861,9 +861,9 @@ func (tree *vbTree) fixSizeWithRemove(cur *Node) {
|
||||||
for cur != nil {
|
for cur != nil {
|
||||||
cur.size--
|
cur.size--
|
||||||
if cur.size > 8 {
|
if cur.size > 8 {
|
||||||
factor := cur.size / 10 // or factor = 1
|
factor := cur.size >> 3 // or factor = 1
|
||||||
ls, rs := getChildrenSize(cur)
|
ls, rs := getChildrenSize(cur)
|
||||||
if rs >= ls*2+factor || ls >= rs*2+factor {
|
if rs >= (ls<<1)+factor || ls >= (rs<<1)+factor {
|
||||||
cur = tree.fixSize(cur, ls, rs)
|
cur = tree.fixSize(cur, ls, rs)
|
||||||
}
|
}
|
||||||
} else if cur.size == 3 {
|
} else if cur.size == 3 {
|
||||||
|
|
|
@ -513,9 +513,9 @@ func (tree *DTree) Put(key, value []rune) (isInsert bool) {
|
||||||
for cur := tree.root; ; {
|
for cur := tree.root; ; {
|
||||||
|
|
||||||
if cur.size > 8 {
|
if cur.size > 8 {
|
||||||
factor := cur.size / 10 // or factor = 1
|
factor := cur.size >> 3 // or factor = 1
|
||||||
ls, rs := cur.family[1].size, cur.family[2].size
|
ls, rs := cur.family[1].size, cur.family[2].size
|
||||||
if rs >= ls*2+factor || ls >= rs*2+factor {
|
if rs >= (ls<<1)+factor || ls >= (rs<<1)+factor {
|
||||||
tree.fixSize(cur, ls, rs)
|
tree.fixSize(cur, ls, rs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -970,9 +970,9 @@ func (tree *DTree) fixSizeWithRemove(cur *DNode) {
|
||||||
for cur != nil {
|
for cur != nil {
|
||||||
cur.size--
|
cur.size--
|
||||||
if cur.size > 8 {
|
if cur.size > 8 {
|
||||||
factor := cur.size / 10 // or factor = 1
|
factor := cur.size >> 3 // or factor = 1
|
||||||
ls, rs := getChildrenSize(cur)
|
ls, rs := getChildrenSize(cur)
|
||||||
if rs >= ls*2+factor || ls >= rs*2+factor {
|
if rs >= (ls<<1)+factor || ls >= (rs<<1)+factor {
|
||||||
tree.fixSize(cur, ls, rs)
|
tree.fixSize(cur, ls, rs)
|
||||||
}
|
}
|
||||||
} else if cur.size == 3 {
|
} else if cur.size == 3 {
|
||||||
|
|
|
@ -41,9 +41,9 @@ func (tree *ITree) Put(key, value []rune) (isInsert bool) {
|
||||||
for cur := tree.root; ; {
|
for cur := tree.root; ; {
|
||||||
|
|
||||||
if cur.size > 8 {
|
if cur.size > 8 {
|
||||||
factor := cur.size / 10 // or factor = 1
|
factor := cur.size >> 3 // or factor = 1
|
||||||
ls, rs := cur.family[1].size, cur.family[2].size
|
ls, rs := cur.family[1].size, cur.family[2].size
|
||||||
if rs >= ls*2+factor || ls >= rs*2+factor {
|
if rs >= (ls<<1)+factor || ls >= (rs<<1)+factor {
|
||||||
tree.ifixSize(cur, ls, rs)
|
tree.ifixSize(cur, ls, rs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -433,9 +433,9 @@ func (tree *ITree) ifixSizeWithRemove(cur *INode) {
|
||||||
for cur != nil {
|
for cur != nil {
|
||||||
cur.size--
|
cur.size--
|
||||||
if cur.size > 8 {
|
if cur.size > 8 {
|
||||||
factor := cur.size / 10 // or factor = 1
|
factor := cur.size >> 3 // or factor = 1
|
||||||
ls, rs := igetChildrenSize(cur)
|
ls, rs := igetChildrenSize(cur)
|
||||||
if rs >= ls*2+factor || ls >= rs*2+factor {
|
if rs >= (ls<<1)+factor || ls >= (rs<<1)+factor {
|
||||||
tree.ifixSize(cur, ls, rs)
|
tree.ifixSize(cur, ls, rs)
|
||||||
}
|
}
|
||||||
} else if cur.size == 3 {
|
} else if cur.size == 3 {
|
||||||
|
|
|
@ -443,9 +443,9 @@ func (tree *Tree) Put(key interface{}) {
|
||||||
for cur := tree.root; ; {
|
for cur := tree.root; ; {
|
||||||
|
|
||||||
if cur.size > 8 {
|
if cur.size > 8 {
|
||||||
factor := cur.size / 10 // or factor = 1
|
factor := cur.size >> 3 // or factor = 1
|
||||||
ls, rs := cur.children[0].size, cur.children[1].size
|
ls, rs := cur.children[0].size, cur.children[1].size
|
||||||
if rs >= ls*2+factor || ls >= rs*2+factor {
|
if rs >= (ls<<1)+factor || ls >= (rs<<1)+factor {
|
||||||
tree.fixSize(cur, ls, rs)
|
tree.fixSize(cur, ls, rs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -874,9 +874,9 @@ func (tree *Tree) fixSizeWithRemove(cur *Node) {
|
||||||
for cur != nil {
|
for cur != nil {
|
||||||
cur.size--
|
cur.size--
|
||||||
if cur.size > 8 {
|
if cur.size > 8 {
|
||||||
factor := cur.size / 10 // or factor = 1
|
factor := cur.size >> 3 // or factor = 1
|
||||||
ls, rs := getChildrenSize(cur)
|
ls, rs := getChildrenSize(cur)
|
||||||
if rs >= ls*2+factor || ls >= rs*2+factor {
|
if rs >= (ls<<1)+factor || ls >= (rs<<1)+factor {
|
||||||
tree.fixSize(cur, ls, rs)
|
tree.fixSize(cur, ls, rs)
|
||||||
}
|
}
|
||||||
} else if cur.size == 3 {
|
} else if cur.size == 3 {
|
||||||
|
|
|
@ -445,9 +445,9 @@ func (tree *Tree) Put(value interface{}) (isInsert bool) {
|
||||||
for cur := tree.root; ; {
|
for cur := tree.root; ; {
|
||||||
|
|
||||||
if cur.size > 8 {
|
if cur.size > 8 {
|
||||||
factor := cur.size / 10 // or factor = 1
|
factor := cur.size >> 3 // or factor = 1
|
||||||
ls, rs := cur.children[0].size, cur.children[1].size
|
ls, rs := cur.children[0].size, cur.children[1].size
|
||||||
if rs >= ls*2+factor || ls >= rs*2+factor {
|
if rs >= (ls<<1)+factor || ls >= (rs<<1)+factor {
|
||||||
tree.fixSize(cur, ls, rs)
|
tree.fixSize(cur, ls, rs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -895,9 +895,9 @@ func (tree *Tree) fixSizeWithRemove(cur *Node) {
|
||||||
for cur != nil {
|
for cur != nil {
|
||||||
cur.size--
|
cur.size--
|
||||||
if cur.size > 8 {
|
if cur.size > 8 {
|
||||||
factor := cur.size / 10 // or factor = 1
|
factor := cur.size >> 3 // or factor = 1
|
||||||
ls, rs := getChildrenSize(cur)
|
ls, rs := getChildrenSize(cur)
|
||||||
if rs >= ls*2+factor || ls >= rs*2+factor {
|
if rs >= (ls<<1)+factor || ls >= (rs<<1)+factor {
|
||||||
tree.fixSize(cur, ls, rs)
|
tree.fixSize(cur, ls, rs)
|
||||||
}
|
}
|
||||||
} else if cur.size == 3 {
|
} else if cur.size == 3 {
|
||||||
|
|
|
@ -446,9 +446,9 @@ func (tree *Tree) Put(key, value interface{}) {
|
||||||
for cur := tree.root; ; {
|
for cur := tree.root; ; {
|
||||||
|
|
||||||
if cur.size > 8 {
|
if cur.size > 8 {
|
||||||
factor := cur.size / 10 // or factor = 1
|
factor := cur.size >> 3 // or factor = 1
|
||||||
ls, rs := cur.children[0].size, cur.children[1].size
|
ls, rs := cur.children[0].size, cur.children[1].size
|
||||||
if rs >= ls*2+factor || ls >= rs*2+factor {
|
if rs >= (ls<<1)+factor || ls >= (rs<<1)+factor {
|
||||||
tree.fixSize(cur, ls, rs)
|
tree.fixSize(cur, ls, rs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -884,9 +884,9 @@ func (tree *Tree) fixSizeWithRemove(cur *Node) {
|
||||||
for cur != nil {
|
for cur != nil {
|
||||||
cur.size--
|
cur.size--
|
||||||
if cur.size > 8 {
|
if cur.size > 8 {
|
||||||
factor := cur.size / 10 // or factor = 1
|
factor := cur.size >> 3 // or factor = 1
|
||||||
ls, rs := getChildrenSize(cur)
|
ls, rs := getChildrenSize(cur)
|
||||||
if rs >= ls*2+factor || ls >= rs*2+factor {
|
if rs >= (ls<<1)+factor || ls >= (rs<<1)+factor {
|
||||||
tree.fixSize(cur, ls, rs)
|
tree.fixSize(cur, ls, rs)
|
||||||
}
|
}
|
||||||
} else if cur.size == 3 {
|
} else if cur.size == 3 {
|
||||||
|
|
|
@ -446,9 +446,9 @@ func (tree *Tree) Put(key, value interface{}) (isInsert bool) {
|
||||||
for cur := tree.root; ; {
|
for cur := tree.root; ; {
|
||||||
|
|
||||||
if cur.size > 8 {
|
if cur.size > 8 {
|
||||||
factor := cur.size / 10 // or factor = 1
|
factor := cur.size >> 3 // or factor = 1
|
||||||
ls, rs := cur.children[0].size, cur.children[1].size
|
ls, rs := cur.children[0].size, cur.children[1].size
|
||||||
if rs >= ls*2+factor || ls >= rs*2+factor {
|
if rs >= (ls<<1)+factor || ls >= (rs<<1)+factor {
|
||||||
tree.fixSize(cur, ls, rs)
|
tree.fixSize(cur, ls, rs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -896,9 +896,9 @@ func (tree *Tree) fixSizeWithRemove(cur *Node) {
|
||||||
for cur != nil {
|
for cur != nil {
|
||||||
cur.size--
|
cur.size--
|
||||||
if cur.size > 8 {
|
if cur.size > 8 {
|
||||||
factor := cur.size / 10 // or factor = 1
|
factor := cur.size >> 3 // or factor = 1
|
||||||
ls, rs := getChildrenSize(cur)
|
ls, rs := getChildrenSize(cur)
|
||||||
if rs >= ls*2+factor || ls >= rs*2+factor {
|
if rs >= (ls<<1)+factor || ls >= (rs<<1)+factor {
|
||||||
tree.fixSize(cur, ls, rs)
|
tree.fixSize(cur, ls, rs)
|
||||||
}
|
}
|
||||||
} else if cur.size == 3 {
|
} else if cur.size == 3 {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user