本文整理汇总了Python中durus.btree.BTree.add方法的典型用法代码示例。如果您正苦于以下问题:Python BTree.add方法的具体用法?Python BTree.add怎么用?Python BTree.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类durus.btree.BTree
的用法示例。
在下文中一共展示了BTree.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from durus.btree import BTree [as 别名]
# 或者: from durus.btree.BTree import add [as 别名]
def get(self):
bt = BTree()
for j in range(10):
bt.add(j)
assert bt.get(2) == True
assert bt.get(-1) == None
assert bt.get(-1, 5) == 5
示例2: test_delete_case_2c
# 需要导入模块: from durus.btree import BTree [as 别名]
# 或者: from durus.btree.BTree import add [as 别名]
def test_delete_case_2c(self):
bt = BTree(BNode)
for j in 'abcdefghi':
bt.add(j)
assert bt.root.items == [('d', True)]
del bt['d']
assert len(bt) == bt.root.get_count()
示例3: clear
# 需要导入模块: from durus.btree import BTree [as 别名]
# 或者: from durus.btree.BTree import add [as 别名]
def clear(self):
bt = BTree()
for j in range(10):
bt.add(j)
assert bt.has_key(2)
bt.clear()
assert not bt.has_key(2)
assert bt.keys() == []
示例4: find_extremes
# 需要导入模块: from durus.btree import BTree [as 别名]
# 或者: from durus.btree.BTree import add [as 别名]
def find_extremes(self):
bt = BTree()
raises(AssertionError, bt.get_min_item)
raises(AssertionError, bt.get_max_item)
for j in range(100):
bt.add(j)
assert bt.get_min_item() == (0, True)
assert bt.get_max_item() == (99, True)
示例5: iter
# 需要导入模块: from durus.btree import BTree [as 别名]
# 或者: from durus.btree.BTree import add [as 别名]
def iter(self):
bt = BTree()
for j in range(100):
bt.add(j)
assert list(bt) == list(bt.iterkeys())
assert list(bt.iteritems()) == list(zip(bt, bt.itervalues()))
assert list(bt.iterkeys()) == list(bt.keys())
assert list(bt.itervalues()) == list(bt.values())
assert list(bt.iteritems()) == list(bt.items())
示例6: items_from
# 需要导入模块: from durus.btree import BTree [as 别名]
# 或者: from durus.btree.BTree import add [as 别名]
def items_from(self):
bt = BTree()
for j in range(100):
bt.add(j)
for cutoff in (-1, 1, 50.1, 100, 102):
assert (list([(x, y) for (x, y) in bt.items() if x >= cutoff]) ==
list(bt.items_from(cutoff)))
assert (list([(x, y) for (x, y) in bt.items() if x > cutoff]) ==
list(bt.items_from(cutoff, closed=False)))
示例7: search
# 需要导入模块: from durus.btree import BTree [as 别名]
# 或者: from durus.btree.BTree import add [as 别名]
def search(self):
bt = BTree(BNode)
for j in range(100):
bt.add(j)
assert bt[1] == True
try:
assert bt[-1]
except KeyError:
pass
示例8: _delete_case_3
# 需要导入模块: from durus.btree import BTree [as 别名]
# 或者: from durus.btree.BTree import add [as 别名]
def _delete_case_3(self):
bt = BTree(BNode)
for j in range(100):
bt.add(j)
assert bt.root.items == [(31, True), (63, True)]
assert [n.items for n in bt.root.nodes] == [
[(15, True)], [(47, True)], [(79, True)]]
assert [[n.items for n in node.nodes]
for node in bt.root.nodes] == [
[[(7, True)], [(23, True)]],
[[(39, True)], [(55, True)]],
[[(71, True)], [(87, True)]]]
return bt
示例9: test_iter
# 需要导入模块: from durus.btree import BTree [as 别名]
# 或者: from durus.btree.BTree import add [as 别名]
def test_iter(self):
bt = BTree()
for j in range(100):
bt.add(j)
if hasattr(bt, 'iterkeys'):
assert list(bt) == list(bt.iterkeys())
assert list(bt.iteritems()) == list(zip(bt, bt.itervalues()))
assert list(bt.iterkeys()) == list(bt.keys())
assert list(bt.itervalues()) == list(bt.values())
assert list(bt.iteritems()) == list(bt.items())
else:
assert list(bt) == list(bt.keys())
assert list(bt.items()) == list(zip(bt, bt.values()))
示例10: items_backward_from
# 需要导入模块: from durus.btree import BTree [as 别名]
# 或者: from durus.btree.BTree import add [as 别名]
def items_backward_from(self):
bt = BTree()
for j in range(100):
bt.add(j)
for cutoff in (-1, 1, 50.1, 100, 102):
expect = list(reversed([(x, y) for (x, y) in bt.items()
if x < cutoff]))
got = list(bt.items_backward_from(cutoff))
assert expect == got, (cutoff, expect, got)
expect = list(reversed([(x, y) for (x, y) in bt.items()
if x <= cutoff]))
got = list(bt.items_backward_from(cutoff, closed=True))
assert expect == got, (cutoff, expect, got)
示例11: items_range
# 需要导入模块: from durus.btree import BTree [as 别名]
# 或者: from durus.btree.BTree import add [as 别名]
def items_range(self):
bt = BTree()
for j in range(100):
bt.add(j)
lo = 0
hi = 40
for lo, hi in [(-1,10), (3, 9), (30, 200), (-10, 200)]:
expect = list([(x, y) for (x, y) in bt.items()
if lo <= x < hi])
got = list(bt.items_range(lo, hi))
assert expect == got, (lo, hi, expect, got)
expect = list([(x, y) for (x, y) in bt.items()
if lo < x < hi])
got = list(bt.items_range(lo, hi, closed_start=False))
assert expect == got, (lo, hi, expect, got)
expect = list([(x, y) for (x, y) in bt.items()
if lo < x <= hi])
got = list(bt.items_range(
lo, hi, closed_start=False, closed_end=True))
assert expect == got, (lo, hi, expect, got)
expect = list([(x, y) for (x, y) in bt.items()
if lo <= x <= hi])
got = list(bt.items_range(
lo, hi, closed_start=True, closed_end=True))
assert expect == got, (lo, hi, expect, got)
expect = list(reversed([(x, y) for (x, y) in bt.items()
if lo < x <= hi]))
got = list(bt.items_range(hi, lo))
assert expect == got, (hi, lo, expect, got)
expect = list(reversed([(x, y) for (x, y) in bt.items()
if lo <= x <= hi]))
got = list(bt.items_range(hi, lo, closed_end=True))
assert expect == got, (hi, lo, expect, got)
expect = list(reversed([(x, y) for (x, y) in bt.items()
if lo <= x < hi]))
got = list(bt.items_range(
hi, lo, closed_start=False, closed_end=True))
assert expect == got, (hi, lo, expect, got)
expect = list(reversed([(x, y) for (x, y) in bt.items()
if lo < x < hi]))
got = list(bt.items_range(
hi, lo, closed_start=False, closed_end=False))
assert expect == got, (hi, lo, expect, got)
expect = list(reversed([(x, y) for (x, y) in bt.items()
if lo <= x <= hi]))
got = list(bt.items_range(hi, lo, closed_end=True))
assert expect == got, (hi, lo, expect, got)
示例12: delete_case_2c
# 需要导入模块: from durus.btree import BTree [as 别名]
# 或者: from durus.btree.BTree import add [as 别名]
def delete_case_2c(self):
bt = BTree(BNode)
for j in 'abcdefghi':
bt.add(j)
assert bt.root.items == [('d', True)]
del bt['d']
示例13: delete_case_2a
# 需要导入模块: from durus.btree import BTree [as 别名]
# 或者: from durus.btree.BTree import add [as 别名]
def delete_case_2a(self):
bt = BTree(BNode)
for j in 'jklmoab':
bt.add(j)
del bt['k']
示例14: reversed
# 需要导入模块: from durus.btree import BTree [as 别名]
# 或者: from durus.btree.BTree import add [as 别名]
def reversed(self):
bt = BTree()
for j in range(100):
bt.add(j)
assert list(reversed(bt)) == list(reversed(list(bt)))
示例15: has_key
# 需要导入模块: from durus.btree import BTree [as 别名]
# 或者: from durus.btree.BTree import add [as 别名]
def has_key(self):
bt = BTree()
for j in range(10):
bt.add(j)
assert bt.has_key(2)
assert not bt.has_key(-1)