Commit a959e43a authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 3e3625a7
......@@ -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__(tree, 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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment