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
7e092087
Commit
7e092087
authored
Jun 03, 2021
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
51d449a1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
12 deletions
+13
-12
wcfs/internal/xbtree/rangeset.go
wcfs/internal/xbtree/rangeset.go
+13
-12
No files found.
wcfs/internal/xbtree/rangeset.go
View file @
7e092087
...
...
@@ -25,6 +25,7 @@ import (
"sort"
)
const
traceRangeSet
=
true
const
debugRangeSet
=
true
// Range represents [lo,hi) Key range.
...
...
@@ -57,7 +58,7 @@ func (S *RangeSet) Del(k Key) {
// AddRange adds Range r to the set.
func
(
S
*
RangeSet
)
AddRange
(
r
Range
)
{
if
debug
RangeSet
{
if
trace
RangeSet
{
fmt
.
Printf
(
"
\n\n
AddRange:
\n
"
)
fmt
.
Printf
(
" S: %s
\n
"
,
S
)
fmt
.
Printf
(
" r: %s
\n
"
,
r
)
...
...
@@ -72,12 +73,12 @@ func (S *RangeSet) AddRange(r Range) {
ilo
:=
sort
.
Search
(
l
,
func
(
i
int
)
bool
{
return
r
.
lo
<=
S
.
rangev
[
i
]
.
hi_
})
trace
fRSet
(
"
\t
ilo: %d
\n
"
,
ilo
)
debug
fRSet
(
"
\t
ilo: %d
\n
"
,
ilo
)
if
ilo
==
l
{
// not found
S
.
rangev
=
append
(
S
.
rangev
,
r
)
l
++
trace
fRSet
(
"
\t
append %s
\t
-> %s
\n
"
,
r
,
S
)
debug
fRSet
(
"
\t
append %s
\t
-> %s
\n
"
,
r
,
S
)
}
// find last jhi: [jhi].lo < r.hi
...
...
@@ -91,7 +92,7 @@ func (S *RangeSet) AddRange(r Range) {
}
break
}
trace
fRSet
(
"
\t
jhi: %d
\n
"
,
jhi
)
debug
fRSet
(
"
\t
jhi: %d
\n
"
,
jhi
)
// entries in [ilo:jhi) ∈ [r.lo,r.hi) and should be merged into one
if
(
jhi
-
ilo
)
>
1
{
...
...
@@ -101,7 +102,7 @@ func (S *RangeSet) AddRange(r Range) {
S
.
rangev
[
:
ilo
],
append
([]
Range
{
Range
{
lo
,
hi_
}},
S
.
rangev
[
jhi
:
]
...
)
...
)
trace
fRSet
(
"
\t
merge [%d:%d]
\t
-> %s
\n
"
,
ilo
,
jhi
,
S
)
debug
fRSet
(
"
\t
merge [%d:%d]
\t
-> %s
\n
"
,
ilo
,
jhi
,
S
)
}
jhi
=
-
1
// no longer valid
...
...
@@ -111,18 +112,18 @@ func (S *RangeSet) AddRange(r Range) {
S
.
rangev
[
:
ilo
],
append
([]
Range
{
r
},
S
.
rangev
[
ilo
:
]
...
)
...
)
trace
fRSet
(
"
\t
insert %s
\t
-> %s
\n
"
,
r
,
S
)
debug
fRSet
(
"
\t
insert %s
\t
-> %s
\n
"
,
r
,
S
)
}
// now we have covered entries merged as needed into [ilo]
// extend this entry if r coverage is wider
if
r
.
lo
<
S
.
rangev
[
ilo
]
.
lo
{
S
.
rangev
[
ilo
]
.
lo
=
r
.
lo
trace
fRSet
(
"
\t
extend left
\t
-> %s
\n
"
,
S
)
debug
fRSet
(
"
\t
extend left
\t
-> %s
\n
"
,
S
)
}
if
r
.
hi_
>
S
.
rangev
[
ilo
]
.
hi_
{
S
.
rangev
[
ilo
]
.
hi_
=
r
.
hi_
trace
fRSet
(
"
\t
extend right
\t
-> %s
\n
"
,
S
)
debug
fRSet
(
"
\t
extend right
\t
-> %s
\n
"
,
S
)
}
// and check if we should merge it with right/left neighbours
...
...
@@ -132,7 +133,7 @@ func (S *RangeSet) AddRange(r Range) {
S
.
rangev
[
:
ilo
],
append
([]
Range
{
Range
{
S
.
rangev
[
ilo
]
.
lo
,
S
.
rangev
[
ilo
+
1
]
.
hi_
}},
S
.
rangev
[
ilo
+
2
:
]
...
)
...
)
trace
fRSet
(
"
\t
merge right
\t
-> %s
\n
"
,
S
)
debug
fRSet
(
"
\t
merge right
\t
-> %s
\n
"
,
S
)
}
}
...
...
@@ -142,7 +143,7 @@ func (S *RangeSet) AddRange(r Range) {
S
.
rangev
[
:
ilo
-
1
],
append
([]
Range
{
Range
{
S
.
rangev
[
ilo
-
1
]
.
lo
,
S
.
rangev
[
ilo
]
.
hi_
}},
S
.
rangev
[
ilo
+
1
:
]
...
)
...
)
trace
fRSet
(
"
\t
merge left
\t
-> %s
\n
"
,
S
)
debug
fRSet
(
"
\t
merge left
\t
-> %s
\n
"
,
S
)
}
}
...
...
@@ -151,7 +152,7 @@ func (S *RangeSet) AddRange(r Range) {
// Del removes Range r from the set.
func
(
S
*
RangeSet
)
DelRange
(
r
Range
)
{
if
debug
RangeSet
{
if
trace
RangeSet
{
fmt
.
Printf
(
"
\n\n
DelRange:
\n
"
)
fmt
.
Printf
(
" S: %s
\n
"
,
S
)
fmt
.
Printf
(
" r: %s
\n
"
,
r
)
...
...
@@ -281,7 +282,7 @@ func (r Range) String() string {
}
func
trace
fRSet
(
format
string
,
argv
...
interface
{})
{
func
debug
fRSet
(
format
string
,
argv
...
interface
{})
{
if
!
debugRangeSet
{
return
}
...
...
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