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
d587b035
Commit
d587b035
authored
Jun 03, 2021
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
496c7632
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
68 deletions
+84
-68
wcfs/internal/xbtree/rangeset.go
wcfs/internal/xbtree/rangeset.go
+49
-46
wcfs/internal/xbtree/rangeset_test.go
wcfs/internal/xbtree/rangeset_test.go
+10
-10
wcfs/internal/xbtree/treediff.go
wcfs/internal/xbtree/treediff.go
+25
-12
No files found.
wcfs/internal/xbtree/rangeset.go
View file @
d587b035
...
...
@@ -28,42 +28,45 @@ import (
const
traceRangeSet
=
false
const
debugRangeSet
=
false
// Range represents [lo,hi) Key range.
// XXX -> KeyRange?
type
Range
struct
{
// KeyRange represents [lo,hi) Key range.
type
KeyRange
struct
{
lo
Key
hi_
Key
// NOTE _not_ hi) to avoid overflow at ∞; hi = hi_ + 1
}
// RangeSet is set of Keys with adjacent keys coaleced into Ranges.
// Range
dKey
Set is set of Keys with adjacent keys coaleced into Ranges.
//
// Zero value represents empty set.
// XXX -> RangedSet ? RangedKeySet ? RangeKeySet?
type
RangeSet
struct
{
type
RangedKeySet
struct
{
// TODO rework to use BTree lo->hi_ instead if in practice in treediff,
// and other usage places, N(ranges) turns out to be not small
// (i.e. performance turns out to be not acceptable)
rangev
[]
Range
// lo↑
rangev
[]
Key
Range
// lo↑
}
/* XXX temp - reenable
// Add adds key k to the set.
func
(
S
*
RangeSet
)
Add
(
k
Key
)
{
S
.
AddRange
(
Range
{
lo
:
k
,
hi_
:
k
})
func (S *Range
dKey
Set) Add(k Key) {
S.AddRange(
Key
Range{lo: k, hi_: k})
}
// Del removes key k from the set.
func
(
S
*
RangeSet
)
Del
(
k
Key
)
{
S
.
DelRange
(
Range
{
lo
:
k
,
hi_
:
k
})
func (S *Range
dKey
Set) Del(k Key) {
S.DelRange(
Key
Range{lo: k, hi_: k})
}
// Has returns whether key k belongs to the set.
func
(
S
*
RangeSet
)
Has
(
k
Key
)
bool
{
return
S
.
HasRange
(
Range
{
lo
:
k
,
hi_
:
k
})
func (S *Range
dKey
Set) Has(k Key) bool {
return S.HasRange(
Key
Range{lo: k, hi_: k})
}
*/
// AddRange adds
R
ange r to the set.
func
(
S
*
Range
Set
)
AddRange
(
r
Range
)
{
// AddRange adds
r
ange r to the set.
func
(
S
*
Range
dKeySet
)
AddRange
(
r
Key
Range
)
{
if
traceRangeSet
{
fmt
.
Printf
(
"
\n\n
AddRange:
\n
"
)
fmt
.
Printf
(
" S: %s
\n
"
,
S
)
...
...
@@ -105,8 +108,8 @@ func (S *RangeSet) AddRange(r Range) {
lo
:=
S
.
rangev
[
ilo
]
.
lo
hi_
:=
S
.
rangev
[
jhi
-
1
]
.
hi_
S
.
rangev
=
append
(
S
.
rangev
[
:
ilo
],
append
([]
Range
{
Range
{
lo
,
hi_
}},
S
.
rangev
[
:
ilo
],
append
([]
Key
Range
{
Key
Range
{
lo
,
hi_
}},
S
.
rangev
[
jhi
:
]
...
)
...
)
debugfRSet
(
"
\t
merge S[%d:%d]
\t
-> %s
\n
"
,
ilo
,
jhi
,
S
)
}
...
...
@@ -115,7 +118,7 @@ func (S *RangeSet) AddRange(r Range) {
// 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
],
append
([]
Range
{
S
.
rangev
[
:
ilo
],
append
([]
Key
Range
{
r
},
S
.
rangev
[
ilo
:
]
...
)
...
)
debugfRSet
(
"
\t
insert %s
\t
-> %s
\n
"
,
r
,
S
)
...
...
@@ -136,8 +139,8 @@ func (S *RangeSet) AddRange(r Range) {
if
ilo
+
1
<
len
(
S
.
rangev
)
{
// right
if
S
.
rangev
[
ilo
]
.
hi_
+
1
==
S
.
rangev
[
ilo
+
1
]
.
lo
{
S
.
rangev
=
append
(
S
.
rangev
[
:
ilo
],
append
([]
Range
{
Range
{
S
.
rangev
[
ilo
]
.
lo
,
S
.
rangev
[
ilo
+
1
]
.
hi_
}},
S
.
rangev
[
:
ilo
],
append
([]
Key
Range
{
Key
Range
{
S
.
rangev
[
ilo
]
.
lo
,
S
.
rangev
[
ilo
+
1
]
.
hi_
}},
S
.
rangev
[
ilo
+
2
:
]
...
)
...
)
debugfRSet
(
"
\t
merge right
\t
-> %s
\n
"
,
S
)
}
...
...
@@ -146,8 +149,8 @@ func (S *RangeSet) AddRange(r Range) {
if
ilo
>
0
{
// left
if
S
.
rangev
[
ilo
-
1
]
.
hi_
+
1
==
S
.
rangev
[
ilo
]
.
lo
{
S
.
rangev
=
append
(
S
.
rangev
[
:
ilo
-
1
],
append
([]
Range
{
Range
{
S
.
rangev
[
ilo
-
1
]
.
lo
,
S
.
rangev
[
ilo
]
.
hi_
}},
S
.
rangev
[
:
ilo
-
1
],
append
([]
Key
Range
{
Key
Range
{
S
.
rangev
[
ilo
-
1
]
.
lo
,
S
.
rangev
[
ilo
]
.
hi_
}},
S
.
rangev
[
ilo
+
1
:
]
...
)
...
)
debugfRSet
(
"
\t
merge left
\t
-> %s
\n
"
,
S
)
}
...
...
@@ -156,8 +159,8 @@ func (S *RangeSet) AddRange(r Range) {
// done
}
// DelRange removes
R
ange r from the set.
func
(
S
*
Range
Set
)
DelRange
(
r
Range
)
{
// DelRange removes
r
ange r from the set.
func
(
S
*
Range
dKeySet
)
DelRange
(
r
Key
Range
)
{
if
traceRangeSet
{
fmt
.
Printf
(
"
\n\n
DelRange:
\n
"
)
fmt
.
Printf
(
" S: %s
\n
"
,
S
)
...
...
@@ -204,7 +207,7 @@ func (S *RangeSet) DelRange(r Range) {
if
jhi
-
ilo
==
1
&&
S
.
rangev
[
ilo
]
.
lo
<
r
.
lo
&&
r
.
hi_
<
S
.
rangev
[
ilo
]
.
hi_
{
x
:=
S
.
rangev
[
ilo
]
S
.
rangev
=
append
(
S
.
rangev
[
:
ilo
],
append
([]
Range
{
S
.
rangev
[
:
ilo
],
append
([]
Key
Range
{
x
,
x
},
S
.
rangev
[
ilo
+
1
:
]
...
)
...
)
jhi
++
...
...
@@ -212,16 +215,16 @@ func (S *RangeSet) DelRange(r Range) {
}
if
S
.
rangev
[
ilo
]
.
lo
<
r
.
lo
{
// shrink left
S
.
rangev
=
append
(
S
.
rangev
[
:
ilo
],
append
([]
Range
{
Range
{
S
.
rangev
[
ilo
]
.
lo
,
r
.
lo
-
1
}},
S
.
rangev
[
:
ilo
],
append
([]
Key
Range
{
Key
Range
{
S
.
rangev
[
ilo
]
.
lo
,
r
.
lo
-
1
}},
S
.
rangev
[
ilo
+
1
:
]
...
)
...
)
ilo
++
debugfRSet
(
"
\t
shrink [%d] left
\t
-> %s
\n
"
,
ilo
,
S
)
}
if
r
.
hi_
<
S
.
rangev
[
jhi
-
1
]
.
hi_
{
// shrink right
S
.
rangev
=
append
(
S
.
rangev
[
:
jhi
-
1
],
append
([]
Range
{
Range
{
r
.
hi_
+
1
,
S
.
rangev
[
jhi
-
1
]
.
hi_
}},
S
.
rangev
[
:
jhi
-
1
],
append
([]
Key
Range
{
Key
Range
{
r
.
hi_
+
1
,
S
.
rangev
[
jhi
-
1
]
.
hi_
}},
S
.
rangev
[
jhi
:
]
...
)
...
)
jhi
--
debugfRSet
(
"
\t
shrink [%d] right
\t
-> %s
\n
"
,
jhi
-
1
,
S
)
...
...
@@ -237,8 +240,8 @@ func (S *RangeSet) DelRange(r Range) {
// done
}
// HasRange returns whether all keys from
R
ange r belong to the set.
func
(
S
*
Range
Set
)
HasRange
(
r
Range
)
(
yes
bool
)
{
// HasRange returns whether all keys from
r
ange r belong to the set.
func
(
S
*
Range
dKeySet
)
HasRange
(
r
Key
Range
)
(
yes
bool
)
{
if
traceRangeSet
{
fmt
.
Printf
(
"
\n\n
HasRange:
\n
"
)
fmt
.
Printf
(
" S: %s
\n
"
,
S
)
...
...
@@ -266,15 +269,15 @@ func (S *RangeSet) HasRange(r Range) (yes bool) {
}
// Union returns RangeSet(A.keys | B.keys).
func
(
A
*
Range
Set
)
Union
(
B
*
RangeSet
)
*
Range
Set
{
// Union returns Range
dKey
Set(A.keys | B.keys).
func
(
A
*
Range
dKeySet
)
Union
(
B
*
RangedKeySet
)
*
RangedKey
Set
{
U
:=
A
.
Clone
()
U
.
UnionInplace
(
B
)
return
U
}
// Difference returns RangeSet(A.keys \ B.keys).
func
(
A
*
Range
Set
)
Difference
(
B
*
RangeSet
)
*
Range
Set
{
// Difference returns Range
dKey
Set(A.keys \ B.keys).
func
(
A
*
Range
dKeySet
)
Difference
(
B
*
RangedKeySet
)
*
RangedKey
Set
{
D
:=
A
.
Clone
()
D
.
DifferenceInplace
(
B
)
return
D
...
...
@@ -282,7 +285,7 @@ func (A *RangeSet) Difference(B *RangeSet) *RangeSet {
// XXX Intersection
func
(
A
*
Range
Set
)
UnionInplace
(
B
*
Range
Set
)
{
func
(
A
*
Range
dKeySet
)
UnionInplace
(
B
*
RangedKey
Set
)
{
A
.
verify
()
B
.
verify
()
defer
A
.
verify
()
...
...
@@ -293,7 +296,7 @@ func (A *RangeSet) UnionInplace(B *RangeSet) {
}
}
func
(
A
*
Range
Set
)
DifferenceInplace
(
B
*
Range
Set
)
{
func
(
A
*
Range
dKeySet
)
DifferenceInplace
(
B
*
RangedKey
Set
)
{
A
.
verify
()
B
.
verify
()
defer
A
.
verify
()
...
...
@@ -310,9 +313,9 @@ func (A *RangeSet) DifferenceInplace(B *RangeSet) {
// --------
// verify check RangeSet for internal consistency:
// verify check Range
dKey
Set for internal consistency:
// - ranges must be not overlapping nor adjacent and ↑
func
(
S
*
RangeSet
)
verify
()
{
func
(
S
*
Range
dKey
Set
)
verify
()
{
// XXX !debug -> return ?
var
badv
[]
string
...
...
@@ -344,19 +347,19 @@ func (S *RangeSet) verify() {
}
// Clone returns copy of the set.
func
(
orig
*
Range
Set
)
Clone
()
*
Range
Set
{
klon
:=
&
RangeSet
{}
func
(
orig
*
Range
dKeySet
)
Clone
()
*
RangedKey
Set
{
klon
:=
&
Range
dKey
Set
{}
klon
.
rangev
=
append
(
klon
.
rangev
,
orig
.
rangev
...
)
return
klon
}
// Empty returns whether the set is empty.
func
(
S
*
RangeSet
)
Empty
()
bool
{
func
(
S
*
Range
dKey
Set
)
Empty
()
bool
{
return
len
(
S
.
rangev
)
==
0
}
// Equal returns whether A == B.
func
(
A
*
Range
Set
)
Equal
(
B
*
Range
Set
)
bool
{
func
(
A
*
Range
dKeySet
)
Equal
(
B
*
RangedKey
Set
)
bool
{
if
len
(
A
.
rangev
)
!=
len
(
B
.
rangev
)
{
return
false
}
...
...
@@ -370,11 +373,11 @@ func (A *RangeSet) Equal(B *RangeSet) bool {
}
// Clear removes all elements from the set.
func
(
S
*
RangeSet
)
Clear
()
{
func
(
S
*
Range
dKey
Set
)
Clear
()
{
S
.
rangev
=
nil
}
func
(
S
RangeSet
)
String
()
string
{
func
(
S
Range
dKey
Set
)
String
()
string
{
s
:=
"{"
for
i
,
r
:=
range
S
.
rangev
{
if
i
>
0
{
...
...
@@ -386,7 +389,7 @@ func (S RangeSet) String() string {
return
s
}
func
(
r
Range
)
String
()
string
{
func
(
r
Key
Range
)
String
()
string
{
slo
:=
"-∞"
;
if
r
.
lo
>
KeyMin
{
slo
=
fmt
.
Sprintf
(
"%v"
,
r
.
lo
)
}
shi
:=
"∞"
;
if
r
.
hi_
<
KeyMax
{
shi
=
fmt
.
Sprintf
(
"%v"
,
r
.
hi_
+
1
)
}
return
fmt
.
Sprintf
(
"[%s,%s)"
,
slo
,
shi
)
...
...
wcfs/internal/xbtree/rangeset_test.go
View file @
d587b035
...
...
@@ -23,28 +23,28 @@ import (
"testing"
)
func
TestRangeSet
(
t
*
testing
.
T
)
{
func
TestRange
dKey
Set
(
t
*
testing
.
T
)
{
const
(
oo
=
KeyMax
noo
=
KeyMin
)
type
testEntry
struct
{
A
,
B
*
RangeSet
Union
*
RangeSet
Difference
*
RangeSet
A
,
B
*
Range
dKey
Set
Union
*
Range
dKey
Set
Difference
*
Range
dKey
Set
}
E
:=
func
(
A
,
B
,
U
,
D
*
RangeSet
)
testEntry
{
E
:=
func
(
A
,
B
,
U
,
D
*
Range
dKey
Set
)
testEntry
{
return
testEntry
{
A
,
B
,
U
,
D
}
}
// S is shorthand to create RangeSet, e.g. S(1,2, 4,5) will return {[1,2) [4,5)}
S
:=
func
(
kv
...
Key
)
*
RangeSet
{
// S is shorthand to create Range
dKey
Set, e.g. S(1,2, 4,5) will return {[1,2) [4,5)}
S
:=
func
(
kv
...
Key
)
*
Range
dKey
Set
{
l
:=
len
(
kv
)
if
l
%
2
!=
0
{
panic
(
"odd number of keys"
)
}
S
:=
&
RangeSet
{}
S
:=
&
Range
dKey
Set
{}
for
i
:=
0
;
i
<
l
/
2
;
i
++
{
// construct .rangev directly, not via AddRange
lo
:=
kv
[
2
*
i
]
...
...
@@ -53,7 +53,7 @@ func TestRangeSet(t *testing.T) {
if
hi_
!=
oo
{
hi_
--
}
S
.
rangev
=
append
(
S
.
rangev
,
Range
{
lo
,
hi_
})
S
.
rangev
=
append
(
S
.
rangev
,
Key
Range
{
lo
,
hi_
})
}
S
.
verify
()
return
S
...
...
@@ -145,7 +145,7 @@ func TestRangeSet(t *testing.T) {
}
// assertHasRange asserts for all ranges from rangev that S.HasRange(r) == hasOK
func
assertHasRange
(
t
*
testing
.
T
,
rangev
[]
Range
,
S
*
Range
Set
,
hasOK
bool
)
{
func
assertHasRange
(
t
*
testing
.
T
,
rangev
[]
KeyRange
,
S
*
RangedKey
Set
,
hasOK
bool
)
{
t
.
Helper
()
for
_
,
r
:=
range
rangev
{
has
:=
S
.
HasRange
(
r
)
...
...
wcfs/internal/xbtree/treediff.go
View file @
d587b035
...
...
@@ -177,7 +177,7 @@ func δZConnectTracked(δZv []zodb.Oid, T PPTreeSubSet) (δZTC SetOid, δtopsByR
// nodeInRange represents a Node coming under [lo, hi_] key range in its tree.
type
nodeInRange
struct
{
prefix
[]
zodb
.
Oid
// path to this node goes via this objects
lo
,
hi_
Key
// [lo, hi_] NOTE _not_ hi) not to overflow at ∞
lo
,
hi_
Key
// [lo, hi_] NOTE _not_ hi) not to overflow at ∞
XXX -> Range
node
Node
done
bool
// whether this node was already taken into account while computing diff
}
...
...
@@ -520,20 +520,28 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackSet PPTreeSubSet)
Bv
:=
rangeSplit
{
btop
}
// nodes expanded from B
// for phase 2:
Akqueue
:=
&
RangeSet
{}
// queue for keys in A to be processed for δ-
Bkqueue
:=
&
RangeSet
{}
// ----//---- in B for δ+
Akdone
:=
&
RangeSet
{}
// already processed keys in A
Bkdone
:=
&
RangeSet
{}
// ----//---- in B
Aktodo
:=
func
(
k
Key
)
{
Akqueue
:=
&
RangedKeySet
{}
// queue for keys in A to be processed for δ-
Bkqueue
:=
&
RangedKeySet
{}
// ----//---- in B for δ+
Akdone
:=
&
RangedKeySet
{}
// already processed keys in A
Bkdone
:=
&
RangedKeySet
{}
// ----//---- in B
Aktodo
:=
func
(
r
KeyRange
)
{
if
!
Akdone
.
HasRange
(
r
)
{
δtodo
:=
&
RangedKeySet
{}
δtodo
.
AddRange
(
r
)
δtodo
.
DifferenceInplace
(
Akdone
)
tracef
(
" Akq <- %d
\n
"
,
δtodo
)
Akqueue
.
UnionInplace
(
δtodo
)
}
/* XXX kill
if !Akdone.Has(k) {
tracef(" Akq <- %d\n", k)
Akqueue.Add(k)
}
*/
}
Bktodo
:=
func
(
lo
,
hi_
Key
)
{
// XXX -> func(r Range)
r
:=
Range
{
lo
,
hi_
}
Bktodo
:=
func
(
r
KeyRange
)
{
if
!
Bkdone
.
HasRange
(
r
)
{
δtodo
:=
&
RangeSet
{}
δtodo
:=
&
Range
dKey
Set
{}
δtodo
.
AddRange
(
r
)
δtodo
.
DifferenceInplace
(
Bkdone
)
tracef
(
" Bkq <- %s
\n
"
,
δtodo
)
...
...
@@ -588,13 +596,13 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackSet PPTreeSubSet)
}
*/
// Bkqueue <- ra.range
Bktodo
(
ra
.
lo
,
ra
.
hi_
)
Bktodo
(
KeyRange
{
ra
.
lo
,
ra
.
hi_
}
)
ra
.
done
=
true
case
*
Tree
:
// empty tree - only queue holes covered by it
if
len
(
a
.
Entryv
())
==
0
{
Bktodo
(
ra
.
lo
,
ra
.
hi_
)
Bktodo
(
KeyRange
{
ra
.
lo
,
ra
.
hi_
}
)
/* XXX kill
for k := range holeIdx.GetInRange(ra.lo, ra.hi_) {
Bktodo(k)
...
...
@@ -722,10 +730,15 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackSet PPTreeSubSet)
δtrack
.
Add
.
AddPath
(
b
.
Path
())
// Akqueue <- δB
br
:=
KeyRange
{
b
.
lo
,
b
.
hi_
}
Bkdone
.
AddRange
(
br
)
Aktodo
(
br
)
/*
for k_ := range δB {
Bkdone.Add(k_)
Aktodo(k_)
}
*/
b
.
done
=
true
}
...
...
@@ -752,7 +765,7 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackSet PPTreeSubSet)
δtrack
.
Del
.
AddPath
(
a
.
Path
())
// Bkqueue <- a.range
Bktodo
(
a
.
lo
,
a
.
hi_
)
Bktodo
(
KeyRange
{
a
.
lo
,
a
.
hi_
}
)
/* XXX kill
// Bkqueue <- δA
for k_ := range δA {
...
...
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