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
64b03b76
Commit
64b03b76
authored
Sep 27, 2021
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
db2d48ae
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
46 deletions
+31
-46
wcfs/internal/xbtree/blib/rangemap.go.in
wcfs/internal/xbtree/blib/rangemap.go.in
+31
-46
No files found.
wcfs/internal/xbtree/blib/rangemap.go.in
View file @
64b03b76
...
@@ -66,10 +66,6 @@ func (M *RangedMap) Get(k Key) VALUE {
...
@@ -66,10 +66,6 @@ func (M *RangedMap) Get(k Key) VALUE {
return
v
return
v
}
}
//
Get_
is
comma
-
ok
version
of
Get
.
func
(
M
*
RangedMap
)
Get_
(
k
Key
)
(
VALUE
,
bool
)
{
panic
(
"TODO"
)
//
XXX
}
//
SetRange
changes
M
to
map
key
range
r
to
value
v
.
//
SetRange
changes
M
to
map
key
range
r
to
value
v
.
...
@@ -87,49 +83,38 @@ func (M *RangedMap) HasRange(r KeyRange) bool {
...
@@ -87,49 +83,38 @@ func (M *RangedMap) HasRange(r KeyRange) bool {
panic
(
"TODO"
)
//
XXX
panic
(
"TODO"
)
//
XXX
}
}
//
Get_
is
comma
-
ok
version
of
Get
.
//
--------
func
(
M
*
RangedMap
)
Get_
(
k
Key
)
(
VALUE
,
bool
)
{
panic
(
"TODO"
)
//
XXX
}
//
XXX
Equal
?
//
XXX
AllEntries
?
//
AddRange
adds
range
r
to
the
set
.
//
SetRange
changes
M
to
map
key
range
r
to
value
v
.
func
(
S
*
RangedKeySet
)
AddRange
(
r
KeyRange
)
{
func
(
M
*
RangedMap
)
SetRange
(
r
KeyRange
,
v
VALUE
)
{
if
traceRangeSet
{
if
traceRangeSet
{
fmt
.
Printf
(
"
\n\n
AddRange:
\n
"
)
fmt
.
Printf
(
"
\n\n
AddRange:
\n
"
)
fmt
.
Printf
(
"
S: %s
\n
"
,
S
)
fmt
.
Printf
(
"
M: %s
\n
"
,
M
)
fmt
.
Printf
(
" r: %s
\n
"
,
r
)
fmt
.
Printf
(
" r: %s
\n
"
,
r
)
defer
fmt
.
Printf
(
"->u: %s
\n
"
,
S
)
fmt
.
Printf
(
" v: %s
\n
"
,
v
)
defer
fmt
.
Printf
(
"->u: %s
\n
"
,
M
)
}
}
S
.
verify
()
M
.
verify
()
defer
S
.
verify
()
defer
M
.
verify
()
//
find
first
ilo
:
r
.
Lo
<
[
ilo
].
hi
//
find
first
ilo
:
r
.
Lo
<
[
ilo
].
hi
l
:=
len
(
S
.
rangev
)
l
:=
len
(
S
.
rangev
)
ilo
:=
sort
.
Search
(
l
,
func
(
i
int
)
bool
{
ilo
:=
sort
.
Search
(
l
,
func
(
i
int
)
bool
{
return
r
.
Lo
<=
S
.
rangev
[
i
].
Hi_
return
r
.
Lo
<=
S
.
rangev
[
i
].
Hi_
})
})
debugfR
Set
(
"
\t
ilo: %d
\n
"
,
ilo
)
debugfR
Map
(
"
\t
ilo: %d
\n
"
,
ilo
)
if
ilo
==
l
{
//
not
found
if
ilo
==
l
{
//
not
found
S
.
rangev
=
append
(
S
.
rangev
,
r
)
S
.
rangev
=
append
(
S
.
rangev
,
r
)
l
++
l
++
debugfR
Set
(
"
\t
append %s
\t
-> %s
\n
"
,
r
,
S
)
debugfR
Map
(
"
\t
append %s
\t
-> %s
\n
"
,
r
,
S
)
}
}
//
find
last
jhi
:
[
jhi
].
Lo
<
r
.
hi
//
find
last
jhi
:
[
jhi
].
Lo
<
r
.
hi
...
@@ -143,32 +128,32 @@ func (S *RangedKeySet) AddRange(r KeyRange) {
...
@@ -143,32 +128,32 @@ func (S *RangedKeySet) AddRange(r KeyRange) {
}
}
break
break
}
}
debugfR
Set
(
"
\t
jhi: %d
\n
"
,
jhi
)
debugfR
Map
(
"
\t
jhi: %d
\n
"
,
jhi
)
//
entries
in
[
ilo
:
jhi
)
∈
[
r
.
Lo
,
r
.
hi
)
and
should
be
merged
into
one
//
entries
in
[
ilo
:
jhi
)
∈
[
r
.
Lo
,
r
.
hi
)
and
should
be
merged
into
one
if
(
jhi
-
ilo
)
>
1
{
if
(
jhi
-
ilo
)
>
1
{
lo
:=
S
.
rangev
[
ilo
].
Lo
lo
:=
S
.
rangev
[
ilo
].
Lo
hi_
:=
S
.
rangev
[
jhi
-
1
].
Hi_
hi_
:=
S
.
rangev
[
jhi
-
1
].
Hi_
vReplaceSlice
(&
S
.
rangev
,
ilo
,
jhi
,
KeyRange
{
lo
,
hi_
})
vReplaceSlice
(&
S
.
rangev
,
ilo
,
jhi
,
KeyRange
{
lo
,
hi_
})
debugfR
Set
(
"
\t
merge S[%d:%d]
\t
-> %s
\n
"
,
ilo
,
jhi
,
S
)
debugfR
Map
(
"
\t
merge S[%d:%d]
\t
-> %s
\n
"
,
ilo
,
jhi
,
S
)
}
}
jhi
=
-
1
//
no
longer
valid
jhi
=
-
1
//
no
longer
valid
//
if
[
r
.
lo
,
r
.
hi
)
was
outside
of
any
entry
-
create
new
entry
//
if
[
r
.
lo
,
r
.
hi
)
was
outside
of
any
entry
-
create
new
entry
if
r
.
Hi_
<
S
.
rangev
[
ilo
].
Lo
{
if
r
.
Hi_
<
S
.
rangev
[
ilo
].
Lo
{
vInsert
(&
S
.
rangev
,
ilo
,
r
)
vInsert
(&
S
.
rangev
,
ilo
,
r
)
debugfR
Set
(
"
\t
insert %s
\t
-> %s
\n
"
,
r
,
S
)
debugfR
Map
(
"
\t
insert %s
\t
-> %s
\n
"
,
r
,
S
)
}
}
//
now
we
have
covered
entries
merged
as
needed
into
[
ilo
]
//
now
we
have
covered
entries
merged
as
needed
into
[
ilo
]
//
extend
this
entry
if
r
coverage
is
wider
//
extend
this
entry
if
r
coverage
is
wider
if
r
.
Lo
<
S
.
rangev
[
ilo
].
Lo
{
if
r
.
Lo
<
S
.
rangev
[
ilo
].
Lo
{
S
.
rangev
[
ilo
].
Lo
=
r
.
Lo
S
.
rangev
[
ilo
].
Lo
=
r
.
Lo
debugfR
Set
(
"
\t
extend left
\t
-> %s
\n
"
,
S
)
debugfR
Map
(
"
\t
extend left
\t
-> %s
\n
"
,
S
)
}
}
if
r
.
Hi_
>
S
.
rangev
[
ilo
].
Hi_
{
if
r
.
Hi_
>
S
.
rangev
[
ilo
].
Hi_
{
S
.
rangev
[
ilo
].
Hi_
=
r
.
Hi_
S
.
rangev
[
ilo
].
Hi_
=
r
.
Hi_
debugfR
Set
(
"
\t
extend right
\t
-> %s
\n
"
,
S
)
debugfR
Map
(
"
\t
extend right
\t
-> %s
\n
"
,
S
)
}
}
//
and
check
if
we
should
merge
it
with
right
/
left
neighbours
//
and
check
if
we
should
merge
it
with
right
/
left
neighbours
...
@@ -176,7 +161,7 @@ func (S *RangedKeySet) AddRange(r KeyRange) {
...
@@ -176,7 +161,7 @@ func (S *RangedKeySet) AddRange(r KeyRange) {
if
S
.
rangev
[
ilo
].
Hi_
+
1
==
S
.
rangev
[
ilo
+
1
].
Lo
{
if
S
.
rangev
[
ilo
].
Hi_
+
1
==
S
.
rangev
[
ilo
+
1
].
Lo
{
vReplaceSlice
(&
S
.
rangev
,
ilo
,
ilo
+
2
,
vReplaceSlice
(&
S
.
rangev
,
ilo
,
ilo
+
2
,
KeyRange
{
S
.
rangev
[
ilo
].
Lo
,
S
.
rangev
[
ilo
+
1
].
Hi_
})
KeyRange
{
S
.
rangev
[
ilo
].
Lo
,
S
.
rangev
[
ilo
+
1
].
Hi_
})
debugfR
Set
(
"
\t
merge right
\t
-> %s
\n
"
,
S
)
debugfR
Map
(
"
\t
merge right
\t
-> %s
\n
"
,
S
)
}
}
}
}
...
@@ -184,7 +169,7 @@ func (S *RangedKeySet) AddRange(r KeyRange) {
...
@@ -184,7 +169,7 @@ func (S *RangedKeySet) AddRange(r KeyRange) {
if
S
.
rangev
[
ilo
-
1
].
Hi_
+
1
==
S
.
rangev
[
ilo
].
Lo
{
if
S
.
rangev
[
ilo
-
1
].
Hi_
+
1
==
S
.
rangev
[
ilo
].
Lo
{
vReplaceSlice
(&
S
.
rangev
,
ilo
-
1
,
ilo
+
1
,
vReplaceSlice
(&
S
.
rangev
,
ilo
-
1
,
ilo
+
1
,
KeyRange
{
S
.
rangev
[
ilo
-
1
].
Lo
,
S
.
rangev
[
ilo
].
Hi_
})
KeyRange
{
S
.
rangev
[
ilo
-
1
].
Lo
,
S
.
rangev
[
ilo
].
Hi_
})
debugfR
Set
(
"
\t
merge left
\t
-> %s
\n
"
,
S
)
debugfR
Map
(
"
\t
merge left
\t
-> %s
\n
"
,
S
)
}
}
}
}
...
@@ -208,10 +193,10 @@ func (S *RangedKeySet) DelRange(r KeyRange) {
...
@@ -208,10 +193,10 @@ func (S *RangedKeySet) DelRange(r KeyRange) {
ilo
:=
sort
.
Search
(
l
,
func
(
i
int
)
bool
{
ilo
:=
sort
.
Search
(
l
,
func
(
i
int
)
bool
{
return
r
.
Lo
<=
S
.
rangev
[
i
].
Hi_
return
r
.
Lo
<=
S
.
rangev
[
i
].
Hi_
})
})
debugfR
Set
(
"
\t
ilo: %d
\n
"
,
ilo
)
debugfR
Map
(
"
\t
ilo: %d
\n
"
,
ilo
)
if
ilo
==
l
{
//
not
found
if
ilo
==
l
{
//
not
found
debugfR
Set
(
"
\t
non-overlap right
\n
"
)
debugfR
Map
(
"
\t
non-overlap right
\n
"
)
return
return
}
}
...
@@ -226,10 +211,10 @@ func (S *RangedKeySet) DelRange(r KeyRange) {
...
@@ -226,10 +211,10 @@ func (S *RangedKeySet) DelRange(r KeyRange) {
}
}
break
break
}
}
debugfR
Set
(
"
\t
jhi: %d
\n
"
,
jhi
)
debugfR
Map
(
"
\t
jhi: %d
\n
"
,
jhi
)
if
jhi
==
0
{
if
jhi
==
0
{
debugfR
Set
(
"
\t
non-overlap left
\n
"
)
debugfR
Map
(
"
\t
non-overlap left
\n
"
)
return
return
}
}
...
@@ -240,22 +225,22 @@ func (S *RangedKeySet) DelRange(r KeyRange) {
...
@@ -240,22 +225,22 @@ func (S *RangedKeySet) DelRange(r KeyRange) {
x
:=
S
.
rangev
[
ilo
]
x
:=
S
.
rangev
[
ilo
]
vInsert
(&
S
.
rangev
,
ilo
,
x
)
vInsert
(&
S
.
rangev
,
ilo
,
x
)
jhi
++
jhi
++
debugfR
Set
(
"
\t
presplit copy %s
\t
-> %s
\n
"
,
x
,
S
)
debugfR
Map
(
"
\t
presplit copy %s
\t
-> %s
\n
"
,
x
,
S
)
}
}
if
S
.
rangev
[
ilo
].
Lo
<
r
.
Lo
{
//
shrink
left
if
S
.
rangev
[
ilo
].
Lo
<
r
.
Lo
{
//
shrink
left
S
.
rangev
[
ilo
]
=
KeyRange
{
S
.
rangev
[
ilo
].
Lo
,
r
.
Lo
-
1
}
S
.
rangev
[
ilo
]
=
KeyRange
{
S
.
rangev
[
ilo
].
Lo
,
r
.
Lo
-
1
}
ilo
++
ilo
++
debugfR
Set
(
"
\t
shrink [%d] left
\t
-> %s
\n
"
,
ilo
,
S
)
debugfR
Map
(
"
\t
shrink [%d] left
\t
-> %s
\n
"
,
ilo
,
S
)
}
}
if
r
.
Hi_
<
S
.
rangev
[
jhi
-
1
].
Hi_
{
//
shrink
right
if
r
.
Hi_
<
S
.
rangev
[
jhi
-
1
].
Hi_
{
//
shrink
right
S
.
rangev
[
jhi
-
1
]
=
KeyRange
{
r
.
Hi_
+
1
,
S
.
rangev
[
jhi
-
1
].
Hi_
}
S
.
rangev
[
jhi
-
1
]
=
KeyRange
{
r
.
Hi_
+
1
,
S
.
rangev
[
jhi
-
1
].
Hi_
}
jhi
--
jhi
--
debugfR
Set
(
"
\t
shrink [%d] right
\t
-> %s
\n
"
,
jhi
-
1
,
S
)
debugfR
Map
(
"
\t
shrink [%d] right
\t
-> %s
\n
"
,
jhi
-
1
,
S
)
}
}
if
(
jhi
-
ilo
)
>
0
{
if
(
jhi
-
ilo
)
>
0
{
vDeleteSlice
(&
S
.
rangev
,
ilo
,
jhi
)
vDeleteSlice
(&
S
.
rangev
,
ilo
,
jhi
)
debugfR
Set
(
"
\t
delete S[%d:%d]
\t
-> %s
\n
"
,
ilo
,
jhi
,
S
)
debugfR
Map
(
"
\t
delete S[%d:%d]
\t
-> %s
\n
"
,
ilo
,
jhi
,
S
)
}
}
//
done
//
done
...
@@ -279,7 +264,7 @@ func (S *RangedKeySet) HasRange(r KeyRange) (yes bool) {
...
@@ -279,7 +264,7 @@ func (S *RangedKeySet) HasRange(r KeyRange) (yes bool) {
ilo
:=
sort
.
Search
(
l
,
func
(
i
int
)
bool
{
ilo
:=
sort
.
Search
(
l
,
func
(
i
int
)
bool
{
return
r
.
Lo
<=
S
.
rangev
[
i
].
Hi_
return
r
.
Lo
<=
S
.
rangev
[
i
].
Hi_
})
})
debugfR
Set
(
"
\t
ilo: %d
\n
"
,
ilo
)
debugfR
Map
(
"
\t
ilo: %d
\n
"
,
ilo
)
if
ilo
==
l
{
//
not
found
if
ilo
==
l
{
//
not
found
return
false
return
false
...
@@ -389,8 +374,8 @@ func (M RangedMap) String() string {
...
@@ -389,8 +374,8 @@ func (M RangedMap) String() string {
}
}
func
debugfR
Set
(
format
string
,
argv
...
interface
{})
{
func
debugfR
Map
(
format
string
,
argv
...
interface
{})
{
if
!debugRange
Set
{
if
!debugRange
Map
{
return
return
}
}
fmt
.
Printf
(
format
,
argv
...)
fmt
.
Printf
(
format
,
argv
...)
...
...
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