本文整理汇总了Python中pybloom.BloomFilter.union方法的典型用法代码示例。如果您正苦于以下问题:Python BloomFilter.union方法的具体用法?Python BloomFilter.union怎么用?Python BloomFilter.union使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pybloom.BloomFilter
的用法示例。
在下文中一共展示了BloomFilter.union方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_union
# 需要导入模块: from pybloom import BloomFilter [as 别名]
# 或者: from pybloom.BloomFilter import union [as 别名]
def test_union(self):
bloom_one = BloomFilter(100, 0.001)
bloom_two = BloomFilter(100, 0.001)
chars = [chr(i) for i in range(97, 123)]
for char in chars[len(chars)/2:]:
bloom_one.add(char)
for char in chars[:len(chars)/2]:
bloom_two.add(char)
new_bloom = bloom_one.union(bloom_two)
for char in chars:
self.assert_(char in new_bloom)
示例2: move
# 需要导入模块: from pybloom import BloomFilter [as 别名]
# 或者: from pybloom.BloomFilter import union [as 别名]
def move(self):
#判断虚手:
if self.x==-1:
if not self.is_pass:
self.is_pass=1
return 0
#判断落子合法性:
if self.board[self.x][self.y].color!=GoPoint.NULL:
print 'You can not move here'
return 1
#确定当前颜色:
if self.nextPlayer:
color=GoPoint.BLACK
else:
color=GoPoint.WHITE
#禁止自填真眼:
cnt1=0
cnt2=0
for i in[[self.x+1,self.y],[self.x-1,self.y],[self.x,self.y+1],[self.x,self.y-1]]:
if self.board[i[0]][i[1]].color==color:
cnt1+=1
elif self.board[i[0]][i[1]].color==GoPoint.WALL:
cnt2+=1
if cnt1+cnt2==4:
for i in [[self.x+1,self.y+1],[self.x-1,self.y-1],[self.x-1,self.y+1],[self.x+1,self.y-1]]:
if self.board[i[0]][i[1]].color==color:
cnt1+=1
elif self.board[i[0]][i[1]].color==GoPoint.WALL:
cnt2+=1
if (not cnt2) and (cnt1>=7):
self.board[self.x][self.y].become_frbidn()
return 1
elif cnt2+cnt1==8:
self.board[self.x][self.y].become_frbidn()
return 1
#备份:
safe_copy=copy.deepcopy(self.board)
#着子:
self.board[self.x][self.y].move(color=color)
#数气:
for i in [[self.x+1,self.y],[self.x-1,self.y],[self.x,self.y+1],[self.x,self.y-1]]:
if self.board[i[0]][i[1]].qi==-1:
self.board[self.x][self.y].qi+=1
#紧气:
for i in [[self.x+1,self.y],[self.x-1,self.y],[self.x,self.y+1],[self.x,self.y-1]]:
if self.board[i[0]][i[1]].qi>0:
self.board[i[0]][i[1]].qi-=1
#连子:
if self.board[i[0]][i[1]].color==color:
self.group_union(g1=[self.x,self.y],g2=i)
#试提子:
else:
#print 'now checking to kill from',i
self.group_check(g=i)
#检查合法性:
#print 'now checking',[self.x,self.y]
if self.group_check(g=[self.x,self.y]):
#print 'ohoh'
self.board=copy.deepcopy(safe_copy)
self.board[self.x][self.y].become_frbidn()
return 1
#print 'allright.'
#print 'qi:',self.board[self.x][self.y].qi
#禁全局同形:
v=self.board_value()
self.copy_value(copy=safe_copy)
if v in self.bf:
self.board=copy.deepcopy(safe_copy)
self.board[self.x][self.y].become_frbidn()
return 1
self.bf.add(v)
self.cnt_c+=1
if self.cnt_c>=self.MAXC:
print 'bf is too little,continue?'
os.system('pause')
self.MAXC*=2
new=BloomFilter(capacity=self.MAXC)
self.bf=new.union(other=self.bf)
#结束:
return 0