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
a959e43a
Commit
a959e43a
authored
Apr 30, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
3e3625a7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
17 deletions
+54
-17
wcfs/internal/xbtree.py
wcfs/internal/xbtree.py
+54
-17
No files found.
wcfs/internal/xbtree.py
View file @
a959e43a
...
...
@@ -26,41 +26,78 @@ It is primarily used to verify ΔBTail in wcfs.
XXX Typology:
"""
from
__future__
import
print_function
,
absolute_import
from
BTrees
import
check
as
bcheck
from
golang
import
panic
import
re
# Tree represents a tree node.
class
Tree
:
# .keyv () of keys
# .children () of children len(.children) == len(.keyv) + 1
def
__init__
(
t
ree
,
keyv
,
*
children
):
def
__init__
(
t
,
keyv
,
*
children
):
assert
len
(
children
)
==
len
(
keyv
)
+
1
,
(
keyv
,
children
)
# XXX assert keyv ↑
# XXX assert children keys consistent?
tree
.
keyv
=
tuple
(
keyv
)
tree
.
children
=
tuple
(
children
)
# XXX assert all children are of the same type
t
.
keyv
=
tuple
(
keyv
)
t
.
children
=
tuple
(
children
)
def
__eq__
(
a
,
b
):
if
not
isinstance
(
b
,
Tree
):
return
False
return
(
a
.
keyv
==
b
.
keyv
)
and
(
a
.
children
==
b
.
children
)
# XXX don't compare .children here?
def
__hash__
(
tree
):
return
hash
(
tree
.
keyv
)
^
hash
(
tree
.
children
)
# XXX children ^^^
def
__hash__
(
t
):
return
hash
(
t
.
keyv
)
^
hash
(
t
.
children
)
# XXX children ^^^
# Bucked represents a bucket node.
class
Bucket
:
# .keyv () of keys
def
__init__
(
b
,
keyv
):
# XXX assert keyv ↑
b
.
keyv
=
tuple
(
keyv
)
def
__eq__
(
a
,
b
):
if
not
isinstance
(
b
,
Bucket
):
return
False
return
a
.
keyv
==
b
.
keyv
def
__hash__
(
b
):
return
hash
(
b
.
keyv
)
# StructureOf returns internal structure of a tree.
def
StructureOf
(
node
):
typ
=
type
(
node
)
print
(
typ
.
__name__
)
print
(
typ
.
__bases__
)
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
)
return
Bucket
(
keys
)
if
is_tree
:
kind
,
keys
,
children
=
bcheck
.
crack_btree
(
node
,
is_map
)
if
kind
==
bcheck
.
BTREE_EMPTY
:
return
Tree
([])
if
kind
==
bcheck
.
BTREE_ONE
:
b
=
node
.
_bucket_type
()
b
.
__setstate__
(
keys
)
# it is keys+values for BTREE_ONE case
return
StructureOf
(
b
)
# StructureOf returns internal structure of the tree.
def
StructureOf
(
tree
):
typ
=
type
(
tree
)
assert
"Tree"
in
typ
.
__name__
,
typ
if
kind
==
bcheck
.
BTREE_NORMAL
:
return
Tree
(
keys
,
*
[
StructureOf
(
_
)
for
_
in
children
])
kind
,
keys
,
children
=
bcheck
.
crack_btree
(
tree
,
True
)
if
kind
==
bcheck
.
BTREE_EMPTY
:
return
Tree
([])
if
kind
==
bcheck
.
BTREE_ONE
:
return
Tree
([])
if
kind
==
bcheck
.
BTREE_NORMAL
:
return
Tree
(
keys
,
*
[
StructureOf
(
_
)
for
_
in
children
])
panic
(
"bad tree kind %r"
%
kind
)
panic
(
"
bad kind %r"
%
kind
)
panic
(
"
unknown node type %r"
%
typ
)
...
...
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