Commit 5c9f7ec4 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 7dc2e157
# -*- coding: utf-8 -*-
# Copyright (C) 2020 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
# it under the terms of the GNU General Public License version 3, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# You can also Link and Combine this program with other software covered by
# the terms of any of the Free Software licenses or any of the Open Source
# Initiative approved licenses and Convey the resulting work. Corresponding
# source of such a combination shall include the source code for all other
# software used.
#
# This program is distributed WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
"""Package xbtree provides utilities for inspecting/manipulating internal structure of BTrees.
It is primarily used to verify ΔBTail in wcfs.
XXX Typology:
"""
# Tree represents internal tree node.
class Tree:
# .keyv () of keys
# .children () of children len(.children) == len(.keyv) + 1
def __init__(tree, keyv, *children):
assert len(children) == len(keyv) + 1
tree.keyv = tuple(keyv)
tree.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 ^^^
# StructureOf returns internal structure of the tree.
def StructureOf(tree):
1/0
# TypologyOf returns topology encoding for internal structure of the tree.
#
# See top-level docstring for what topology is.
def TypologyOf(tree):
1/0
treeStruct = StructureOf(tree)
# XXX convert struct -> topology
# -*- coding: utf-8 -*-
# Copyright (C) 2020 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
# it under the terms of the GNU General Public License version 3, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# You can also Link and Combine this program with other software covered by
# the terms of any of the Free Software licenses or any of the Open Source
# Initiative approved licenses and Convey the resulting work. Corresponding
# source of such a combination shall include the source code for all other
# software used.
#
# This program is distributed WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
from wendelin.wcfs.internal import xbtree
from BTrees.tests import testBTrees
def test_topologyOf():
T = xbtree.Tree
# XXX empty
# XXX 1 k->v
# XXX known degenerate topology
# https://github.com/zopefoundation/ZODB/commit/6cd24e99f89b
# https://github.com/zopefoundation/BTrees/blob/4.7.2-1-g078ba60/BTrees/tests/testBTrees.py#L20
t, keys = testBTrees.DegenerateBTree("testBasicOps")._build_degenerate_tree()
assert keys == [1, 3, 5, 7, 11]
assert xbtree.StructureOf(t) == T([4],
T([2],
T([]), T([])),
T([],
T([6, 10],
T([], T([])),
T([]),
T([])) ))
"""
assert xbtree.TopologyOf(t) == ( (4,),
((2,), ()),
(((), ()), (6, 10)),
"""
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