本文整理匯總了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())