本文整理汇总了Python中BTrees.OIBTree.OIBTree.maxKey方法的典型用法代码示例。如果您正苦于以下问题:Python OIBTree.maxKey方法的具体用法?Python OIBTree.maxKey怎么用?Python OIBTree.maxKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BTrees.OIBTree.OIBTree
的用法示例。
在下文中一共展示了OIBTree.maxKey方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: IPTree
# 需要导入模块: from BTrees.OIBTree import OIBTree [as 别名]
# 或者: from BTrees.OIBTree.OIBTree import maxKey [as 别名]
class IPTree(object):
"""Data structure for storing sets of IP addresses"""
def __init__(self, l=None):
self._tree = OIBTree()
self._tree[[-1,255,255,255]] = 0
self._tree[[256,0,0,1]] = 0
def add(self, s):
ip4 = IP4(s)
t = self._tree
#print "adding %r" % ip4
inbetween = list(t.items(min=ip4.begin, max=ip4.end,
excludemin=True,
excludemax=True))
ma = t.minKey(ip4.end) # returns smallest key >= ip4.end
mi = t.maxKey(ip4.begin) # returns largest key <= ip4.begin
if ma == ip4.end:
if t[ma] == 1:
del t[ma]
else:
if not ip4.end in self:
t[ip4.end] = 0
if mi == ip4.begin:
if t[mi] == 0:
del t[mi]
else:
if not ip4.begin in self:
t[ip4.begin] = 1
for node, val in inbetween:
del self._tree[node]
def remove(self, s):
ip4 = IP4(s)
t = self._tree
#print "removing %r" % ip4
inbetween = list(t.items(min=ip4.begin, max=ip4.end,
excludemin=True,
excludemax=True))
ma = t.minKey(ip4.end) # returns smallest key >= ip4.end
mi = t.maxKey(ip4.begin) # returns largest key <= ip4.begin
if ma == ip4.end:
if t[ma] == 0:
del t[ma]
else:
if ip4.end in self:
t[ip4.end] = 1
if mi == ip4.begin:
if t[mi] == 1:
del t[mi]
else:
if ip4.begin in self:
t[ip4.begin] = 0
for node, val in inbetween:
del self._tree[node]
def as_iter(self):
i = iter(self._tree)
i.next() # discard first item
while True:
p0 = i.next()
p1 = i.next()
yield (p0, p1)
def __contains__(self, a):
if isinstance(a, list):
k = self._tree.maxKey(a)
return self._tree[k]
raise RuntimeError("Should not happen!")
def __repr__(self):
return repr(list(self.as_iter()))