2008年10月28日星期二

Priority queue in python

I found a plain list with a 2-cut insert like this
lo = 0
hi = len(a)
while lo < hi:
mid = (lo+hi)/2
if prioityOfx > prioityOfa[mid]: hi = mid
else: lo = mid+1
a.insert(lo, x)
is fastest as i know.
much faster than using heapq. so become the first one. its bottleneck seems to be this insert operation.

没有评论:

博客归档

neoedmund's shared items

我的简介

ZIP Code File