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
6ea5920a
Commit
6ea5920a
authored
Jun 28, 2021
by
Kirill Smelkov
2
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
X xbtree: Less copy/garbage in RangedKeySet ops
rebuild tests ~75 -> ~73s.
parent
8f0e37f2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
33 deletions
+42
-33
wcfs/.gitignore
wcfs/.gitignore
+1
-0
wcfs/internal/xbtree/rangeset.go
wcfs/internal/xbtree/rangeset.go
+41
-33
No files found.
wcfs/.gitignore
View file @
6ea5920a
/wcfs
/wcfs
*.test
wcfs/internal/xbtree/rangeset.go
View file @
6ea5920a
...
@@ -34,7 +34,7 @@ type KeyRange struct {
...
@@ -34,7 +34,7 @@ type KeyRange struct {
hi_
Key
// NOTE _not_ hi) to avoid overflow at ∞; hi = hi_ + 1
hi_
Key
// NOTE _not_ hi) to avoid overflow at ∞; hi = hi_ + 1
}
}
// RangedKeySet is set of Keys with adjacent keys coaleced into Ranges.
// RangedKeySet is set of Keys with adjacent keys coale
s
ced into Ranges.
//
//
// Zero value represents empty set.
// Zero value represents empty set.
type
RangedKeySet
struct
{
type
RangedKeySet
struct
{
...
@@ -109,20 +109,14 @@ func (S *RangedKeySet) AddRange(r KeyRange) {
...
@@ -109,20 +109,14 @@ func (S *RangedKeySet) AddRange(r KeyRange) {
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_
S
.
rangev
=
append
(
vReplaceSlice
(
&
S
.
rangev
,
ilo
,
jhi
,
KeyRange
{
lo
,
hi_
})
S
.
rangev
[
:
ilo
],
append
([]
KeyRange
{
KeyRange
{
lo
,
hi_
}},
S
.
rangev
[
jhi
:
]
...
)
...
)
debugfRSet
(
"
\t
merge S[%d:%d]
\t
-> %s
\n
"
,
ilo
,
jhi
,
S
)
debugfRSet
(
"
\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
{
S
.
rangev
=
append
(
vInsert
(
&
S
.
rangev
,
ilo
,
r
)
S
.
rangev
[
:
ilo
],
append
([]
KeyRange
{
r
},
S
.
rangev
[
ilo
:
]
...
)
...
)
debugfRSet
(
"
\t
insert %s
\t
-> %s
\n
"
,
r
,
S
)
debugfRSet
(
"
\t
insert %s
\t
-> %s
\n
"
,
r
,
S
)
}
}
...
@@ -140,20 +134,16 @@ func (S *RangedKeySet) AddRange(r KeyRange) {
...
@@ -140,20 +134,16 @@ func (S *RangedKeySet) AddRange(r KeyRange) {
// and check if we should merge it with right/left neighbours
// and check if we should merge it with right/left neighbours
if
ilo
+
1
<
len
(
S
.
rangev
)
{
// right
if
ilo
+
1
<
len
(
S
.
rangev
)
{
// right
if
S
.
rangev
[
ilo
]
.
hi_
+
1
==
S
.
rangev
[
ilo
+
1
]
.
lo
{
if
S
.
rangev
[
ilo
]
.
hi_
+
1
==
S
.
rangev
[
ilo
+
1
]
.
lo
{
S
.
rangev
=
append
(
vReplaceSlice
(
&
S
.
rangev
,
ilo
,
ilo
+
2
,
S
.
rangev
[
:
ilo
],
append
([]
KeyRange
{
KeyRange
{
S
.
rangev
[
ilo
]
.
lo
,
S
.
rangev
[
ilo
+
1
]
.
hi_
})
KeyRange
{
S
.
rangev
[
ilo
]
.
lo
,
S
.
rangev
[
ilo
+
1
]
.
hi_
}},
S
.
rangev
[
ilo
+
2
:
]
...
)
...
)
debugfRSet
(
"
\t
merge right
\t
-> %s
\n
"
,
S
)
debugfRSet
(
"
\t
merge right
\t
-> %s
\n
"
,
S
)
}
}
}
}
if
ilo
>
0
{
// left
if
ilo
>
0
{
// left
if
S
.
rangev
[
ilo
-
1
]
.
hi_
+
1
==
S
.
rangev
[
ilo
]
.
lo
{
if
S
.
rangev
[
ilo
-
1
]
.
hi_
+
1
==
S
.
rangev
[
ilo
]
.
lo
{
S
.
rangev
=
append
(
vReplaceSlice
(
&
S
.
rangev
,
ilo
-
1
,
ilo
+
1
,
S
.
rangev
[
:
ilo
-
1
],
append
([]
KeyRange
{
KeyRange
{
S
.
rangev
[
ilo
-
1
]
.
lo
,
S
.
rangev
[
ilo
]
.
hi_
})
KeyRange
{
S
.
rangev
[
ilo
-
1
]
.
lo
,
S
.
rangev
[
ilo
]
.
hi_
}},
S
.
rangev
[
ilo
+
1
:
]
...
)
...
)
debugfRSet
(
"
\t
merge left
\t
-> %s
\n
"
,
S
)
debugfRSet
(
"
\t
merge left
\t
-> %s
\n
"
,
S
)
}
}
}
}
...
@@ -204,38 +194,27 @@ func (S *RangedKeySet) DelRange(r KeyRange) {
...
@@ -204,38 +194,27 @@ func (S *RangedKeySet) DelRange(r KeyRange) {
}
}
// [ilo+1:jhi-1] should be deleted
// [ilo+1:jhi-1] should be deleted
// [ilo] and [jhi-1] overlap with [r.lo,r.hi) - they sh
uo
ld be deleted, or shrinked,
// [ilo] and [jhi-1] overlap with [r.lo,r.hi) - they sh
ou
ld be deleted, or shrinked,
// or split+shrinked if ilo==jhi-1 and r is inside [ilo]
// or split+shrinked if ilo==jhi-1 and r is inside [ilo]
if
jhi
-
ilo
==
1
&&
S
.
rangev
[
ilo
]
.
lo
<
r
.
lo
&&
r
.
hi_
<
S
.
rangev
[
ilo
]
.
hi_
{
if
jhi
-
ilo
==
1
&&
S
.
rangev
[
ilo
]
.
lo
<
r
.
lo
&&
r
.
hi_
<
S
.
rangev
[
ilo
]
.
hi_
{
x
:=
S
.
rangev
[
ilo
]
x
:=
S
.
rangev
[
ilo
]
S
.
rangev
=
append
(
vInsert
(
&
S
.
rangev
,
ilo
,
x
)
S
.
rangev
[
:
ilo
],
append
([]
KeyRange
{
x
,
x
},
S
.
rangev
[
ilo
+
1
:
]
...
)
...
)
jhi
++
jhi
++
debugfRSet
(
"
\t
presplit copy %s
\t
-> %s
\n
"
,
x
,
S
)
debugfRSet
(
"
\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
=
append
(
S
.
rangev
[
ilo
]
=
KeyRange
{
S
.
rangev
[
ilo
]
.
lo
,
r
.
lo
-
1
}
S
.
rangev
[
:
ilo
],
append
([]
KeyRange
{
KeyRange
{
S
.
rangev
[
ilo
]
.
lo
,
r
.
lo
-
1
}},
S
.
rangev
[
ilo
+
1
:
]
...
)
...
)
ilo
++
ilo
++
debugfRSet
(
"
\t
shrink [%d] left
\t
-> %s
\n
"
,
ilo
,
S
)
debugfRSet
(
"
\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
=
append
(
S
.
rangev
[
jhi
-
1
]
=
KeyRange
{
r
.
hi_
+
1
,
S
.
rangev
[
jhi
-
1
]
.
hi_
}
S
.
rangev
[
:
jhi
-
1
],
append
([]
KeyRange
{
KeyRange
{
r
.
hi_
+
1
,
S
.
rangev
[
jhi
-
1
]
.
hi_
}},
S
.
rangev
[
jhi
:
]
...
)
...
)
jhi
--
jhi
--
debugfRSet
(
"
\t
shrink [%d] right
\t
-> %s
\n
"
,
jhi
-
1
,
S
)
debugfRSet
(
"
\t
shrink [%d] right
\t
-> %s
\n
"
,
jhi
-
1
,
S
)
}
}
if
(
jhi
-
ilo
)
>
0
{
if
(
jhi
-
ilo
)
>
0
{
S
.
rangev
=
append
(
vDeleteSlice
(
&
S
.
rangev
,
ilo
,
jhi
)
S
.
rangev
[
:
ilo
],
S
.
rangev
[
jhi
:
]
...
)
debugfRSet
(
"
\t
delete S[%d:%d]
\t
-> %s
\n
"
,
ilo
,
jhi
,
S
)
debugfRSet
(
"
\t
delete S[%d:%d]
\t
-> %s
\n
"
,
ilo
,
jhi
,
S
)
}
}
...
@@ -414,3 +393,32 @@ func debugfRSet(format string, argv ...interface{}) {
...
@@ -414,3 +393,32 @@ func debugfRSet(format string, argv ...interface{}) {
}
}
fmt
.
Printf
(
format
,
argv
...
)
fmt
.
Printf
(
format
,
argv
...
)
}
}
// ---- slice ops ----
// vInsert inserts r into *pv[i].
func
vInsert
(
pv
*
[]
KeyRange
,
i
int
,
r
KeyRange
)
{
v
:=
*
pv
v
=
append
(
v
,
KeyRange
{})
copy
(
v
[
i
+
1
:
],
v
[
i
:
])
v
[
i
]
=
r
*
pv
=
v
}
// vDeleteSlice deletes *pv[lo:hi].
func
vDeleteSlice
(
pv
*
[]
KeyRange
,
lo
,
hi
int
)
{
v
:=
*
pv
n
:=
copy
(
v
[
lo
:
],
v
[
hi
:
])
v
=
v
[
:
lo
+
n
]
*
pv
=
v
}
// vReplaceSlice replaces *pv[lo:hi] with r.
func
vReplaceSlice
(
pv
*
[]
KeyRange
,
lo
,
hi
int
,
r
KeyRange
)
{
v
:=
*
pv
n
:=
copy
(
v
[
lo
+
1
:
],
v
[
hi
:
])
v
[
lo
]
=
r
v
=
v
[
:
lo
+
1
+
n
]
*
pv
=
v
}
Kirill Smelkov
@kirr
mentioned in commit
b7c560c5
·
Oct 27, 2021
mentioned in commit
b7c560c5
mentioned in commit b7c560c5fd08d93518d3d20ec0633fcbdcd1dc16
Toggle commit list
Kirill Smelkov
@kirr
mentioned in commit
1f2cd49d
·
Oct 28, 2021
mentioned in commit
1f2cd49d
mentioned in commit 1f2cd49d230d897a9e006987d0d3a26df4987a31
Toggle commit list
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