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