add RemoveNode IndexNode method

This commit is contained in:
eson 2019-12-23 00:43:25 +08:00
parent 9f8a971c2a
commit 88a20acf13
4 changed files with 19 additions and 17 deletions

View File

@ -1,7 +1,7 @@
package vbt
import (
"github.com/474420502/focus/stack/listarraystack"
lastack "github.com/474420502/focus/stack/listarraystack"
)
type Iterator struct {
@ -112,6 +112,7 @@ func (iter *Iterator) Next() (result bool) {
return false
}
func (iter *Iterator) GetPrev(cur *Node, idx int) *Node {
// iter := NewIterator(cur)

View File

@ -61,7 +61,7 @@ func (tree *Tree) Size() int {
return tree.root.size
}
func (tree *Tree) indexNode(idx int) *Node {
func (tree *Tree) IndexNode(idx int) *Node {
cur := tree.root
if idx >= 0 {
for cur != nil {
@ -93,7 +93,7 @@ func (tree *Tree) indexNode(idx int) *Node {
}
func (tree *Tree) Index(idx int) (interface{}, bool) {
n := tree.indexNode(idx)
n := tree.IndexNode(idx)
if n != nil {
return n.value, true
}
@ -117,7 +117,7 @@ func (tree *Tree) IndexRange(idx1, idx2 int) (result []interface{}, ok bool) { /
ok = false
}
n := tree.indexNode(idx1)
n := tree.IndexNode(idx1)
tree.iter.SetNode(n)
iter := tree.iter
result = make([]interface{}, 0, idx1-idx2)
@ -139,7 +139,7 @@ func (tree *Tree) IndexRange(idx1, idx2 int) (result []interface{}, ok bool) { /
ok = false
}
if n := tree.indexNode(idx1); n != nil {
if n := tree.IndexNode(idx1); n != nil {
tree.iter.SetNode(n)
iter := tree.iter
result = make([]interface{}, 0, idx2-idx1)
@ -161,15 +161,15 @@ func (tree *Tree) IndexRange(idx1, idx2 int) (result []interface{}, ok bool) { /
}
func (tree *Tree) RemoveIndex(idx int) (interface{}, bool) {
n := tree.indexNode(idx)
n := tree.IndexNode(idx)
if n != nil {
tree.removeNode(n)
tree.RemoveNode(n)
return n.value, true
}
return nil, false
}
func (tree *Tree) removeNode(n *Node) {
func (tree *Tree) RemoveNode(n *Node) {
if tree.root.size == 1 {
tree.root = nil
// return n
@ -230,7 +230,7 @@ func (tree *Tree) removeNode(n *Node) {
func (tree *Tree) Remove(key interface{}) (interface{}, bool) {
if n, ok := tree.GetNode(key); ok {
tree.removeNode(n)
tree.RemoveNode(n)
return n.value, true
}
// return nil

View File

@ -62,7 +62,7 @@ func (tree *Tree) Size() int {
return tree.root.size
}
func (tree *Tree) indexNode(idx int) *Node {
func (tree *Tree) IndexNode(idx int) *Node {
cur := tree.root
if idx >= 0 {
for cur != nil {
@ -94,7 +94,7 @@ func (tree *Tree) indexNode(idx int) *Node {
}
func (tree *Tree) Index(idx int) (interface{}, bool) {
n := tree.indexNode(idx)
n := tree.IndexNode(idx)
if n != nil {
return n.value, true
}
@ -118,7 +118,7 @@ func (tree *Tree) IndexRange(idx1, idx2 int) (result []interface{}, ok bool) { /
ok = false
}
n := tree.indexNode(idx1)
n := tree.IndexNode(idx1)
tree.iter.SetNode(n)
iter := tree.iter
result = make([]interface{}, 0, idx1-idx2)
@ -140,7 +140,7 @@ func (tree *Tree) IndexRange(idx1, idx2 int) (result []interface{}, ok bool) { /
ok = false
}
if n := tree.indexNode(idx1); n != nil {
if n := tree.IndexNode(idx1); n != nil {
tree.iter.SetNode(n)
iter := tree.iter
result = make([]interface{}, 0, idx2-idx1)
@ -162,15 +162,15 @@ func (tree *Tree) IndexRange(idx1, idx2 int) (result []interface{}, ok bool) { /
}
func (tree *Tree) RemoveIndex(idx int) (interface{}, bool) {
n := tree.indexNode(idx)
n := tree.IndexNode(idx)
if n != nil {
tree.removeNode(n)
tree.RemoveNode(n)
return n.value, true
}
return nil, false
}
func (tree *Tree) removeNode(n *Node) {
func (tree *Tree) RemoveNode(n *Node) {
if tree.root.size == 1 {
tree.root = nil
// return n
@ -231,7 +231,7 @@ func (tree *Tree) removeNode(n *Node) {
func (tree *Tree) Remove(key interface{}) (interface{}, bool) {
if n, ok := tree.GetNode(key); ok {
tree.removeNode(n)
tree.RemoveNode(n)
return n.value, true
}
// return nil

View File

@ -3,6 +3,7 @@ package utils
var bit = uint(32 << (^uint(0) >> 63))
var bitsub1 = bit - 1
// AbsInt
func AbsInt(n int) uint {
y := n >> bitsub1
return uint((n ^ y) - y)