Commit 5b30965f authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 32e85309
...@@ -46,9 +46,11 @@ type RangedMapEntry struct { ...@@ -46,9 +46,11 @@ type RangedMapEntry struct {
// Get returns value associated with key k. // Get returns value associated with key k.
func (M *RangedMap) Get(k Key) VALUE { //
v, _ := M.Get_(k) // KeyRange indicates all keys adjacent to k, that are too mapped to the same value.
return v func (M *RangedMap) Get(k Key) (VALUE, KeyRange) {
v, r, _ := M.Get_(k)
return v, r
} }
// Set changes M to map key k to value v. // Set changes M to map key k to value v.
...@@ -63,20 +65,20 @@ func (M *RangedMap) Del(k Key) { ...@@ -63,20 +65,20 @@ func (M *RangedMap) Del(k Key) {
// Has returns whether key k is present in the map. // Has returns whether key k is present in the map.
func (M *RangedMap) Has(k Key) bool { func (M *RangedMap) Has(k Key) bool {
_, ok := M.Get_(k) _, _, ok := M.Get_(k)
return ok return ok
} }
// Get_ is comma-ok version of Get. // Get_ is comma-ok version of Get.
func (M *RangedMap) Get_(k Key) (v VALUE, ok bool) { func (M *RangedMap) Get_(k Key) (v VALUE, r KeyRange, ok bool) {
if traceRangeMap { if traceRangeMap {
fmt.Printf("\n\nGet_:\n") fmt.Printf("\n\nGet_:\n")
fmt.Printf(" M: %s\n", M) fmt.Printf(" M: %s\n", M)
fmt.Printf(" k: %s\n", KStr(k)) fmt.Printf(" k: %s\n", KStr(k))
defer func() { defer func() {
fmt.Printf("->·: %v, %t\n", v, ok) fmt.Printf("->·: %v%s, %t\n", v, r, ok)
}() }()
} }
...@@ -99,7 +101,7 @@ func (M *RangedMap) Get_(k Key) (v VALUE, ok bool) { ...@@ -99,7 +101,7 @@ func (M *RangedMap) Get_(k Key) (v VALUE, ok bool) {
} }
// found // found
return e.Value, true return e.Value, e.KeyRange, true
} }
// SetRange changes M to map key range r to value v. // SetRange changes M to map key range r to value v.
......
...@@ -283,10 +283,10 @@ func verifyGet(t *testing.T, M *RangedMap) { ...@@ -283,10 +283,10 @@ func verifyGet(t *testing.T, M *RangedMap) {
lo := kmax(e.Lo, Z.Lo) lo := kmax(e.Lo, Z.Lo)
hi_ := kmin(e.Hi_, Z.Hi_) hi_ := kmin(e.Hi_, Z.Hi_)
for k := lo; k <= hi_; k++ { for k := lo; k <= hi_; k++ {
v, ok := M.Get_(k) v, r, ok := M.Get_(k)
if !(v == e.Value && ok) { if !(v == e.Value && r == e.KeyRange && ok) {
t.Errorf("%s\tGet(%s):\nhave: %q, %t\nwant: %q, true", t.Errorf("%s\tGet(%s):\nhave: %q%s, %t\nwant: %q%s, true",
M, KStr(k), v, ok, e.Value) M, KStr(k), v, r, ok, e.Value, e.KeyRange)
} }
} }
} }
...@@ -303,10 +303,10 @@ func verifyGet(t *testing.T, M *RangedMap) { ...@@ -303,10 +303,10 @@ func verifyGet(t *testing.T, M *RangedMap) {
lo := kmax(r.Lo, Z.Lo) lo := kmax(r.Lo, Z.Lo)
hi_ := kmin(r.Hi_, Z.Hi_) hi_ := kmin(r.Hi_, Z.Hi_)
for k := lo; k <= hi_; k++ { for k := lo; k <= hi_; k++ {
v, ok := M.Get_(k) v, r_, ok := M.Get_(k)
if !(v == "" && !ok) { if !(v == "" && r_.Empty() && !ok) {
t.Errorf("%s\tGet(%s):\nhave: %q, %t\nwant: %q, false", t.Errorf("%s\tGet(%s):\nhave: %q%s, %t\nwant: %q[), false",
M, KStr(k), v, ok, "") M, KStr(k), v, r_, ok, "")
} }
} }
} }
......
...@@ -48,9 +48,11 @@ type _RangedMap_strEntry struct { ...@@ -48,9 +48,11 @@ type _RangedMap_strEntry struct {
// Get returns value associated with key k. // Get returns value associated with key k.
func (M *_RangedMap_str) Get(k Key) string { //
v, _ := M.Get_(k) // KeyRange indicates all keys adjacent to k, that are too mapped to the same value.
return v func (M *_RangedMap_str) Get(k Key) (string, KeyRange) {
v, r, _ := M.Get_(k)
return v, r
} }
// Set changes M to map key k to value v. // Set changes M to map key k to value v.
...@@ -65,20 +67,20 @@ func (M *_RangedMap_str) Del(k Key) { ...@@ -65,20 +67,20 @@ func (M *_RangedMap_str) Del(k Key) {
// Has returns whether key k is present in the map. // Has returns whether key k is present in the map.
func (M *_RangedMap_str) Has(k Key) bool { func (M *_RangedMap_str) Has(k Key) bool {
_, ok := M.Get_(k) _, _, ok := M.Get_(k)
return ok return ok
} }
// Get_ is comma-ok version of Get. // Get_ is comma-ok version of Get.
func (M *_RangedMap_str) Get_(k Key) (v string, ok bool) { func (M *_RangedMap_str) Get_(k Key) (v string, r KeyRange, ok bool) {
if trace_RangedMap_str { if trace_RangedMap_str {
fmt.Printf("\n\nGet_:\n") fmt.Printf("\n\nGet_:\n")
fmt.Printf(" M: %s\n", M) fmt.Printf(" M: %s\n", M)
fmt.Printf(" k: %s\n", KStr(k)) fmt.Printf(" k: %s\n", KStr(k))
defer func() { defer func() {
fmt.Printf("->·: %v, %t\n", v, ok) fmt.Printf("->·: %v%s, %t\n", v, r, ok)
}() }()
} }
...@@ -101,7 +103,7 @@ func (M *_RangedMap_str) Get_(k Key) (v string, ok bool) { ...@@ -101,7 +103,7 @@ func (M *_RangedMap_str) Get_(k Key) (v string, ok bool) {
} }
// found // found
return e.Value, true return e.Value, e.KeyRange, true
} }
// SetRange changes M to map key range r to value v. // SetRange changes M to map key range r to value v.
......
...@@ -48,9 +48,11 @@ type _RangedMap_voidEntry struct { ...@@ -48,9 +48,11 @@ type _RangedMap_voidEntry struct {
// Get returns value associated with key k. // Get returns value associated with key k.
func (M *_RangedMap_void) Get(k Key) void { //
v, _ := M.Get_(k) // KeyRange indicates all keys adjacent to k, that are too mapped to the same value.
return v func (M *_RangedMap_void) Get(k Key) (void, KeyRange) {
v, r, _ := M.Get_(k)
return v, r
} }
// Set changes M to map key k to value v. // Set changes M to map key k to value v.
...@@ -65,20 +67,20 @@ func (M *_RangedMap_void) Del(k Key) { ...@@ -65,20 +67,20 @@ func (M *_RangedMap_void) Del(k Key) {
// Has returns whether key k is present in the map. // Has returns whether key k is present in the map.
func (M *_RangedMap_void) Has(k Key) bool { func (M *_RangedMap_void) Has(k Key) bool {
_, ok := M.Get_(k) _, _, ok := M.Get_(k)
return ok return ok
} }
// Get_ is comma-ok version of Get. // Get_ is comma-ok version of Get.
func (M *_RangedMap_void) Get_(k Key) (v void, ok bool) { func (M *_RangedMap_void) Get_(k Key) (v void, r KeyRange, ok bool) {
if trace_RangedMap_void { if trace_RangedMap_void {
fmt.Printf("\n\nGet_:\n") fmt.Printf("\n\nGet_:\n")
fmt.Printf(" M: %s\n", M) fmt.Printf(" M: %s\n", M)
fmt.Printf(" k: %s\n", KStr(k)) fmt.Printf(" k: %s\n", KStr(k))
defer func() { defer func() {
fmt.Printf("->·: %v, %t\n", v, ok) fmt.Printf("->·: %v%s, %t\n", v, r, ok)
}() }()
} }
...@@ -101,7 +103,7 @@ func (M *_RangedMap_void) Get_(k Key) (v void, ok bool) { ...@@ -101,7 +103,7 @@ func (M *_RangedMap_void) Get_(k Key) (v void, ok bool) {
} }
// found // found
return e.Value, true return e.Value, e.KeyRange, true
} }
// SetRange changes M to map key range r to value v. // SetRange changes M to map key range r to value v.
......
...@@ -586,8 +586,10 @@ func (δTtail *_ΔTtail) __rebuild(root zodb.Oid, δBtail *ΔBtail, releaseLock ...@@ -586,8 +586,10 @@ func (δTtail *_ΔTtail) __rebuild(root zodb.Oid, δBtail *ΔBtail, releaseLock
// krebuildJobs += ktrackNew // krebuildJobs += ktrackNew
for _, r := range ktrackNew.AllRanges() { for _, r := range ktrackNew.AllRanges() {
// assert krebuildJobs ^ r = ø
if δTtail.krebuildJobs.IntersectsRange(r) { if δTtail.krebuildJobs.IntersectsRange(r) {
panicf("BUG: rebuild: krebuildJobs ^ ktrackNew != ø:\nkrebuildJobs: %s\nktrackNew: %s", panicf("BUG: rebuild: prologue: " +
"krebuildJobs ^ ktrackNew != ø:\nkrebuildJobs: %s\nktrackNew: %s",
δTtail.krebuildJobs, ktrackNew) δTtail.krebuildJobs, ktrackNew)
} }
δTtail.krebuildJobs.SetRange(r, job) δTtail.krebuildJobs.SetRange(r, job)
...@@ -605,7 +607,13 @@ func (δTtail *_ΔTtail) __rebuild(root zodb.Oid, δBtail *ΔBtail, releaseLock ...@@ -605,7 +607,13 @@ func (δTtail *_ΔTtail) __rebuild(root zodb.Oid, δBtail *ΔBtail, releaseLock
// krebuildJobs -= ktrackNew // krebuildJobs -= ktrackNew
for _, r := range ktrackNew.AllRanges() { for _, r := range ktrackNew.AllRanges() {
// XXX assert krebuildJobs[r] == job // assert krebuildJobs[r] = job
job_, r_ := δTtail.krebuildJobs.Get_(r.Lo)
if !(job_ == job && r_ == r) {
panicf("BUG: rebuild: epilogue: " +
"krebuildJobs entry mutated:\nset in prologue [%s]=%p\ngot in epilogue: [%s]=%p",
r, job, r_, job_)
}
δTtail.krebuildJobs.DelRange(r) δTtail.krebuildJobs.DelRange(r)
} }
......
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