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
6c65f491
Commit
6c65f491
authored
May 08, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
07e27e54
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
16 deletions
+16
-16
wcfs/internal/xbtree.py
wcfs/internal/xbtree.py
+16
-16
No files found.
wcfs/internal/xbtree.py
View file @
6c65f491
...
...
@@ -77,7 +77,7 @@ in left-to-right order.
from
__future__
import
print_function
,
absolute_import
from
BTrees
import
check
as
bcheck
from
BTrees
import
check
as
z
bcheck
from
golang
import
func
,
panic
from
golang.gcompat
import
qq
import
itertools
...
...
@@ -105,7 +105,6 @@ class Tree(object):
# assert children keys are consistent
v
=
[
-
inf
]
+
keyv
+
[
+
inf
]
for
i
,
(
klo
,
khi
)
in
enumerate
(
zip
(
v
[:
-
1
],
v
[
1
:])):
# (klo, khi) = [] of (k_i, k_{i+1})
child
=
children
[
i
]
for
k
in
children
[
i
].
keyv
:
if
not
(
klo
<=
k
<
khi
):
panic
(
"children[%d] key %d is outside key range [%s, %s)"
%
(
i
,
k
,
klo
,
khi
))
...
...
@@ -156,39 +155,39 @@ class Bucket(object):
# StructureOf returns internal structure of a BTree.
#
# The structure is represented as Tree and Bucket nodes.
def
StructureOf
(
node
):
typ
=
type
(
node
)
def
StructureOf
(
z
node
):
typ
=
type
(
z
node
)
is_tree
=
(
"Tree"
in
typ
.
__name__
)
is_set
=
(
"Set"
in
typ
.
__name__
)
is_bucket
=
((
"Bucket"
in
typ
.
__name__
)
or
re
.
match
(
"..Set"
,
typ
.
__name__
))
is_map
=
(
not
is_set
)
if
is_bucket
:
keys
,
_
=
bcheck
.
crack_bucket
(
node
,
is_map
)
keys
,
_
=
zbcheck
.
crack_bucket
(
z
node
,
is_map
)
return
Bucket
(
*
keys
)
if
is_tree
:
kind
,
keys
,
children
=
bcheck
.
crack_btree
(
node
,
is_map
)
if
kind
==
bcheck
.
BTREE_EMPTY
:
kind
,
keys
,
children
=
zbcheck
.
crack_btree
(
z
node
,
is_map
)
if
kind
==
z
bcheck
.
BTREE_EMPTY
:
return
Tree
([],
Bucket
())
if
kind
==
bcheck
.
BTREE_ONE
:
b
=
node
.
_bucket_type
()
if
kind
==
z
bcheck
.
BTREE_ONE
:
b
=
z
node
.
_bucket_type
()
b
.
__setstate__
(
keys
)
# it is keys+values for BTREE_ONE case
return
Tree
([],
StructureOf
(
b
))
if
kind
==
bcheck
.
BTREE_NORMAL
:
if
kind
==
z
bcheck
.
BTREE_NORMAL
:
return
Tree
(
keys
,
*
[
StructureOf
(
_
)
for
_
in
children
])
panic
(
"bad tree kind %r"
%
kind
)
panic
(
"unknown node type %r"
%
typ
)
panic
(
"unknown
z
node type %r"
%
typ
)
# Restructure reorganizes ZODB BTree instance (not Tree) according to specified
# structure.
def
Restructure
(
ztree
,
newStructure
):
assert
istree
(
ztree
)
# XXX -> use bcheck.classify
assert
istree
(
ztree
)
# XXX -> use
z
bcheck.classify
assert
isinstance
(
newStructure
,
Tree
)
1
/
0
...
...
@@ -322,7 +321,7 @@ def TopoEncode(tree):
# _walkBFS walks tree in breadth-first order layer by layer.
def
_walkBFS
(
tree
):
# i[] of [](of nodes on each level)
assert
isinstance
(
tree
,
Tree
)
current
v
=
[]
current
q
=
[]
nextq
=
[
tree
]
while
len
(
nextq
)
>
0
:
yield
tuple
(
nextq
)
...
...
@@ -410,9 +409,10 @@ def _assertIncv(v):
prev
=
v
[
i
]
# _bcheck performs checks on ztree provided by ZODB packages.
# the checks are what BTree.check and node._check() provide.
class
_ZChecker
(
_bcheck
.
Checker
):
# _bcheck performs full consistency checks on ztree provided by ZODB.
#
# The checks are what is provided by BTree.check and node._check().
class
_ZChecker
(
zbcheck
.
Checker
):
def
visit_btree
(
self
,
obj
,
*
argv
):
super
(
_ZChecker
,
self
).
visit_btree
(
obj
,
*
argv
)
obj
.
_check
()
# also check internal C-level pointers consistency
...
...
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