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
49dcaf65
Commit
49dcaf65
authored
Jun 03, 2021
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
fa425e7a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
5 deletions
+25
-5
wcfs/internal/xbtree/rangeset.go
wcfs/internal/xbtree/rangeset.go
+25
-5
No files found.
wcfs/internal/xbtree/rangeset.go
View file @
49dcaf65
...
...
@@ -72,29 +72,36 @@ func (S *RangeSet) AddRange(r Range) {
ilo
:=
sort
.
Search
(
l
,
func
(
i
int
)
bool
{
return
r
.
lo
<=
S
.
rangev
[
i
]
.
hi_
})
tracefRSet
(
"
\t
ilo: %d
\n
"
,
ilo
)
if
ilo
==
l
{
// not found
S
.
rangev
=
append
(
S
.
rangev
,
r
)
l
++
tracefRSet
(
"
\t
append %s
\t
-> %s
\n
"
,
r
,
S
)
}
// find
firt jhi: r.hi > =(?) [jhi].lo
// find
last jhi: [jhi].lo < r.hi
jhi
:=
ilo
for
;
jhi
<
l
;
jhi
++
{
if
r
.
hi_
>=
S
.
rangev
[
jhi
]
.
lo
{
for
;;
jhi
++
{
if
jhi
==
l
{
break
}
if
S
.
rangev
[
jhi
]
.
lo
<=
r
.
hi_
{
continue
}
break
}
tracefRSet
(
"
\t
jhi: %d
\n
"
,
jhi
)
// entries in [ilo:jhi) ∈ [r.lo,r.hi) and should be merged into one
if
ilo
<
jhi
{
if
(
jhi
-
ilo
)
>
1
{
lo
:=
S
.
rangev
[
ilo
]
.
lo
hi_
:=
S
.
rangev
[
jhi
-
1
]
.
hi_
S
.
rangev
=
append
(
S
.
rangev
[
:
ilo
],
append
([]
Range
{
Range
{
lo
,
hi_
}},
S
.
rangev
[
jhi
:
]
...
)
...
)
// debugfRangeSet("\tmerge [%d:%d] -> %s\n"
, S)
tracefRSet
(
"
\t
merge [%d:%d]
\t
-> %s
\n
"
,
ilo
,
jhi
,
S
)
}
// if [r.lo,r.hi) was outside of any entry - create new entry
...
...
@@ -103,15 +110,18 @@ func (S *RangeSet) AddRange(r Range) {
S
.
rangev
[
:
ilo
],
append
([]
Range
{
r
},
S
.
rangev
[
ilo
:
]
...
)
...
)
tracefRSet
(
"
\t
insert new %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
tracefRSet
(
"
\t
extend left
\t
-> %s
\n
"
,
S
)
}
if
r
.
hi_
>
S
.
rangev
[
ilo
]
.
hi_
{
S
.
rangev
[
ilo
]
.
hi_
=
r
.
hi_
tracefRSet
(
"
\t
extend right
\t
-> %s
\n
"
,
S
)
}
// and check if we should merge it with right/left neighbours
...
...
@@ -121,6 +131,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
:
]
...
)
...
)
tracefRSet
(
"
\t
merge right
\t
-> %s
\n
"
,
S
)
}
}
...
...
@@ -130,6 +141,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
:
]
...
)
...
)
tracefRSet
(
"
\t
merge left
\t
-> %s
\n
"
,
S
)
}
}
...
...
@@ -266,3 +278,11 @@ func (r Range) String() string {
shi
:=
"∞"
;
if
r
.
hi_
<
KeyMax
{
shi
=
fmt
.
Sprintf
(
"%v"
,
r
.
hi_
+
1
)
}
return
fmt
.
Sprintf
(
"[%s,%s)"
,
slo
,
shi
)
}
func
tracefRSet
(
format
string
,
argv
...
interface
{})
{
if
!
debugRangeSet
{
return
}
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