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

.

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