Ejemplo n.º 1
0
 def __new__(cls, key=None, root_data=None, comp=None,
             is_order_statistic=False, max_children=2):
     obj = object.__new__(cls)
     if key is None and root_data is not None:
         raise ValueError('Key required.')
     key = None if root_data is None else key
     root = MAryTreeNode(key, root_data)
     root.is_root = True
     obj.root_idx = 0
     obj.max_children = max_children
     obj.tree, obj.size = ArrayForTrees(MAryTreeNode, [root]), 1
     obj.comparator = lambda key1, key2: key1 < key2 \
                     if comp is None else comp
     obj.is_order_statistic = is_order_statistic
     return obj
Ejemplo n.º 2
0
def test_MAryTreeNode():
    m = MAryTreeNode(1, 1)
    m.add_children(*list(range(2, 10)))
    assert str(m) == "(1, 1)"
    assert str(m.children) == "['2', '3', '4', '5', '6', '7', '8', '9']"