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
5c9f7ec4
Commit
5c9f7ec4
authored
Apr 30, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
7dc2e157
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
107 additions
and
0 deletions
+107
-0
wcfs/internal/xbtree.py
wcfs/internal/xbtree.py
+56
-0
wcfs/internal/xbtree_test.py
wcfs/internal/xbtree_test.py
+51
-0
No files found.
wcfs/internal/xbtree.py
0 → 100644
View file @
5c9f7ec4
# -*- 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
wcfs/internal/xbtree_test.py
0 → 100644
View file @
5c9f7ec4
# -*- 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)),
"""
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