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
abf4ac63
Commit
abf4ac63
authored
May 15, 2021
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
bb76489c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
89 additions
and
84 deletions
+89
-84
wcfs/pptreesubset.go
wcfs/pptreesubset.go
+89
-84
No files found.
wcfs/pptreesubset.go
View file @
abf4ac63
...
@@ -26,6 +26,7 @@ import (
...
@@ -26,6 +26,7 @@ import (
"lab.nexedi.com/kirr/neo/go/zodb"
"lab.nexedi.com/kirr/neo/go/zodb"
)
)
const
debugPPSet
=
false
// PPTreeSubSet repesents PP-connected subset of tree node objects.
// PPTreeSubSet repesents PP-connected subset of tree node objects.
//
//
...
@@ -55,66 +56,6 @@ type nodeInTree struct {
...
@@ -55,66 +56,6 @@ type nodeInTree struct {
// XXX + [lo,hi) range this node is coming under in its parent
// XXX + [lo,hi) range this node is coming under in its parent
}
}
// ΔPPTreeSubSet represents a change to PPTreeSubSet.
//
// It can be applied via PPTreeSubSet.ApplyΔ .
//
// The result B of applying δ to A is:
//
// B = A.xDifference(δ.Del).xUnion(δ.Add) (*)
//
// (*) NOTE δ.Del and δ.Add might have their leafs starting from non-leaf nodes in A/B.
// This situation arises when δ represents a change in path to particular
// node, but that node itself does not change, for example:
//
// c* c
// / \ /
// 41* 42 41
// | | | \
// 22 43 46 43
// | | |
// 44 22 44
//
// Here nodes {c, 41} are changed, node 42 is unlinked, and node 46 is added.
// Nodes 43 and 44 stay unchanged.
//
// δ.Del = c-42-43 | c-41-22
// δ.Add = c-41-43 | c-41-46-22
//
// The second component with "-22" builds from leaf, but the first
// component with "-43" builds from non-leaf node.
//
// δnchildNonLeafs = {43: +1}
//
// Only complete result of applying all
//
// - xfixup(-1, δnchildNonLeafs)
// - δ.Del,
// - δ.Add, and
// - xfixup(+1, δnchildNonLeafs)
//
// produce correctly PP-connected set.
type
ΔPPTreeSubSet
struct
{
Del
PPTreeSubSet
Add
PPTreeSubSet
δnchildNonLeafs
map
[
zodb
.
Oid
]
int
}
// Update updates δ to be combination of δ+δ2.
func
(
δ
*
ΔPPTreeSubSet
)
Update
(
δ2
*
ΔPPTreeSubSet
)
{
δ
.
Del
.
UnionInplace
(
δ2
.
Del
)
δ
.
Add
.
UnionInplace
(
δ2
.
Add
)
for
oid
,
δnc
:=
range
δ2
.
δnchildNonLeafs
{
δ
.
δnchildNonLeafs
[
oid
]
+=
δnc
}
}
// Reverse changes δ=diff(A->B) to δ'=diff(A<-B).
func
(
δ
*
ΔPPTreeSubSet
)
Reverse
()
{
δ
.
Del
,
δ
.
Add
=
δ
.
Add
,
δ
.
Del
// δnchildNonLeafs stays the same
}
// verify checks internal consistency of S.
// verify checks internal consistency of S.
func
(
S
PPTreeSubSet
)
verify
()
{
func
(
S
PPTreeSubSet
)
verify
()
{
...
@@ -316,29 +257,6 @@ func (A PPTreeSubSet) UnionInplace(B PPTreeSubSet) {
...
@@ -316,29 +257,6 @@ func (A PPTreeSubSet) UnionInplace(B PPTreeSubSet) {
A
.
xUnionInplace
(
B
)
A
.
xUnionInplace
(
B
)
}
}
// ApplyΔ applies δ to S.
//
// See ΔPPTreeSubSet documentation for details.
func
(
S
PPTreeSubSet
)
ApplyΔ
(
δ
*
ΔPPTreeSubSet
)
{
if
debugPPSet
{
fmt
.
Printf
(
"
\n\n
ApplyΔ
\n
"
)
fmt
.
Printf
(
" A: %s
\n
"
,
S
)
fmt
.
Printf
(
" -: %s
\n
"
,
δ
.
Del
)
fmt
.
Printf
(
" +: %s
\n
"
,
δ
.
Add
)
fmt
.
Printf
(
" x: %v
\n
"
,
δ
.
δnchildNonLeafs
)
defer
fmt
.
Printf
(
"
\n
->B: %s
\n
"
,
S
)
}
S
.
verify
()
δ
.
Del
.
verify
()
δ
.
Add
.
verify
()
defer
S
.
verify
()
S
.
xfixup
(
-
1
,
δ
.
δnchildNonLeafs
)
S
.
xDifferenceInplace
(
δ
.
Del
)
S
.
xUnionInplace
(
δ
.
Add
)
S
.
xfixup
(
+
1
,
δ
.
δnchildNonLeafs
)
}
// Path returns path leading to node specified by oid.
// Path returns path leading to node specified by oid.
//
//
...
@@ -461,4 +379,91 @@ func (t nodeInTree) String() string {
...
@@ -461,4 +379,91 @@ func (t nodeInTree) String() string {
return
fmt
.
Sprintf
(
"{p%s c%d}"
,
t
.
parent
,
t
.
nchild
)
return
fmt
.
Sprintf
(
"{p%s c%d}"
,
t
.
parent
,
t
.
nchild
)
}
}
const
debugPPSet
=
false
// ---- diff/patch ----
// ΔPPTreeSubSet represents a change to PPTreeSubSet.
//
// It can be applied via PPTreeSubSet.ApplyΔ .
//
// The result B of applying δ to A is:
//
// B = A.xDifference(δ.Del).xUnion(δ.Add) (*)
//
// (*) NOTE δ.Del and δ.Add might have their leafs starting from non-leaf nodes in A/B.
// This situation arises when δ represents a change in path to particular
// node, but that node itself does not change, for example:
//
// c* c
// / \ /
// 41* 42 41
// | | | \
// 22 43 46 43
// | | |
// 44 22 44
//
// Here nodes {c, 41} are changed, node 42 is unlinked, and node 46 is added.
// Nodes 43 and 44 stay unchanged.
//
// δ.Del = c-42-43 | c-41-22
// δ.Add = c-41-43 | c-41-46-22
//
// The second component with "-22" builds from leaf, but the first
// component with "-43" builds from non-leaf node.
//
// δnchildNonLeafs = {43: +1}
//
// Only complete result of applying all
//
// - xfixup(-1, δnchildNonLeafs)
// - δ.Del,
// - δ.Add, and
// - xfixup(+1, δnchildNonLeafs)
//
// produce correctly PP-connected set.
type
ΔPPTreeSubSet
struct
{
Del
PPTreeSubSet
Add
PPTreeSubSet
δnchildNonLeafs
map
[
zodb
.
Oid
]
int
}
// Update updates δ to be combination of δ+δ2.
func
(
δ
*
ΔPPTreeSubSet
)
Update
(
δ2
*
ΔPPTreeSubSet
)
{
δ
.
Del
.
UnionInplace
(
δ2
.
Del
)
δ
.
Add
.
UnionInplace
(
δ2
.
Add
)
for
oid
,
δnc
:=
range
δ2
.
δnchildNonLeafs
{
δ
.
δnchildNonLeafs
[
oid
]
+=
δnc
}
}
// Reverse changes δ=diff(A->B) to δ'=diff(A<-B).
func
(
δ
*
ΔPPTreeSubSet
)
Reverse
()
{
δ
.
Del
,
δ
.
Add
=
δ
.
Add
,
δ
.
Del
// δnchildNonLeafs stays the same
}
// ApplyΔ applies δ to S.
//
// See ΔPPTreeSubSet documentation for details.
func
(
S
PPTreeSubSet
)
ApplyΔ
(
δ
*
ΔPPTreeSubSet
)
{
if
debugPPSet
{
fmt
.
Printf
(
"
\n\n
ApplyΔ
\n
"
)
fmt
.
Printf
(
" A: %s
\n
"
,
S
)
fmt
.
Printf
(
" -: %s
\n
"
,
δ
.
Del
)
fmt
.
Printf
(
" +: %s
\n
"
,
δ
.
Add
)
fmt
.
Printf
(
" x: %v
\n
"
,
δ
.
δnchildNonLeafs
)
defer
fmt
.
Printf
(
"
\n
->B: %s
\n
"
,
S
)
}
S
.
verify
()
δ
.
Del
.
verify
()
δ
.
Add
.
verify
()
defer
S
.
verify
()
S
.
xfixup
(
-
1
,
δ
.
δnchildNonLeafs
)
S
.
xDifferenceInplace
(
δ
.
Del
)
S
.
xUnionInplace
(
δ
.
Add
)
S
.
xfixup
(
+
1
,
δ
.
δnchildNonLeafs
)
}
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