Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Kirill Smelkov
wendelin.core
Commits
a5b9b19b
Commit
a5b9b19b
authored
Sep 29, 2021
by
Kirill Smelkov
2
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
X SetRange draftly works
parent
ae51741d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
256 additions
and
22 deletions
+256
-22
wcfs/internal/xbtree/blib/rangemap.go.in
wcfs/internal/xbtree/blib/rangemap.go.in
+81
-3
wcfs/internal/xbtree/blib/rangemap_test.go
wcfs/internal/xbtree/blib/rangemap_test.go
+3
-3
wcfs/internal/xbtree/blib/rangeset_test.go
wcfs/internal/xbtree/blib/rangeset_test.go
+6
-0
wcfs/internal/xbtree/blib/zrangemap_str.go
wcfs/internal/xbtree/blib/zrangemap_str.go
+83
-8
wcfs/internal/xbtree/blib/zrangemap_void.go
wcfs/internal/xbtree/blib/zrangemap_void.go
+83
-8
No files found.
wcfs/internal/xbtree/blib/rangemap.go.in
View file @
a5b9b19b
...
...
@@ -115,6 +115,36 @@ func (M *RangedMap) SetRange(r KeyRange, v VALUE) {
M
.
verify
()
defer
M
.
verify
()
//
clear
range
for
r
and
insert
new
entry
//
TODO
optimize
for
set
case
(
just
merge
all
covered
entries
into
one
)
i
:=
M
.
delRange
(
r
)
vInsert
(&
M
.
entryv
,
i
,
e
)
debugfRMap
(
"
\t
insert %s
\t
-> %s
\n
"
,
e
,
M
)
//
check
if
we
should
merge
inserted
entry
with
right
/
left
neighbours
if
i
+
1
<
len
(
M
.
entryv
)
{
//
right
x
:=
M
.
entryv
[
i
]
right
:=
M
.
entryv
[
i
+
1
]
if
(
x
.
Hi_
+
1
==
right
.
Lo
)
&&
(
v
==
right
.
Value
)
{
vReplaceSlice
(&
M
.
entryv
,
i
,
i
+
2
,
RangedMapEntry
{
v
,
KeyRange
{
x
.
Lo
,
right
.
Hi_
}})
debugfRMap
(
"
\t
merge right
\t
-> %s
\n
"
,
M
)
}
}
if
i
>
0
{
//
left
left
:=
M
.
entryv
[
i
-
1
]
x
:=
M
.
entryv
[
i
]
if
(
left
.
Hi_
+
1
==
x
.
Lo
)
&&
(
left
.
Value
==
v
)
{
vReplaceSlice
(&
M
.
entryv
,
i
-
1
,
i
+
1
,
RangedMapEntry
{
v
,
KeyRange
{
left
.
Lo
,
x
.
Hi_
}})
debugfRMap
(
"
\t
merge left
\t
-> %s
\n
"
,
M
)
}
}
//
done
/*
//
find
first
ilo
:
r
.
Lo
<
[
ilo
].
hi
l
:=
len
(
M
.
entryv
)
ilo
:=
sort
.
Search
(
l
,
func
(
i
int
)
bool
{
...
...
@@ -141,6 +171,45 @@ func (M *RangedMap) SetRange(r KeyRange, v VALUE) {
}
debugfRMap
(
"
\t
jhi: %d
\n
"
,
jhi
)
//
[
ilo
+
1
:
jhi
-
1
]
should
be
deleted
if
(
jhi
-
ilo
)
>
2
{
vDeleteSlice
(&
M
.
entryv
,
ilo
+
1
,
jhi
-
1
)
debugfRMap
(
"
\t
delete M[%d:%d]
\t
-> %s
\n
"
,
ilo
+
1
,
jhi
-
1
,
M
)
}
//
if
r
was
overlapping
with
sole
region
->
presplit
it
TODO
only
if
!vsame
x
:=
M
.
entryv
[
ilo
]
if
jhi
-
ilo
==
1
&&
x
.
Lo
<
r
.
Lo
&&
r
.
Hi_
<
x
.
Hi_
{
vInsert
(&
M
.
entryv
,
ilo
,
x
)
jhi
++
debugfRMap
(
"
\t
presplit copy %s
\t
-> %s
\n
"
,
x
,
M
)
}
jhi
=
-
1
//
no
longer
valid
//
create
new
entry
//
now
it
is
vInsert
(&
M
.
entryv
,
ilo
+
1
,
e
)
//
[
ilo
]
is
now
to
the
left
//
[
ilo
]
and
[
jhi
-
1
]
overlap
with
[
r
.
lo
,
r
.
hi
)
-
XXX
if
jhi
-
ilo
==
1
{
x
:=
M
.
entryv
[
ilo
]
if
x
.
Value
!= v {
vInsert
(&
M
.
entryv
,
ilo
,
x
)
jhi
++
debugfRMap
(
"
\t
presplit copy %s
\t
-> %s
\n
"
,
x
,
M
)
}
else
{
//
XXX
extend
left
/
right
if
needed
XXX
here
?
}
}
if
xl
.
Value
!= v {
}
//
entries
in
[
ilo
:
jhi
)
∈
[
r
.
Lo
,
r
.
hi
)
and
should
be
merged
into
one
//
FIXME
check
different
values
if
(
jhi
-
ilo
)
>
1
{
...
...
@@ -190,6 +259,7 @@ func (M *RangedMap) SetRange(r KeyRange, v VALUE) {
}
//
done
*/
}
//
DelRange
removes
range
r
from
the
map
.
...
...
@@ -204,6 +274,12 @@ func (M *RangedMap) DelRange(r KeyRange) {
M
.
verify
()
defer
M
.
verify
()
M
.
delRange
(
r
)
}
//
delRange
deletes
range
r
from
the
map
and
returns
.
entryv
index
where
r
//
should
be
inserted
/
appended
if
needed
.
func
(
M
*
RangedMap
)
delRange
(
r
KeyRange
)
(
i
int
)
{
//
find
first
ilo
:
r
.
Lo
<
[
ilo
].
hi
l
:=
len
(
M
.
entryv
)
ilo
:=
sort
.
Search
(
l
,
func
(
i
int
)
bool
{
...
...
@@ -213,7 +289,7 @@ func (M *RangedMap) DelRange(r KeyRange) {
if
ilo
==
l
{
//
not
found
debugfRMap
(
"
\t
non-overlap right
\n
"
)
return
return
l
}
//
find
last
jhi
:
[
jhi
].
Lo
<
r
.
hi
...
...
@@ -231,9 +307,11 @@ func (M *RangedMap) DelRange(r KeyRange) {
if
jhi
==
0
{
debugfRMap
(
"
\t
non-overlap left
\n
"
)
return
return
0
}
//
XXX
if
jhi
-
ilo
==
0
{
return
"non-overlap"
}
?
//
[
ilo
+
1
:
jhi
-
1
]
should
be
deleted
//
[
ilo
]
and
[
jhi
-
1
]
overlap
with
[
r
.
lo
,
r
.
hi
)
-
they
should
be
deleted
,
or
shrinked
,
//
or
split
+
shrinked
if
ilo
==
jhi
-
1
and
r
is
inside
[
ilo
]
...
...
@@ -260,6 +338,7 @@ func (M *RangedMap) DelRange(r KeyRange) {
}
//
done
return
ilo
}
//
HasRange
returns
whether
all
keys
from
range
r
belong
to
the
map
.
...
...
@@ -286,7 +365,6 @@ func (M *RangedMap) HasRange(r KeyRange) (yes bool) {
return
false
}
//
scan
right
and
verify
that
whole
r
is
covered
lo
:=
r
.
Lo
for
{
...
...
wcfs/internal/xbtree/blib/rangemap_test.go
View file @
a5b9b19b
...
...
@@ -34,15 +34,15 @@ func TestRangedMap(t *testing.T) {
A
*
RangedMap
B
RangedMapEntry
Set
*
RangedMap
// A.SetRange(B.keycov, B.value)
Del
*
RangedMap
// A.DelRange(B)
Has
bool
// A.HasRange(B)
Del
*
RangedMap
// A.DelRange(B
.keycov
)
Has
bool
// A.HasRange(B
.keycov
)
// XXX Get?
}
E
:=
func
(
A
*
RangedMap
,
B
RangedMapEntry
,
S
,
D
*
RangedMap
,
H
bool
)
testEntry
{
return
testEntry
{
A
,
B
,
S
,
D
,
H
}
}
// M is shorthand to create RangedMap, e.g. M(1,2,
"a", 3,4,"b") will return {[1,2):"a" [3,4):"b"
}.
// M is shorthand to create RangedMap, e.g. M(1,2,
a, 3,4,b) will return {[1,2):a [3,4):b
}.
M
:=
func
(
argv
...
interface
{})
*
RangedMap
{
l
:=
len
(
argv
)
if
l
%
3
!=
0
{
...
...
wcfs/internal/xbtree/blib/rangeset_test.go
View file @
a5b9b19b
...
...
@@ -122,6 +122,12 @@ func TestRangedKeySet(t *testing.T) {
S
(
noo
,
oo
),
// U
S
()),
// D
E
(
S
(
5
,
7
),
// A
S
(
3
,
5
),
// B
S
(
3
,
7
),
// U
S
(
5
,
7
)),
// D
// [1,3) [5,7) + insert [3,5) -> [1,7)
E
(
S
(
1
,
3
,
5
,
7
),
// A
...
...
wcfs/internal/xbtree/blib/zrangemap_str.go
View file @
a5b9b19b
...
...
@@ -117,6 +117,36 @@ func (M *_RangedMap_str) SetRange(r KeyRange, v string) {
M
.
verify
()
defer
M
.
verify
()
// clear range for r and insert new entry
// TODO optimize for set case (just merge all covered entries into one)
i
:=
M
.
delRange
(
r
)
vInsert__RangedMap_str
(
&
M
.
entryv
,
i
,
e
)
debugf_RangedMap_str
(
"
\t
insert %s
\t
-> %s
\n
"
,
e
,
M
)
// check if we should merge inserted entry with right/left neighbours
if
i
+
1
<
len
(
M
.
entryv
)
{
// right
x
:=
M
.
entryv
[
i
]
right
:=
M
.
entryv
[
i
+
1
]
if
(
x
.
Hi_
+
1
==
right
.
Lo
)
&&
(
v
==
right
.
Value
)
{
vReplaceSlice__RangedMap_str
(
&
M
.
entryv
,
i
,
i
+
2
,
_RangedMap_strEntry
{
v
,
KeyRange
{
x
.
Lo
,
right
.
Hi_
}})
debugf_RangedMap_str
(
"
\t
merge right
\t
-> %s
\n
"
,
M
)
}
}
if
i
>
0
{
// left
left
:=
M
.
entryv
[
i
-
1
]
x
:=
M
.
entryv
[
i
]
if
(
left
.
Hi_
+
1
==
x
.
Lo
)
&&
(
left
.
Value
==
v
)
{
vReplaceSlice__RangedMap_str
(
&
M
.
entryv
,
i
-
1
,
i
+
1
,
_RangedMap_strEntry
{
v
,
KeyRange
{
left
.
Lo
,
x
.
Hi_
}})
debugf_RangedMap_str
(
"
\t
merge left
\t
-> %s
\n
"
,
M
)
}
}
// done
/*
// find first ilo: r.Lo < [ilo].hi
l := len(M.entryv)
ilo := sort.Search(l, func(i int) bool {
...
...
@@ -143,6 +173,45 @@ func (M *_RangedMap_str) SetRange(r KeyRange, v string) {
}
debugf_RangedMap_str("\tjhi: %d\n", jhi)
// [ilo+1:jhi-1] should be deleted
if (jhi - ilo) > 2 {
vDeleteSlice__RangedMap_str(&M.entryv, ilo+1,jhi-1)
debugf_RangedMap_str("\tdelete M[%d:%d]\t-> %s\n", ilo+1, jhi-1, M)
}
// if r was overlapping with sole region -> presplit it TODO only if !vsame
x := M.entryv[ilo]
if jhi-ilo == 1 && x.Lo < r.Lo && r.Hi_ < x.Hi_ {
vInsert__RangedMap_str(&M.entryv, ilo, x)
jhi++
debugf_RangedMap_str("\tpresplit copy %s\t-> %s\n", x, M)
}
jhi = -1 // no longer valid
// create new entry
// now it is
vInsert__RangedMap_str(&M.entryv, ilo+1, e)
// [ilo] is now to the left
// [ilo] and [jhi-1] overlap with [r.lo,r.hi) - XXX
if jhi-ilo == 1 {
x := M.entryv[ilo]
if x.Value != v {
vInsert__RangedMap_str(&M.entryv, ilo, x)
jhi++
debugf_RangedMap_str("\tpresplit copy %s\t-> %s\n", x, M)
} else {
// XXX extend left/right if needed XXX here?
}
}
if xl.Value != v {
}
// entries in [ilo:jhi) ∈ [r.Lo,r.hi) and should be merged into one
// FIXME check different values
if (jhi - ilo) > 1 {
...
...
@@ -192,6 +261,7 @@ func (M *_RangedMap_str) SetRange(r KeyRange, v string) {
}
// done
*/
}
// DelRange removes range r from the map.
...
...
@@ -206,6 +276,12 @@ func (M *_RangedMap_str) DelRange(r KeyRange) {
M
.
verify
()
defer
M
.
verify
()
M
.
delRange
(
r
)
}
// delRange deletes range r from the map and returns .entryv index where r
// should be inserted/appended if needed.
func
(
M
*
_RangedMap_str
)
delRange
(
r
KeyRange
)
(
i
int
)
{
// find first ilo: r.Lo < [ilo].hi
l
:=
len
(
M
.
entryv
)
ilo
:=
sort
.
Search
(
l
,
func
(
i
int
)
bool
{
...
...
@@ -215,7 +291,7 @@ func (M *_RangedMap_str) DelRange(r KeyRange) {
if
ilo
==
l
{
// not found
debugf_RangedMap_str
(
"
\t
non-overlap right
\n
"
)
return
return
l
}
// find last jhi: [jhi].Lo < r.hi
...
...
@@ -233,9 +309,11 @@ func (M *_RangedMap_str) DelRange(r KeyRange) {
if
jhi
==
0
{
debugf_RangedMap_str
(
"
\t
non-overlap left
\n
"
)
return
return
0
}
// XXX if jhi - ilo == 0 { return "non-overlap" } ?
// [ilo+1:jhi-1] should be deleted
// [ilo] and [jhi-1] overlap with [r.lo,r.hi) - they should be deleted, or shrinked,
// or split+shrinked if ilo==jhi-1 and r is inside [ilo]
...
...
@@ -262,6 +340,7 @@ func (M *_RangedMap_str) DelRange(r KeyRange) {
}
// done
return
ilo
}
// HasRange returns whether all keys from range r belong to the map.
...
...
@@ -288,7 +367,7 @@ func (M *_RangedMap_str) HasRange(r KeyRange) (yes bool) {
return
false
}
// scan right and verify that whole r is covered
lo
:=
r
.
Lo
for
{
e
:=
M
.
entryv
[
ilo
]
...
...
@@ -298,7 +377,7 @@ func (M *_RangedMap_str) HasRange(r KeyRange) (yes bool) {
return
false
// hole in coverage
}
if
r
.
Hi_
<=
e
.
Hi_
{
return
true
// full coverage
return
true
//
reached
full coverage
}
lo
=
e
.
Hi_
...
...
@@ -311,10 +390,6 @@ func (M *_RangedMap_str) HasRange(r KeyRange) (yes bool) {
return
false
// r's right not fully covered
}
}
// // all keys from r are in M if r ∈ [ilo] XXX not in case of different values
// return (M.entryv[ilo].Lo <= r.Lo && r.Hi_ <= M.entryv[ilo].Hi_)
}
...
...
wcfs/internal/xbtree/blib/zrangemap_void.go
View file @
a5b9b19b
...
...
@@ -117,6 +117,36 @@ func (M *_RangedMap_void) SetRange(r KeyRange, v void) {
M
.
verify
()
defer
M
.
verify
()
// clear range for r and insert new entry
// TODO optimize for set case (just merge all covered entries into one)
i
:=
M
.
delRange
(
r
)
vInsert__RangedMap_void
(
&
M
.
entryv
,
i
,
e
)
debugf_RangedMap_void
(
"
\t
insert %s
\t
-> %s
\n
"
,
e
,
M
)
// check if we should merge inserted entry with right/left neighbours
if
i
+
1
<
len
(
M
.
entryv
)
{
// right
x
:=
M
.
entryv
[
i
]
right
:=
M
.
entryv
[
i
+
1
]
if
(
x
.
Hi_
+
1
==
right
.
Lo
)
&&
(
v
==
right
.
Value
)
{
vReplaceSlice__RangedMap_void
(
&
M
.
entryv
,
i
,
i
+
2
,
_RangedMap_voidEntry
{
v
,
KeyRange
{
x
.
Lo
,
right
.
Hi_
}})
debugf_RangedMap_void
(
"
\t
merge right
\t
-> %s
\n
"
,
M
)
}
}
if
i
>
0
{
// left
left
:=
M
.
entryv
[
i
-
1
]
x
:=
M
.
entryv
[
i
]
if
(
left
.
Hi_
+
1
==
x
.
Lo
)
&&
(
left
.
Value
==
v
)
{
vReplaceSlice__RangedMap_void
(
&
M
.
entryv
,
i
-
1
,
i
+
1
,
_RangedMap_voidEntry
{
v
,
KeyRange
{
left
.
Lo
,
x
.
Hi_
}})
debugf_RangedMap_void
(
"
\t
merge left
\t
-> %s
\n
"
,
M
)
}
}
// done
/*
// find first ilo: r.Lo < [ilo].hi
l := len(M.entryv)
ilo := sort.Search(l, func(i int) bool {
...
...
@@ -143,6 +173,45 @@ func (M *_RangedMap_void) SetRange(r KeyRange, v void) {
}
debugf_RangedMap_void("\tjhi: %d\n", jhi)
// [ilo+1:jhi-1] should be deleted
if (jhi - ilo) > 2 {
vDeleteSlice__RangedMap_void(&M.entryv, ilo+1,jhi-1)
debugf_RangedMap_void("\tdelete M[%d:%d]\t-> %s\n", ilo+1, jhi-1, M)
}
// if r was overlapping with sole region -> presplit it TODO only if !vsame
x := M.entryv[ilo]
if jhi-ilo == 1 && x.Lo < r.Lo && r.Hi_ < x.Hi_ {
vInsert__RangedMap_void(&M.entryv, ilo, x)
jhi++
debugf_RangedMap_void("\tpresplit copy %s\t-> %s\n", x, M)
}
jhi = -1 // no longer valid
// create new entry
// now it is
vInsert__RangedMap_void(&M.entryv, ilo+1, e)
// [ilo] is now to the left
// [ilo] and [jhi-1] overlap with [r.lo,r.hi) - XXX
if jhi-ilo == 1 {
x := M.entryv[ilo]
if x.Value != v {
vInsert__RangedMap_void(&M.entryv, ilo, x)
jhi++
debugf_RangedMap_void("\tpresplit copy %s\t-> %s\n", x, M)
} else {
// XXX extend left/right if needed XXX here?
}
}
if xl.Value != v {
}
// entries in [ilo:jhi) ∈ [r.Lo,r.hi) and should be merged into one
// FIXME check different values
if (jhi - ilo) > 1 {
...
...
@@ -192,6 +261,7 @@ func (M *_RangedMap_void) SetRange(r KeyRange, v void) {
}
// done
*/
}
// DelRange removes range r from the map.
...
...
@@ -206,6 +276,12 @@ func (M *_RangedMap_void) DelRange(r KeyRange) {
M
.
verify
()
defer
M
.
verify
()
M
.
delRange
(
r
)
}
// delRange deletes range r from the map and returns .entryv index where r
// should be inserted/appended if needed.
func
(
M
*
_RangedMap_void
)
delRange
(
r
KeyRange
)
(
i
int
)
{
// find first ilo: r.Lo < [ilo].hi
l
:=
len
(
M
.
entryv
)
ilo
:=
sort
.
Search
(
l
,
func
(
i
int
)
bool
{
...
...
@@ -215,7 +291,7 @@ func (M *_RangedMap_void) DelRange(r KeyRange) {
if
ilo
==
l
{
// not found
debugf_RangedMap_void
(
"
\t
non-overlap right
\n
"
)
return
return
l
}
// find last jhi: [jhi].Lo < r.hi
...
...
@@ -233,9 +309,11 @@ func (M *_RangedMap_void) DelRange(r KeyRange) {
if
jhi
==
0
{
debugf_RangedMap_void
(
"
\t
non-overlap left
\n
"
)
return
return
0
}
// XXX if jhi - ilo == 0 { return "non-overlap" } ?
// [ilo+1:jhi-1] should be deleted
// [ilo] and [jhi-1] overlap with [r.lo,r.hi) - they should be deleted, or shrinked,
// or split+shrinked if ilo==jhi-1 and r is inside [ilo]
...
...
@@ -262,6 +340,7 @@ func (M *_RangedMap_void) DelRange(r KeyRange) {
}
// done
return
ilo
}
// HasRange returns whether all keys from range r belong to the map.
...
...
@@ -288,7 +367,7 @@ func (M *_RangedMap_void) HasRange(r KeyRange) (yes bool) {
return
false
}
// scan right and verify that whole r is covered
lo
:=
r
.
Lo
for
{
e
:=
M
.
entryv
[
ilo
]
...
...
@@ -298,7 +377,7 @@ func (M *_RangedMap_void) HasRange(r KeyRange) (yes bool) {
return
false
// hole in coverage
}
if
r
.
Hi_
<=
e
.
Hi_
{
return
true
// full coverage
return
true
//
reached
full coverage
}
lo
=
e
.
Hi_
...
...
@@ -311,10 +390,6 @@ func (M *_RangedMap_void) HasRange(r KeyRange) (yes bool) {
return
false
// r's right not fully covered
}
}
// // all keys from r are in M if r ∈ [ilo] XXX not in case of different values
// return (M.entryv[ilo].Lo <= r.Lo && r.Hi_ <= M.entryv[ilo].Hi_)
}
...
...
Kirill Smelkov
@kirr
mentioned in commit
b7c560c5
·
Oct 27, 2021
mentioned in commit
b7c560c5
mentioned in commit b7c560c5fd08d93518d3d20ec0633fcbdcd1dc16
Toggle commit list
Kirill Smelkov
@kirr
mentioned in commit
1f2cd49d
·
Oct 28, 2021
mentioned in commit
1f2cd49d
mentioned in commit 1f2cd49d230d897a9e006987d0d3a26df4987a31
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment