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
eff86eeb
Commit
eff86eeb
authored
Jun 03, 2021
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
5d5bf632
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
6 deletions
+15
-6
wcfs/internal/xbtree/rangeset.go
wcfs/internal/xbtree/rangeset.go
+12
-5
wcfs/internal/xbtree/rangeset_test.go
wcfs/internal/xbtree/rangeset_test.go
+3
-1
No files found.
wcfs/internal/xbtree/rangeset.go
View file @
eff86eeb
...
@@ -22,6 +22,7 @@ package xbtree
...
@@ -22,6 +22,7 @@ package xbtree
import
(
import
(
"fmt"
"fmt"
// "sort"
)
)
// Range represents [lo,hi) Key range.
// Range represents [lo,hi) Key range.
...
@@ -54,11 +55,17 @@ func (S *RangeSet) Del(k Key) {
...
@@ -54,11 +55,17 @@ func (S *RangeSet) Del(k Key) {
// AddRange adds Range r to the set.
// AddRange adds Range r to the set.
func
(
S
*
RangeSet
)
AddRange
(
r
Range
)
{
func
(
S
*
RangeSet
)
AddRange
(
r
Range
)
{
S
.
verify
()
defer
S
.
verify
()
panic
(
"TODO"
)
// XXX
panic
(
"TODO"
)
// XXX
}
}
// Del removes Range r from the set.
// Del removes Range r from the set.
func
(
S
*
RangeSet
)
DelRange
(
r
Range
)
{
func
(
S
*
RangeSet
)
DelRange
(
r
Range
)
{
S
.
verify
()
defer
S
.
verify
()
panic
(
"TODO"
)
// XXX
panic
(
"TODO"
)
// XXX
}
}
...
@@ -106,7 +113,7 @@ func (A *RangeSet) DifferenceInplace(B *RangeSet) {
...
@@ -106,7 +113,7 @@ func (A *RangeSet) DifferenceInplace(B *RangeSet) {
// --------
// --------
// verify check RangeSet for internal consistency:
// verify check RangeSet for internal consistency:
// - ranges must be not overlapping and ↑
// - ranges must be not overlapping
nor adjacent
and ↑
func
(
S
*
RangeSet
)
verify
()
{
func
(
S
*
RangeSet
)
verify
()
{
// XXX !debug -> return ?
// XXX !debug -> return ?
...
@@ -127,11 +134,11 @@ func (S *RangeSet) verify() {
...
@@ -127,11 +134,11 @@ func (S *RangeSet) verify() {
hi_Prev
:=
KeyMin
hi_Prev
:=
KeyMin
for
i
,
r
:=
range
S
.
rangev
{
for
i
,
r
:=
range
S
.
rangev
{
if
!
(
hi_Prev
<=
r
.
lo
)
{
if
i
>
0
&&
!
(
hi_Prev
<
r
.
lo
)
{
// NOTE not ≤ - adjacent ranges must be merged
badf
(
"[%d]: lo < hi_Prev"
,
i
)
badf
(
"[%d]: lo <
=
hi_Prev"
,
i
)
}
}
if
!
(
r
.
lo
<
r
.
hi_
)
{
if
!
(
r
.
lo
<
=
r
.
hi_
)
{
badf
(
"[%d]: lo >
=
hi_"
,
i
)
badf
(
"[%d]: lo > hi_"
,
i
)
}
}
hi_Prev
=
r
.
hi_
hi_Prev
=
r
.
hi_
}
}
...
...
wcfs/internal/xbtree/rangeset_test.go
View file @
eff86eeb
...
@@ -46,8 +46,10 @@ func TestRangeSet(t *testing.T) {
...
@@ -46,8 +46,10 @@ func TestRangeSet(t *testing.T) {
}
}
S
:=
&
RangeSet
{}
S
:=
&
RangeSet
{}
for
i
:=
0
;
i
<
l
/
2
;
i
++
{
for
i
:=
0
;
i
<
l
/
2
;
i
++
{
S
.
AddRange
(
Range
{
kv
[
2
*
i
],
kv
[
2
*
i
+
1
]})
// construct .rangev directly, not via AddRange
S
.
rangev
=
append
(
S
.
rangev
,
Range
{
kv
[
2
*
i
],
kv
[
2
*
i
+
1
]})
}
}
S
.
verify
()
return
S
return
S
}
}
...
...
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