diff --git a/tree/vbt/iterator.go b/tree/vbt/iterator.go index 776238b..1bedc99 100644 --- a/tree/vbt/iterator.go +++ b/tree/vbt/iterator.go @@ -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) diff --git a/tree/vbt/vbt.go b/tree/vbt/vbt.go index 29668d0..c574d53 100644 --- a/tree/vbt/vbt.go +++ b/tree/vbt/vbt.go @@ -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 diff --git a/tree/vbtkey/vbtkey.go b/tree/vbtkey/vbtkey.go index e5b0459..604b08b 100644 --- a/tree/vbtkey/vbtkey.go +++ b/tree/vbtkey/vbtkey.go @@ -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 diff --git a/utils/math.go b/utils/math.go index a66db91..f7c882a 100644 --- a/utils/math.go +++ b/utils/math.go @@ -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)