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
cb93b11f
Commit
cb93b11f
authored
May 25, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
bef6285c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
12 deletions
+19
-12
wcfs/internal/xbtree.py
wcfs/internal/xbtree.py
+19
-12
No files found.
wcfs/internal/xbtree.py
View file @
cb93b11f
...
...
@@ -148,8 +148,9 @@ class Tree(object):
# copy returns a deep copy of the tree.
def
copy
(
t
):
return
Tree
(
t
.
keyv
,
*
[
_
.
copy
()
for
_
in
t
.
children
])
# if onlyKeys=Y buckets in returned tree will contain only keys not values.
def
copy
(
t
,
onlyKeys
=
False
):
return
Tree
(
t
.
keyv
,
*
[
_
.
copy
(
onlyKeys
)
for
_
in
t
.
children
])
# firstbucket returns Bucket reachable through leftmost child links.
def
firstbucket
(
t
):
...
...
@@ -194,19 +195,23 @@ class Bucket(object):
return
"B"
+
','
.
join
(
kvv
)
__repr__
=
__str__
def
copy
(
b
):
return
Bucket
(
b
.
keyv
,
b
.
valuev
)
def
copy
(
b
,
onlyKeys
=
False
):
if
onlyKeys
:
return
Bucket
(
b
.
keyv
,
None
)
else
:
return
Bucket
(
b
.
keyv
,
b
.
valuev
)
# StructureOf returns internal structure of a ZODB BTree.
#
# The structure is represented as Tree and Bucket nodes.
def
StructureOf
(
znode
):
# If onlyKeys=Y values of the tree are not represented in returned structure.
def
StructureOf
(
znode
,
onlyKeys
=
False
):
ztype
=
_zclassify
(
znode
)
if
ztype
.
is_zbucket
:
keys
,
values
=
zbcheck
.
crack_bucket
(
znode
,
ztype
.
is_map
)
if
not
ztype
.
is_map
:
if
(
not
ztype
.
is_map
)
or
onlyKeys
:
return
Bucket
(
keys
,
None
)
else
:
return
Bucket
(
keys
,
values
)
...
...
@@ -214,15 +219,15 @@ def StructureOf(znode):
if
ztype
.
is_ztree
:
kind
,
keys
,
children
=
zbcheck
.
crack_btree
(
znode
,
ztype
.
is_map
)
if
kind
==
zbcheck
.
BTREE_EMPTY
:
return
Tree
([],
Bucket
([],
[]
if
ztype
.
is_map
else
None
))
return
Tree
([],
Bucket
([],
[]
if
(
ztype
.
is_map
or
not
onlyKeys
)
else
None
))
if
kind
==
zbcheck
.
BTREE_ONE
:
b
=
znode
.
_bucket_type
()
b
.
__setstate__
(
keys
)
# it is keys+values for BTREE_ONE case
return
Tree
([],
StructureOf
(
b
))
return
Tree
([],
StructureOf
(
b
,
onlyKeys
))
if
kind
==
zbcheck
.
BTREE_NORMAL
:
return
Tree
(
keys
,
*
[
StructureOf
(
_
)
for
_
in
children
])
return
Tree
(
keys
,
*
[
StructureOf
(
_
,
onlyKeys
)
for
_
in
children
])
panic
(
"bad tree kind %r"
%
kind
)
...
...
@@ -232,6 +237,8 @@ def StructureOf(znode):
# Restructure reorganizes ZODB BTree instance (not Tree) according to specified
# topology structure.
#
# The new structure should be given with buckets without values. XXX should -> can?
#
# NOTE ZODB BTree package does not tolerate structures with empty BTree nodes
# except for the sole single case of empty tree.
@
func
...
...
@@ -285,9 +292,9 @@ def Restructure(ztree, newStructure):
# we will modify nodes from new set:
# - node.Z will point to associated znode
# - bucket.next_bucket will point to bucket that is coming with next keys in the tree
tnew
=
newStructure
.
copy
()
tnew
=
newStructure
.
copy
()
# XXX onlyKeys=True ?
# assign assign
e
s tree nodes from RNv to ztree nodes from RZv in optimal way.
# assign assigns tree nodes from RNv to ztree nodes from RZv in optimal way.
# Bj ∈ RNv is mapped into Ai ∈ RZv such that that sum_j D(A_i, Bj) is minimal.
# it is used to associate nodes in tnew to ztree nodes.
def
assign
(
RZv
,
RNv
):
...
...
@@ -493,7 +500,7 @@ def Restructure(ztree, newStructure):
assert
len
(
kv
)
==
0
# all keys must have been popped
_zbcheck
(
ztree
)
# verify ztree after our tweaks
tstruct
=
StructureOf
(
ztree
)
tstruct
=
StructureOf
(
ztree
,
onlyKeys
=
True
)
if
tstruct
!=
newStructure
:
panic
(
"BUG: Restructure: result structure is not what was"
" requested:
\
n
%s
\
n
\
n
want:
\
n
%s"
%
(
tstruct
,
newStructure
))
...
...
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