本文整理汇总了Python中PriorityQueue.PriorityQueue.extractMin方法的典型用法代码示例。如果您正苦于以下问题:Python PriorityQueue.extractMin方法的具体用法?Python PriorityQueue.extractMin怎么用?Python PriorityQueue.extractMin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PriorityQueue.PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue.extractMin方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test1
# 需要导入模块: from PriorityQueue import PriorityQueue [as 别名]
# 或者: from PriorityQueue.PriorityQueue import extractMin [as 别名]
def test1():
from PriorityQueue import PriorityQueue
import random
print("test1")
ITERATIONS = 10000
que = PriorityQueue()
heap = BinomialHeap()
length = 0
for i in range(ITERATIONS):
if i % 300 == 0:
print("Progress: {:.0%}".format(float(i) / ITERATIONS))
op = random.randint(0, 99)
if op < 1: # Clear
heap.check_structure()
for j in range(length):
if heap.dequeue() != que.extractMin():
raise AssertionError()
if not que.empty():
raise AssertionError()
length = 0
elif op < 2: # Peek
heap.check_structure()
if length > 0:
val = que.extractMin()
if heap.peek() != val:
raise AssertionError()
que.insert(val)
elif op < 60: # Add
n = random.randint(1, 100)
for j in range(n):
val = random.randint(0, 9999)
que.insert(val)
heap.enqueue(val)
length += n
elif op < 70: # Merge
n = random.randint(1, 100)
temp = BinomialHeap()
for j in range(n):
val = random.randint(0, 9999)
que.insert(val)
temp.enqueue(val)
heap.merge(temp)
if len(temp) != 0:
raise AssertionError()
length += n
elif op < 100: # Remove
n = min(random.randint(1, 100), length)
for j in range(n):
if heap.dequeue() != que.extractMin():
raise AssertionError()
length -= n
else:
raise AssertionError()
if len(heap) != length:
raise AssertionError()
print("Test passed")