Commit 7829c494 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 1c847f19
......@@ -44,6 +44,13 @@ type RangeMapEntry struct {
Value VALUE
}
// Get returns value associated with key k.
func (M *RangedMap) Get(k Key) VALUE {
v, _ := M.Get_(k)
return v
}
// Set changes M to map key k to value v.
func (M *RangedMap) Set(k Key, v VALUE) {
M.SetRange(KeyRange{Lo: k, Hi_: k}, v)
......@@ -60,17 +67,39 @@ func (M *RangedMap) Has(k Key) bool {
return ok
}
// Get returns value associated with key k.
func (M *RangedMap) Get(k Key) VALUE {
v, _ := M.Get_(k)
return v
}
// Get_ is comma-ok version of Get.
func (M *RangedMap) Get_(k Key) (VALUE, bool) {
panic("TODO") // XXX
func (M *RangedMap) Get_(k Key) (v VALUE, ok bool) {
if traceRangeMap {
fmt.Printf("\n\nGet_:\n")
fmt.Printf(" M: %s\n", M)
fmt.Printf(" k: %s\n", k)
defer func() {
fmt.Printf("->·: %v, %t\n", v, ok)
}()
}
M.verify()
// find first ilo: k < [ilo].hi
l := len(M.entryv)
ilo := sort.Search(l, func(i int) bool {
return k <= M.entryv[i].Hi_
})
debugfRMap("\tilo: %d\n", ilo)
if ilo == l { // not found
return
}
e := M.entryv[ilo]
if !(e.Lo <= k) { // not found
return
}
// found
return e.value, true
}
......@@ -246,9 +275,9 @@ func (M *RangedMap) HasRange(r KeyRange) (yes bool) {
M.verify()
// find first ilo: r.lo < [ilo].hi
l := len(M.rangev)
l := len(M.entryv)
ilo := sort.Search(l, func(i int) bool {
return r.Lo <= M.rangev[i].Hi_
return r.Lo <= M.entryv[i].Hi_
})
debugfRMap("\tilo: %d\n", ilo)
......@@ -257,7 +286,7 @@ func (M *RangedMap) HasRange(r KeyRange) (yes bool) {
}
// all keys from r are in M if r [ilo] XXX not in case of different values
return (M.rangev[ilo].Lo <= r.Lo && r.Hi_ <= M.rangev[ilo].Hi_)
return (M.entryv[ilo].Lo <= r.Lo && r.Hi_ <= M.entryv[ilo].Hi_)
}
......
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