本文整理汇总了Python中priorityQueue.PriorityQueue.isempty方法的典型用法代码示例。如果您正苦于以下问题:Python PriorityQueue.isempty方法的具体用法?Python PriorityQueue.isempty怎么用?Python PriorityQueue.isempty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类priorityQueue.PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue.isempty方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from priorityQueue import PriorityQueue [as 别名]
# 或者: from priorityQueue.PriorityQueue import isempty [as 别名]
class PubVenPriorityQueue:
def __init__(self,newsSeedList,socialSeedList,govSeedList):
self.turn = 0
'''
if newsSeedList is not None:
self.newsQueue = PriorityQueue(newsSeedList)
if socialSeedList is not None:
self.socialQueue = PriorityQueue(socialSeedList)
if govSeedList is not None:
self.govQueue = PriorityQueue(govSeedList)
'''
self.newsQueue = PriorityQueue(newsSeedList)
self.socialQueue = PriorityQueue(socialSeedList)
self.govQueue = PriorityQueue(govSeedList)
heapq.heapify(self.newsQueue.queue)
heapq.heapify(self.socialQueue.queue)
heapq.heapify(self.govQueue.queue)
def pop(self):
if self.turn == 0:
if self.newsQueue.isempty():
self.turn = 1
return self.pop()
else:
return heapq.heappop(self.newsQueue.queue)
elif self.turn == 1:
if self.socialQueue.isempty():
self.turn = 2
return self.pop()
else:
return heapq.heappop(self.socialQueue.queue)
else:
if self.govQueue.isempty():
self.turn = 0
return self.pop()
else:
return heapq.heappop(self.govQueue.queue)
def push(self,element):
if self.turn == 0:
return heapq.heappush(self.newsQueue.queue,element)
elif self.turn == 1:
return heapq.heappush(self.socialQueue.queue,element)
else:
return heapq.heappush(self.govQueue.queue,element)
def next(self):
self.turn = (self.turn + 1 ) % 3
def isempty(self):
if self.govQueue.isempty() and self.newsQueue.isempty() and self.socialQueue.isempty():
return True
return False
def exists(self,url):
urlList = [v for p,v,k in self.newsQueue.queue]
if url in urlList:
return True
else:
urlList = [v for p,v,k in self.socialQueue.queue]
if url in urlList:
return True
else:
urlList = [v for p,v,k in self.govQueue.queue]
return url in urlList
'''
def exists(self,url):
if self.turn == 0:
urlList = [v for p,v,k in self.newsQueue.queue]
return url in urlList
elif self.turn == 1:
urlList = [v for p,v,k in self.socialQueue.queue]
return url in urlList
else:
urlList = [v for p,v,k in self.govQueue.queue]
return url in urlList
'''