Commit 58f94ed4 authored by Kirill Smelkov's avatar Kirill Smelkov

X Fix RangedMap to be usable from outide of blib package

parent 6ae828b3
......@@ -26,10 +26,27 @@ VALUE=$2
out=$3
input=$(dirname $0)/rangemap.go.in
blib=$(cd $(dirname $0) && go list) # fullpath for blib package
curr=$(go list) # ----//---- current package
pkgname=$(go list -f {{.Name}}) # name of current package
echo "// Code generated by gen-rangemap $TYPE $VALUE; DO NOT EDIT." >$out
echo >>$out
# fiximports adjusts rangemap.go code to work outside of blib packages.
fiximports() {
if [ "$curr" == "$blib" ]; then
cat
return
fi
sed \
-e "/package blib/a \\\\nimport \"$blib\"\\n" \
-e "s/package blib/package $pkgname/g" \
-e 's/\([^\w.]\)KeyRange\b/\1blib.KeyRange/g' \
-e 's/\bKStr\b/blib.KStr/g'
}
sed \
-e "s/VALUE/$VALUE/g" \
-e "s/\bRangedMap\b/${TYPE}/g" \
......@@ -40,4 +57,4 @@ sed \
-e "s/\btraceRangeMap\b/trace${TYPE}/g" \
-e "s/\bdebugRangeMap\b/debug${TYPE}/g" \
-e "s/\bdebugfRMap\b/debugf${TYPE}/g" \
$input >>$out
$input |fiximports >>$out
......@@ -19,7 +19,10 @@
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
package blib
package xbtree
import "lab.nexedi.com/nexedi/wendelin.core/wcfs/internal/xbtree/blib"
// map [lo,hi) Key ranges to values.
import (
......@@ -43,7 +46,7 @@ type _RangedMap_RebuildJob struct {
// _RangedMap_RebuildJobEntry represents one entry in _RangedMap_RebuildJob.
type _RangedMap_RebuildJobEntry struct {
Value _RebuildJob
KeyRange
blib.KeyRange
}
......@@ -55,12 +58,12 @@ func (M *_RangedMap_RebuildJob) Get(k Key) _RebuildJob {
// Set changes M to map key k to value v.
func (M *_RangedMap_RebuildJob) Set(k Key, v _RebuildJob) {
M.SetRange(KeyRange{Lo: k, Hi_: k}, v)
M.SetRange(blib.KeyRange{Lo: k, Hi_: k}, v)
}
// Del removes key k.
func (M *_RangedMap_RebuildJob) Del(k Key) {
M.DelRange(KeyRange{Lo: k, Hi_: k})
M.DelRange(blib.KeyRange{Lo: k, Hi_: k})
}
// Has returns whether key k is present in the map.
......@@ -76,7 +79,7 @@ func (M *_RangedMap_RebuildJob) Get_(k Key) (v _RebuildJob, ok bool) {
if trace_RangedMap_RebuildJob {
fmt.Printf("\n\nGet_:\n")
fmt.Printf(" M: %s\n", M)
fmt.Printf(" k: %s\n", KStr(k))
fmt.Printf(" k: %s\n", blib.KStr(k))
defer func() {
fmt.Printf("->·: %v, %t\n", v, ok)
}()
......@@ -105,7 +108,7 @@ func (M *_RangedMap_RebuildJob) Get_(k Key) (v _RebuildJob, ok bool) {
}
// SetRange changes M to map key range r to value v.
func (M *_RangedMap_RebuildJob) SetRange(r KeyRange, v _RebuildJob) {
func (M *_RangedMap_RebuildJob) SetRange(r blib.KeyRange, v _RebuildJob) {
e := _RangedMap_RebuildJobEntry{v,r}
if trace_RangedMap_RebuildJob {
fmt.Printf("\n\nSetRange:\n")
......@@ -134,7 +137,7 @@ func (M *_RangedMap_RebuildJob) SetRange(r KeyRange, v _RebuildJob) {
right := M.entryv[i+1]
if (x.Hi_+1 == right.Lo) && (v == right.Value) {
vReplaceSlice__RangedMap_RebuildJob(&M.entryv, i,i+2,
_RangedMap_RebuildJobEntry{v, KeyRange{x.Lo, right.Hi_}})
_RangedMap_RebuildJobEntry{v, blib.KeyRange{x.Lo, right.Hi_}})
debugf_RangedMap_RebuildJob("\tmerge right\t-> %s\n", M)
}
}
......@@ -144,7 +147,7 @@ func (M *_RangedMap_RebuildJob) SetRange(r KeyRange, v _RebuildJob) {
x := M.entryv[i]
if (left.Hi_+1 == x.Lo) && (left.Value == v) {
vReplaceSlice__RangedMap_RebuildJob(&M.entryv, i-1,i+1,
_RangedMap_RebuildJobEntry{v, KeyRange{left.Lo, x.Hi_}})
_RangedMap_RebuildJobEntry{v, blib.KeyRange{left.Lo, x.Hi_}})
debugf_RangedMap_RebuildJob("\tmerge left\t-> %s\n", M)
}
}
......@@ -182,7 +185,7 @@ func (M *_RangedMap_RebuildJob) SetRange(r KeyRange, v _RebuildJob) {
if (jhi - ilo) > 1 {
lo := S.rangev[ilo].Lo
hi_ := S.rangev[jhi-1].Hi_
vReplaceSlice__RangedMap_RebuildJob(&S.rangev, ilo,jhi, KeyRange{lo,hi_})
vReplaceSlice__RangedMap_RebuildJob(&S.rangev, ilo,jhi, blib.KeyRange{lo,hi_})
debugfRSet("\tmerge S[%d:%d]\t-> %s\n", ilo, jhi, S)
}
jhi = -1 // no longer valid
......@@ -208,7 +211,7 @@ func (M *_RangedMap_RebuildJob) SetRange(r KeyRange, v _RebuildJob) {
if ilo+1 < len(S.rangev) { // right
if S.rangev[ilo].Hi_+1 == S.rangev[ilo+1].Lo {
vReplaceSlice__RangedMap_RebuildJob(&S.rangev, ilo,ilo+2,
KeyRange{S.rangev[ilo].Lo, S.rangev[ilo+1].Hi_})
blib.KeyRange{S.rangev[ilo].Lo, S.rangev[ilo+1].Hi_})
debugfRSet("\tmerge right\t-> %s\n", S)
}
}
......@@ -216,7 +219,7 @@ func (M *_RangedMap_RebuildJob) SetRange(r KeyRange, v _RebuildJob) {
if ilo > 0 { // left
if S.rangev[ilo-1].Hi_+1 == S.rangev[ilo].Lo {
vReplaceSlice__RangedMap_RebuildJob(&S.rangev, ilo-1,ilo+1,
KeyRange{S.rangev[ilo-1].Lo, S.rangev[ilo].Hi_})
blib.KeyRange{S.rangev[ilo-1].Lo, S.rangev[ilo].Hi_})
debugfRSet("\tmerge left\t-> %s\n", S)
}
}
......@@ -226,7 +229,7 @@ func (M *_RangedMap_RebuildJob) SetRange(r KeyRange, v _RebuildJob) {
}
// DelRange removes range r from the map.
func (M *_RangedMap_RebuildJob) DelRange(r KeyRange) {
func (M *_RangedMap_RebuildJob) DelRange(r blib.KeyRange) {
if trace_RangedMap_RebuildJob {
fmt.Printf("\n\nDelRange:\n")
fmt.Printf(" M: %s\n", M)
......@@ -248,7 +251,7 @@ func (M *_RangedMap_RebuildJob) DelRange(r KeyRange) {
// should be inserted/appended if needed.
//
// r must be !empty.
func (M *_RangedMap_RebuildJob) delRange(r KeyRange) (i int) {
func (M *_RangedMap_RebuildJob) delRange(r blib.KeyRange) (i int) {
// find first ilo: r.Lo < [ilo].hi
l := len(M.entryv)
ilo := sort.Search(l, func(i int) bool {
......@@ -309,7 +312,7 @@ func (M *_RangedMap_RebuildJob) delRange(r KeyRange) (i int) {
}
// HasRange returns whether all keys from range r belong to the map.
func (M *_RangedMap_RebuildJob) HasRange(r KeyRange) (yes bool) {
func (M *_RangedMap_RebuildJob) HasRange(r blib.KeyRange) (yes bool) {
if trace_RangedMap_RebuildJob {
fmt.Printf("\n\nHasRange:\n")
fmt.Printf(" M: %s\n", M)
......@@ -340,7 +343,7 @@ func (M *_RangedMap_RebuildJob) HasRange(r KeyRange) (yes bool) {
lo := r.Lo
for {
e := M.entryv[ilo]
debugf_RangedMap_RebuildJob("\te: %s\ttocheck: %s\n", e, KeyRange{lo, r.Hi_})
debugf_RangedMap_RebuildJob("\te: %s\ttocheck: %s\n", e, blib.KeyRange{lo, r.Hi_})
if lo < e.Lo {
return false // hole in coverage
......
......@@ -189,6 +189,12 @@ type ΔTree struct {
}
// XXX place
type _RebuildJob struct {
// XXX
}
// NewΔBtail creates new empty ΔBtail object.
//
// Initial tracked set is empty.
......
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