Commit 7750ff3f authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 986ff81d
......@@ -34,6 +34,7 @@ from __future__ import print_function, absolute_import
from BTrees import check as bcheck
from golang import panic
import re
inf = float('inf')
# Tree represents a tree node.
......@@ -41,8 +42,8 @@ class Tree:
# .keyv () of keys
# .children () of children len(.children) == len(.keyv) + 1
def __init__(t, keyv, *children):
assert len(children) == len(keyv) + 1, (keyv, children) # XXX empty tree
# XXX assert keyv ↑
assert len(children) == len(keyv) + 1, (keyv, children)
_assertIncv(keyv)
# XXX assert children keys consistent?
# XXX assert all children are of the same type
t.keyv = tuple(keyv)
......@@ -69,7 +70,7 @@ class Tree:
class Bucket:
# .keyv () of keys
def __init__(b, *keyv): # XXX *keyv -> keyv ?
# XXX assert keyv ↑
_assertIncv(keyv)
b.keyv = tuple(keyv)
def __eq__(a, b):
......@@ -136,3 +137,11 @@ def _indent(prefix, text): # -> text
textv = [prefix+_ for _ in textv]
text = '\n'.join(textv)
return text
# _assertIncv asserts that values of vector v are strictly ↑
def _assertIncv(v):
prev = -inf
for i in range(len(v)):
if not (v[i] > prev):
panic("assert incv: [%d] not ↑: %s -> %s" % (i, v[i], prev))
prev = v[i]
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