Commit 96c28df2 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent ccc251b9
......@@ -505,22 +505,21 @@ type nodeInRange struct {
node Node
}
// rangeCover represents set of nodes covering a range.
// nodes come with key↑ and not intersection [lo,hi)
// XXX -> nodeSet? nodeSetInRange?
type rangeCover []*nodeInRange // key↑
// rangeSplit represents set of nodes covering a range.
// nodes come with key↑ and no intersection in between their [lo,hi)
type rangeSplit []*nodeInRange // key↑
// Get returns node covering key k.
// Get panics if k is outside covered range.
func (rc rangeCover) Get(k Key) *nodeInRange { // XXX -> Get_ -> rn, ok
i := sort.Search(len(rc), func(i int) bool {
return k <= rc[i].hi_
func (rs rangeSplit) Get(k Key) *nodeInRange { // XXX -> Get_ -> rn, ok
i := sort.Search(len(rs), func(i int) bool {
return k <= rs[i].hi_
})
if i == len(rc) {
if i == len(rs) {
panicf("key %v not covered", k) // XXX + coverage: ...
}
rn := rc[i]
rn := rs[i]
if !(rn.lo <= k && k <= rn.hi_) {
panicf("BUG: get(%v) -> [%v, %v]", k, rn.lo, rn.hi_)
}
......@@ -530,15 +529,15 @@ func (rc rangeCover) Get(k Key) *nodeInRange { // XXX -> Get_ -> rn, ok
// Expand replaces rnode with its children.
//
// rnode must be initially in rc.
// rnode must be initially in *prs.
// rnode.node must be tree.
// rnode.node must be aleady activated.
func (prc *rangeCover) Expand(rnode *nodeInRange) []*nodeInRange {
rc := *prc
i := sort.Search(len(rc), func(i int) bool {
return rnode.hi_ <= rc[i].hi_
func (prs *rangeCover) Expand(rnode *nodeInRange) []*nodeInRange {
rs := *prs
i := sort.Search(len(rs), func(i int) bool {
return rnode.hi_ <= rs[i].hi_
})
if i == len(rc) || rc[i] != rnode {
if i == len(rs) || rs[i] != rnode {
panicf("%s not in rangeCover", rnode)
}
......@@ -563,7 +562,7 @@ func (prc *rangeCover) Expand(rnode *nodeInRange) []*nodeInRange {
}
// del[i]; insert(@i, children)
*prc = append(rc[:i], append(children, rc[i+1:]...)...)
*prs = append(rs[:i], append(children, rs[i+1:]...)...)
return children
}
......@@ -573,7 +572,7 @@ func (rc rangeCover) String() string {
if s != "" {
s += " "
}
s += fmt.Sprintf("[%v,%v]%s", rn.lo, rn.hi_, vnode(rn.node))
s += fmt.Sprintf("%s", rn)
}
return s
}
......@@ -1335,7 +1334,9 @@ func vnode(node Node) string {
}
func (rn nodeInRange) String() string {
return fmt.Sprintf("[%v,%v]%s", rn.lo, rn.hi_, vnode(rn.node))
slo := "-∞"; if rn.lo > KeyMin { slo = fmt.Sprintf("%v", rn.lo) }
shi := "∞"; if rn.hi_ < KeyMax { shi = fmt.Sprintf("%v", rn.hi_+1) }
return fmt.Sprintf("[%s,%s)%s", slo, shi, vnode(rn.node))
}
func (track nodeTrack) String() string {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment