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
14ea63ba
Commit
14ea63ba
authored
May 11, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
b4b07b83
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
2 deletions
+47
-2
wcfs/internal/xbtree.py
wcfs/internal/xbtree.py
+47
-2
No files found.
wcfs/internal/xbtree.py
View file @
14ea63ba
...
...
@@ -90,6 +90,7 @@ class Tree(object):
# .keyv () of keys
# .children () of children len(.children) == len(.keyv) + 1
def
__init__
(
t
,
keyv
,
*
children
):
keyv
=
tuple
(
keyv
)
assert
len
(
children
)
==
len
(
keyv
)
+
1
,
(
keyv
,
children
)
_assertIncv
(
keyv
)
if
len
(
children
)
>
0
:
...
...
@@ -103,13 +104,13 @@ class Tree(object):
assert
childtype
in
(
Tree
,
Bucket
),
childtype
# assert children keys are consistent
v
=
[
-
inf
]
+
keyv
+
[
+
inf
]
v
=
(
-
inf
,)
+
keyv
+
(
+
inf
,)
for
i
,
(
klo
,
khi
)
in
enumerate
(
zip
(
v
[:
-
1
],
v
[
1
:])):
# (klo, khi) = [] of (k_i, k_{i+1})
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
))
t
.
keyv
=
tuple
(
keyv
)
t
.
keyv
=
keyv
t
.
children
=
tuple
(
children
)
def
__hash__
(
t
):
...
...
@@ -131,6 +132,10 @@ class Tree(object):
__repr__
=
__str__
def
copy
(
t
):
return
Tree
(
t
.
keyv
,
*
[
_
.
copy
()
for
_
in
t
.
children
])
# Bucket represents a bucket node.
class
Bucket
(
object
):
# .keyv () of keys
...
...
@@ -151,6 +156,9 @@ class Bucket(object):
return
"B("
+
','
.
join
([
'%s'
%
_
for
_
in
b
.
keyv
])
+
")"
__repr__
=
__str__
def
copy
(
b
):
return
Bucket
(
*
b
.
keyv
)
# StructureOf returns internal structure of a BTree.
#
...
...
@@ -214,6 +222,12 @@ def Restructure(ztree, newStructure):
# D(A,B) = ────────────── + ──────────────
# N(A) N(B)
#
tnew
=
newStructure
.
copy
()
zlevelv
=
_zwalkBFS
(
ztree
)
levelv
=
_walkBFS
(
tnew
)
_bcheck
(
ztree
)
# verify ztree after our tweaks
tstruct
=
StructureOf
(
ztree
)
...
...
@@ -360,6 +374,37 @@ def _walkBFS(tree): # i[] of [](of nodes on each level)
if
isinstance
(
node
,
Tree
):
nextq
+=
node
.
children
# _zwalkBFS, similarly to _walkBFS, walks ZODB BTree in breadth-first order layer by layer.
def
_zwalkBFS
(
ztree
):
# i[] of [](of nodes on each level)
# assert istree(ztree)
currentq
=
[]
nextq
=
[
ztree
]
while
len
(
nextq
)
>
0
:
yield
tuple
(
nextq
)
currentq
=
nextq
nextq
=
[]
while
len
(
currentq
)
>
0
:
znode
=
currentq
.
pop
(
0
)
assert
istree
(
znode
)
or
isbucket
(
znode
)
if
istree
(
znode
):
kind
,
keys
,
kids
=
zbcheck
.
crack_btree
(
znode
)
if
kind
==
zbcheck
.
BTREE_EMPTY
:
b
=
znode
.
_bucket_type
()
children
=
[
b
]
elif
kind
==
zbcheck
.
BTREE_ONE
:
b
=
znode
.
_bucket_type
()
b
.
__setstate__
(
keys
)
children
=
[
b
]
elif
kind
==
zbcheck
.
BTREE_NORMAL
:
children
=
kids
else
:
panic
(
"bad tree kind %r"
%
kind
)
nextq
+=
children
# TopoDecode decodes topology-encoded text into Tree structure.
...
...
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