本文整理汇总了Python中durus.btree.BTree.items方法的典型用法代码示例。如果您正苦于以下问题:Python BTree.items方法的具体用法?Python BTree.items怎么用?Python BTree.items使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类durus.btree.BTree
的用法示例。
在下文中一共展示了BTree.items方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: items_from
# 需要导入模块: from durus.btree import BTree [as 别名]
# 或者: from durus.btree.BTree import items [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)))
示例2: items_backward_from
# 需要导入模块: from durus.btree import BTree [as 别名]
# 或者: from durus.btree.BTree import items [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)
示例3: test_iter
# 需要导入模块: from durus.btree import BTree [as 别名]
# 或者: from durus.btree.BTree import items [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()))
示例4: iter
# 需要导入模块: from durus.btree import BTree [as 别名]
# 或者: from durus.btree.BTree import items [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())
示例5: items_range
# 需要导入模块: from durus.btree import BTree [as 别名]
# 或者: from durus.btree.BTree import items [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)
示例6: update
# 需要导入模块: from durus.btree import BTree [as 别名]
# 或者: from durus.btree.BTree import items [as 别名]
def update(self):
bt = BTree()
bt.update()
assert not list(bt.items())
bt.update(a=1)
assert list(bt.items()) == [('a', 1)]
bt = BTree()
bt.update(dict(b=2), a=1)
assert len(list(bt.items())) == 2
assert bt['b'] == 2
assert bt['a'] == 1
bt = BTree()
bt.update([('b', 2)], a=1)
assert len(list(bt.items())) == 2
assert bt['b'] == 2
assert bt['a'] == 1
class Fake(object):
def items(self):
return [('1',2)]
bt.update(Fake())
raises(TypeError, bt.update, 1, 2)
示例7: test_slow
# 需要导入模块: from durus.btree import BTree [as 别名]
# 或者: from durus.btree.BTree import items [as 别名]
def test_slow(self):
if '--slow' not in sys.argv:
skip('test not run because it is slow')
if SAME_RANDOM:
seed(42)
for bnode_class in BNode.__subclasses__():
if bnode_class.minimum_degree not in (4, 16):
continue
sys.stdout.write('\nbnode_class=%s' % bnode_class)
bt = BTree(bnode_class)
d = {}
number = 0
limit = 10000
for k in range(limit*10):
number = randint(0, limit)
if DEBUG:
bt_bak = deepcopy(bt)
d_bak = deepcopy(d)
if number in bt:
assert number in d
if randint(0, 1) == 1:
del bt[number]
del d[number]
op = 'del'
#sys.stdout.write('\ndel bt[%s]' % number)
else:
bt[number] = 1
d[number] = 1
op = 'ins'
if DEBUG or k % limit == 0:
d_items = sorted(d.items())
assert d_items == list(bt.items())
if DEBUG and not len(d_items) == len(bt):
# set a breakpoint here for interactive debugging
if op == 'ins':
bt_bak[number] = 1
else:
del bt_bak[number]
assert len(d_items) == len(bt)
示例8: slow
# 需要导入模块: from durus.btree import BTree [as 别名]
# 或者: from durus.btree.BTree import items [as 别名]
def slow(self):
for bnode_class in BNode.__subclasses__():
if bnode_class.minimum_degree not in (4, 16):
continue
sys.stdout.write('\nbnode_class=%s' % bnode_class)
bt = BTree(bnode_class)
d = {}
number = 0
limit = 10000
for k in range(limit*10):
number = randint(0, limit)
if number in bt:
assert number in d
if randint(0, 1) == 1:
del bt[number]
del d[number]
sys.stdout.write('\ndel bt[%s]' % number)
else:
bt[number] = 1
d[number] = 1
if k % limit == 0:
d_items = sorted(d.items())
assert d_items == list(bt.items())
assert len(d_items) == len(bt)
示例9: items_backward
# 需要导入模块: from durus.btree import BTree [as 别名]
# 或者: from durus.btree.BTree import items [as 别名]
def items_backward(self):
bt = BTree()
for j in range(100):
bt.add(j)
assert list(reversed(bt.items())) == list(bt.items_backward())