Commit a6bac322 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 7829c494
#!/bin/bash -e #!/bin/bash -e
# rangemap.go.in -> specialized with concrete types # rangemap.go.in -> specialized with concrete types
# gen-rangemap KIND VALUE out # gen-rangemap TYPE VALUE out
# Copyright (C) 2018-2021 Nexedi SA and Contributors. # Copyright (C) 2018-2021 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com> # Kirill Smelkov <kirr@nexedi.com>
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
# See COPYING file for full licensing terms. # See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options. # See https://www.nexedi.com/licensing for rationale and options.
KIND=$1 TYPE=$1
VALUE=$2 VALUE=$2
out=$3 out=$3
...@@ -30,7 +30,7 @@ Value=${VALUE^} ...@@ -30,7 +30,7 @@ Value=${VALUE^}
input=$(dirname $0)/rangemap.go.in input=$(dirname $0)/rangemap.go.in
echo "// Code generated by gen-rangemap; DO NOT EDIT." >$out echo "// Code generated by gen-rangemap $TYPE $VALUE; DO NOT EDIT." >$out
echo >>$out echo >>$out
sed \ sed \
...@@ -38,11 +38,12 @@ sed \ ...@@ -38,11 +38,12 @@ sed \
-e "s/<KIND>/$KIND/g" \ -e "s/<KIND>/$KIND/g" \
-e "s/VALUE/$VALUE/g" \ -e "s/VALUE/$VALUE/g" \
-e "s/<Value>/$Value/g" \ -e "s/<Value>/$Value/g" \
-e "s/\bNode\b/${KIND}Node/g" \ -e "s/\bRangedMap\b/${TYPE}/g" \
-e "s/\bBTree\b/${KIND}BTree/g" \ -e "s/\bRangedMapEntry\b/${TYPE}Entry/g" \
-e "s/\bEntry\b/${KIND}Entry/g" \ -e "s/\bvInsert\b/vInsert_${TYPE}/g" \
-e "s/\bBucket\b/${KIND}Bucket/g" \ -e "s/\bvDeleteSlice\b/vDeleteSlice_${TYPE}/g" \
-e "s/\bBucketEntry\b/${KIND}BucketEntry/g" \ -e "s/\bvReplaceSlice\b/vReplaceSlice_${TYPE}/g"\
-e "s/\bbtreeState\b/${kind}btreeState/g" \ -e "s/\btraceRangeMap\b/trace${TYPE}/g" \
-e "s/\bbucketState\b/${kind}bucketState/g" \ -e "s/\bdebugRangeMap\b/debug${TYPE}/g" \
-e "s/\bdebugfRMap\b/debugf${TYPE}/g" \
$input >>$out $input >>$out
...@@ -35,11 +35,11 @@ type RangedMap struct { ...@@ -35,11 +35,11 @@ type RangedMap struct {
// TODO rework to use BTree lo->hi_ instead if in practice in treediff, // TODO rework to use BTree lo->hi_ instead if in practice in treediff,
// and other usage places, N(ranges) turns out to be not small // and other usage places, N(ranges) turns out to be not small
// (i.e. performance turns out to be not acceptable) // (i.e. performance turns out to be not acceptable)
entryv []RangeMapEntry // lo entryv []RangedMapEntry // lo
} }
// RangeMapEntry represents one entry in RangedMap. // RangedMapEntry represents one entry in RangedMap.
type RangeMapEntry struct { type RangedMapEntry struct {
KeyRange KeyRange
Value VALUE Value VALUE
} }
...@@ -102,12 +102,9 @@ func (M *RangedMap) Get_(k Key) (v VALUE, ok bool) { ...@@ -102,12 +102,9 @@ func (M *RangedMap) Get_(k Key) (v VALUE, ok bool) {
return e.value, true return e.value, true
} }
// SetRange changes M to map key range r to value v. // SetRange changes M to map key range r to value v.
func (M *RangedMap) SetRange(r KeyRange, v VALUE) { func (M *RangedMap) SetRange(r KeyRange, v VALUE) {
e := mapEntry{r,v} e := RangedMapEntry{r,v}
if traceRangeMap { if traceRangeMap {
fmt.Printf("\n\nSetRange:\n") fmt.Printf("\n\nSetRange:\n")
fmt.Printf(" M: %s\n", M) fmt.Printf(" M: %s\n", M)
...@@ -370,10 +367,10 @@ func (M *RangedMap) Clear() { ...@@ -370,10 +367,10 @@ func (M *RangedMap) Clear() {
M.entryv = nil M.entryv = nil
} }
// AllEntries returns slice of all key ranges in the set. // AllRanges returns slice of all key ranges in the set.
// //
// TODO -> iter? // TODO -> iter?
func (M *RangedKeySet) AllEntries() /*readonly*/[]RangeMapEntry { func (M *RangedKeySet) AllRanges() /*readonly*/[]RangedMapEntry {
return M.entryv return M.entryv
} }
...@@ -390,7 +387,7 @@ func (M RangedMap) String() string { ...@@ -390,7 +387,7 @@ func (M RangedMap) String() string {
return s return s
} }
func (e *mapEntry) String() string { func (e *RangedMapEntry) String() string {
s := e.keycov.String() s := e.keycov.String()
v := fmt.Sprintf("%v", e.value) v := fmt.Sprintf("%v", e.value)
if v != "" { // omit ":<v>" in the case of set if v != "" { // omit ":<v>" in the case of set
...@@ -411,16 +408,16 @@ func debugfRMap(format string, argv ...interface{}) { ...@@ -411,16 +408,16 @@ func debugfRMap(format string, argv ...interface{}) {
// ---- slice ops ---- // ---- slice ops ----
// vInsert inserts e into *pv[i]. // vInsert inserts e into *pv[i].
func vInsert(pv *[]RangeMapEntry, i int, e RangeMapEntry) { func vInsert(pv *[]RangedMapEntry, i int, e RangedMapEntry) {
v := *pv v := *pv
v = append(v, RangeMapEntry{}) v = append(v, RangedMapEntry{})
copy(v[i+1:], v[i:]) copy(v[i+1:], v[i:])
v[i] = e v[i] = e
*pv = v *pv = v
} }
// vDeleteSlice deletes *pv[lo:hi]. // vDeleteSlice deletes *pv[lo:hi].
func vDeleteSlice(pv *[]RangeMapEntry, lo,hi int) { func vDeleteSlice(pv *[]RangedMapEntry, lo,hi int) {
v := *pv v := *pv
n := copy(v[lo:], v[hi:]) n := copy(v[lo:], v[hi:])
v = v[:lo+n] v = v[:lo+n]
...@@ -428,7 +425,7 @@ func vDeleteSlice(pv *[]RangeMapEntry, lo,hi int) { ...@@ -428,7 +425,7 @@ func vDeleteSlice(pv *[]RangeMapEntry, lo,hi int) {
} }
// vReplaceSlice replaces *pv[lo:hi] with e. // vReplaceSlice replaces *pv[lo:hi] with e.
func vReplaceSlice(pv *[]RangeMapEntry, lo,hi int, e RangeMapEntry) { func vReplaceSlice(pv *[]RangedMapEntry, lo,hi int, e RangedMapEntry) {
v := *pv v := *pv
n := copy(v[lo+1:], v[hi:]) n := copy(v[lo+1:], v[hi:])
v[lo] = e v[lo] = e
......
...@@ -20,16 +20,19 @@ ...@@ -20,16 +20,19 @@
package blib package blib
// set of [lo,hi) Key ranges. // set of [lo,hi) Key ranges.
//go:generate gen-rangemap void struct{} zrangemap_void.go //go:generate ./gen-rangemap _RangedMap_void void zrangemap_void.go
// RangedKeySet is set of Keys with adjacent keys coalesced into Ranges. // RangedKeySet is set of Keys with adjacent keys coalesced into Ranges.
// //
// Zero value represents empty set. // Zero value represents empty set.
type RangedKeySet struct { type RangedKeySet struct {
m _RangedKeyMap_void // XXX naming m _RangedMap_void // XXX naming
} }
// void is used as value type for RangedMap to be used as set.
type void struct{}
func (_ void) String() string { return "" }
// Union returns RangedKeySet(A.keys | B.keys). // Union returns RangedKeySet(A.keys | B.keys).
......
This diff is collapsed.
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