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
696428d9
Commit
696428d9
authored
Sep 27, 2021
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
64b03b76
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
44 deletions
+44
-44
wcfs/internal/xbtree/blib/rangemap.go.in
wcfs/internal/xbtree/blib/rangemap.go.in
+44
-44
No files found.
wcfs/internal/xbtree/blib/rangemap.go.in
View file @
696428d9
...
...
@@ -40,7 +40,7 @@ type RangedMap struct {
//
mapEntry
represents
one
entry
in
RangedMap
.
type
mapEntry
struct
{
keycov
KeyRange
KeyRange
value
VALUE
}
...
...
@@ -68,16 +68,6 @@ func (M *RangedMap) Get(k Key) VALUE {
//
SetRange
changes
M
to
map
key
range
r
to
value
v
.
func
(
M
*
RangedMap
)
SetRange
(
r
KeyRange
,
v
VALUE
)
{
panic
(
"TODO"
)
//
XXX
}
//
DelRange
removes
range
r
from
the
map
.
func
(
M
*
RangedMap
)
DelRange
(
r
KeyRange
)
{
panic
(
"TODO"
)
//
XXX
}
//
HasRange
returns
whether
all
keys
from
range
r
belong
to
the
map
.
func
(
M
*
RangedMap
)
HasRange
(
r
KeyRange
)
bool
{
panic
(
"TODO"
)
//
XXX
...
...
@@ -93,11 +83,11 @@ func (M *RangedMap) Get_(k Key) (VALUE, bool) {
//
SetRange
changes
M
to
map
key
range
r
to
value
v
.
func
(
M
*
RangedMap
)
SetRange
(
r
KeyRange
,
v
VALUE
)
{
e
:=
mapEntry
{
r
,
v
}
if
traceRangeSet
{
fmt
.
Printf
(
"
\n\n
Add
Range:
\n
"
)
fmt
.
Printf
(
"
\n\n
Set
Range:
\n
"
)
fmt
.
Printf
(
" M: %s
\n
"
,
M
)
fmt
.
Printf
(
" r: %s
\n
"
,
r
)
fmt
.
Printf
(
" v: %s
\n
"
,
v
)
fmt
.
Printf
(
" e: %s
\n
"
,
e
)
defer
fmt
.
Printf
(
"->u: %s
\n
"
,
M
)
}
...
...
@@ -105,16 +95,16 @@ func (M *RangedMap) SetRange(r KeyRange, v VALUE) {
defer
M
.
verify
()
//
find
first
ilo
:
r
.
Lo
<
[
ilo
].
hi
l
:=
len
(
S
.
range
v
)
l
:=
len
(
M
.
entry
v
)
ilo
:=
sort
.
Search
(
l
,
func
(
i
int
)
bool
{
return
r
.
Lo
<=
S
.
range
v
[
i
].
Hi_
return
r
.
Lo
<=
M
.
entry
v
[
i
].
Hi_
})
debugfRMap
(
"
\t
ilo: %d
\n
"
,
ilo
)
if
ilo
==
l
{
//
not
found
S
.
rangev
=
append
(
S
.
rangev
,
r
)
M
.
entryv
=
append
(
M
.
entryv
,
e
)
l
++
debugfRMap
(
"
\t
append %s
\t
-> %s
\n
"
,
r
,
S
)
debugfRMap
(
"
\t
append %s
\t
-> %s
\n
"
,
e
,
M
)
}
//
find
last
jhi
:
[
jhi
].
Lo
<
r
.
hi
...
...
@@ -123,7 +113,7 @@ func (M *RangedMap) SetRange(r KeyRange, v VALUE) {
if
jhi
==
l
{
break
}
if
S
.
range
v
[
jhi
].
Lo
<=
r
.
Hi_
{
if
M
.
entry
v
[
jhi
].
Lo
<=
r
.
Hi_
{
continue
}
break
...
...
@@ -131,6 +121,7 @@ func (M *RangedMap) SetRange(r KeyRange, v VALUE) {
debugfRMap
(
"
\t
jhi: %d
\n
"
,
jhi
)
//
entries
in
[
ilo
:
jhi
)
∈
[
r
.
Lo
,
r
.
hi
)
and
should
be
merged
into
one
//
XXX
check
different
values
if
(
jhi
-
ilo
)
>
1
{
lo
:=
S
.
rangev
[
ilo
].
Lo
hi_
:=
S
.
rangev
[
jhi
-
1
].
Hi_
...
...
@@ -158,7 +149,7 @@ func (M *RangedMap) SetRange(r KeyRange, v VALUE) {
//
and
check
if
we
should
merge
it
with
right
/
left
neighbours
if
ilo
+
1
<
len
(
S
.
rangev
)
{
//
right
if
S
.
rangev
[
ilo
].
Hi_
+
1
==
S
.
rangev
[
ilo
+
1
].
Lo
{
if
S
.
rangev
[
ilo
].
Hi_
+
1
==
S
.
rangev
[
ilo
+
1
].
Lo
{
//
XXX
&&
.
value
same
vReplaceSlice
(&
S
.
rangev
,
ilo
,
ilo
+
2
,
KeyRange
{
S
.
rangev
[
ilo
].
Lo
,
S
.
rangev
[
ilo
+
1
].
Hi_
})
debugfRMap
(
"
\t
merge right
\t
-> %s
\n
"
,
S
)
...
...
@@ -166,7 +157,7 @@ func (M *RangedMap) SetRange(r KeyRange, v VALUE) {
}
if
ilo
>
0
{
//
left
if
S
.
rangev
[
ilo
-
1
].
Hi_
+
1
==
S
.
rangev
[
ilo
].
Lo
{
if
S
.
rangev
[
ilo
-
1
].
Hi_
+
1
==
S
.
rangev
[
ilo
].
Lo
{
//
XXX
&&
.
value
same
vReplaceSlice
(&
S
.
rangev
,
ilo
-
1
,
ilo
+
1
,
KeyRange
{
S
.
rangev
[
ilo
-
1
].
Lo
,
S
.
rangev
[
ilo
].
Hi_
})
debugfRMap
(
"
\t
merge left
\t
-> %s
\n
"
,
S
)
...
...
@@ -176,22 +167,22 @@ func (M *RangedMap) SetRange(r KeyRange, v VALUE) {
//
done
}
//
DelRange
removes
range
r
from
the
set
.
func
(
S
*
RangedKeySet
)
DelRange
(
r
KeyRange
)
{
//
DelRange
removes
range
r
from
the
map
.
func
(
M
*
RangedKeySet
)
DelRange
(
r
KeyRange
)
{
if
traceRangeSet
{
fmt
.
Printf
(
"
\n\n
DelRange:
\n
"
)
fmt
.
Printf
(
"
S: %s
\n
"
,
S
)
fmt
.
Printf
(
"
M: %s
\n
"
,
M
)
fmt
.
Printf
(
" r: %s
\n
"
,
r
)
defer
fmt
.
Printf
(
"->d: %s
\n
"
,
S
)
defer
fmt
.
Printf
(
"->d: %s
\n
"
,
M
)
}
S
.
verify
()
defer
S
.
verify
()
M
.
verify
()
defer
M
.
verify
()
//
find
first
ilo
:
r
.
Lo
<
[
ilo
].
hi
l
:=
len
(
S
.
range
v
)
l
:=
len
(
M
.
entry
v
)
ilo
:=
sort
.
Search
(
l
,
func
(
i
int
)
bool
{
return
r
.
Lo
<=
S
.
range
v
[
i
].
Hi_
return
r
.
Lo
<=
M
.
entry
v
[
i
].
Hi_
})
debugfRMap
(
"
\t
ilo: %d
\n
"
,
ilo
)
...
...
@@ -206,7 +197,7 @@ func (S *RangedKeySet) DelRange(r KeyRange) {
if
jhi
==
l
{
break
}
if
S
.
range
v
[
jhi
].
Lo
<=
r
.
Hi_
{
if
M
.
entry
v
[
jhi
].
Lo
<=
r
.
Hi_
{
continue
}
break
...
...
@@ -221,26 +212,26 @@ func (S *RangedKeySet) DelRange(r KeyRange) {
//
[
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
]
if
jhi
-
ilo
==
1
&&
S
.
rangev
[
ilo
].
Lo
<
r
.
Lo
&&
r
.
Hi_
<
S
.
range
v
[
ilo
].
Hi_
{
x
:=
S
.
range
v
[
ilo
]
vInsert
(&
S
.
range
v
,
ilo
,
x
)
if
jhi
-
ilo
==
1
&&
M
.
entryv
[
ilo
].
Lo
<
r
.
Lo
&&
r
.
Hi_
<
M
.
entry
v
[
ilo
].
Hi_
{
x
:=
M
.
entry
v
[
ilo
]
vInsert
(&
M
.
entry
v
,
ilo
,
x
)
jhi
++
debugfRMap
(
"
\t
presplit copy %s
\t
-> %s
\n
"
,
x
,
S
)
debugfRMap
(
"
\t
presplit copy %s
\t
-> %s
\n
"
,
x
,
M
)
}
if
S
.
range
v
[
ilo
].
Lo
<
r
.
Lo
{
//
shrink
left
S
.
rangev
[
ilo
]
=
KeyRange
{
S
.
rangev
[
ilo
].
Lo
,
r
.
Lo
-
1
}
if
M
.
entry
v
[
ilo
].
Lo
<
r
.
Lo
{
//
shrink
left
M
.
entryv
[
ilo
].
Hi_
=
r
.
Lo
-
1
ilo
++
debugfRMap
(
"
\t
shrink [%d] left
\t
-> %s
\n
"
,
ilo
,
S
)
debugfRMap
(
"
\t
shrink [%d] left
\t
-> %s
\n
"
,
ilo
,
M
)
}
if
r
.
Hi_
<
S
.
range
v
[
jhi
-
1
].
Hi_
{
//
shrink
right
S
.
rangev
[
jhi
-
1
]
=
KeyRange
{
r
.
Hi_
+
1
,
S
.
rangev
[
jhi
-
1
].
Hi_
}
if
r
.
Hi_
<
M
.
entry
v
[
jhi
-
1
].
Hi_
{
//
shrink
right
M
.
entryv
[
jhi
-
1
].
Lo
=
r
.
Hi_
+
1
jhi
--
debugfRMap
(
"
\t
shrink [%d] right
\t
-> %s
\n
"
,
jhi
-
1
,
S
)
debugfRMap
(
"
\t
shrink [%d] right
\t
-> %s
\n
"
,
jhi
-
1
,
M
)
}
if
(
jhi
-
ilo
)
>
0
{
vDeleteSlice
(&
S
.
range
v
,
ilo
,
jhi
)
debugfRMap
(
"
\t
delete
S[%d:%d]
\t
-> %s
\n
"
,
ilo
,
jhi
,
S
)
vDeleteSlice
(&
M
.
entry
v
,
ilo
,
jhi
)
debugfRMap
(
"
\t
delete
M[%d:%d]
\t
-> %s
\n
"
,
ilo
,
jhi
,
M
)
}
//
done
...
...
@@ -315,7 +306,7 @@ func (M *RangedMap) verify() {
}
}
if
!(e.Lo <= e.Hi_) {
badf
(
"[%d]: !(e.lo
<=
e.hi_)"
,
i
)
badf
(
"[%d]: !(e.lo
≤
e.hi_)"
,
i
)
}
hi_Prev
=
e
.
Hi_
v_Prev
=
e
.
value
...
...
@@ -367,12 +358,21 @@ func (M RangedMap) String() string {
if
i
>
0
{
s
+=
" "
}
s
+=
fmt
.
Sprintf
(
"%s:%v"
,
e
.
keycov
,
e
.
value
)
s
+=
e
.
String
(
)
}
s
+=
"}"
return
s
}
func
(
e
*
mapEntry
)
String
()
string
{
s
:=
e
.
keycov
.
String
()
v
:=
fmt
.
Sprintf
(
"%v"
,
e
.
value
)
if
v
!= "" { // omit ":<v>" in the case of set
s
+=
":"
+
v
}
return
s
}
func
debugfRMap
(
format
string
,
argv
...
interface
{})
{
if
!debugRangeMap {
...
...
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