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
97edfd89
Commit
97edfd89
authored
Jun 03, 2021
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
eff86eeb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
2 deletions
+69
-2
wcfs/internal/xbtree/rangeset.go
wcfs/internal/xbtree/rangeset.go
+59
-2
wcfs/internal/xbtree/rangeset_test.go
wcfs/internal/xbtree/rangeset_test.go
+10
-0
No files found.
wcfs/internal/xbtree/rangeset.go
View file @
97edfd89
...
...
@@ -22,7 +22,7 @@ package xbtree
import
(
"fmt"
//
"sort"
"sort"
)
// Range represents [lo,hi) Key range.
...
...
@@ -58,7 +58,63 @@ func (S *RangeSet) AddRange(r Range) {
S
.
verify
()
defer
S
.
verify
()
panic
(
"TODO"
)
// XXX
// find first ilo: r.lo < [ilo].hi
l
:=
len
(
S
.
rangev
)
ilo
:=
sort
.
Search
(
l
,
func
(
i
int
)
bool
{
return
r
.
lo
<=
S
.
rangev
[
i
]
.
hi_
})
if
ilo
==
l
{
// not found
// XXX append r; l++
// XXX check & merge with prev
}
// find firt jhi: r.hi > =(?) [jhi].lo
jhi
:=
ilo
for
;
jhi
<
l
;
jhi
++
{
if
r
.
hi_
>=
S
.
rangev
[
jhi
]
.
lo
{
break
}
}
// entries in [ilo:jhi) ∈ [r.lo,r.hi) and should be merged into one
if
ilo
<
jhi
{
lo
:=
S
.
rangev
[
ilo
]
.
lo
hi_
:=
S
.
rangev
[
jhi
-
1
]
.
hi_
S
.
rangev
=
append
(
S
.
rangev
[
:
ilo
],
Range
{
lo
,
hi_
},
S
.
rangev
[
jhi
:
]
...
)
}
// if [r.lo,r.hi) was outside of any entry - create new entry
if
r
.
hi_
<=
S
.
rangev
[
ilo
]
.
lo
{
S
.
rangev
=
append
(
S
.
rangev
[
:
ilo
],
r
,
S
.
rangev
[
ilo
:
])
}
// 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
}
if
r
.
hi_
>
S
.
rangev
[
ilo
]
.
hi_
{
S
.
rangev
[
ilo
]
.
hi_
=
r
.
hi_
}
// and check if we should merge it with right/left neighbours
if
ilo
<
len
(
S
.
rangev
)
{
if
S
.
rangev
[
ilo
]
.
hi_
==
S
.
rangev
[
ilo
+
1
]
.
lo
{
S
.
rangev
=
append
(
S
.
rangev
[
:
ilo
],
Range
{
S
.
rangev
[
ilo
]
.
lo
,
S
.
rangev
[
ilo
+
1
]
.
hi_
},
S
.
rangev
[
ilo
+
2
:
]
...
)
}
}
// done
}
// Del removes Range r from the set.
...
...
@@ -66,6 +122,7 @@ func (S *RangeSet) DelRange(r Range) {
S
.
verify
()
defer
S
.
verify
()
return
// XX temp
panic
(
"TODO"
)
// XXX
}
...
...
wcfs/internal/xbtree/rangeset_test.go
View file @
97edfd89
...
...
@@ -93,6 +93,16 @@ func TestRangeSet(t *testing.T) {
S
(
noo
,
oo
),
// B
S
(
1
,
3
,
5
,
7
,
11
,
100
),
// U
S
()),
// D
// [1,3) [5,7) + insert [3,5) -> [1,7)
E
(
S
(
1
,
3
,
5
,
7
),
// A
S
(
3
,
5
),
// B
S
(
1
,
7
),
// U
S
(
1
,
3
,
5
,
7
)),
// D
// XXX Add to left - merge
// XXX Add to right - merge
}
for
_
,
tt
:=
range
testv
{
...
...
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