谷歌关闭工具优先级队列错误的顺序



我使用如下所示的排队方法创建了一个唯一的优先级队列:

huzz.ak.UniquePriorityQueue.prototype.enqueue =
    function(priority, value) {
  var node = {'valid': true, 'value': value, 'priority': priority};
  var key = value.key;
  if (this.pointers_[key] !== undefined) {
    this.pointers_[key].valid = false;
  }
  this.pointers_[key] = node;
  this.priorityQueue_.enqueue(priority, node);
};

当我输出值时,它们以随机顺序出现:

while (true) {
  p = this.priorityQueue_.dequeue();
  this.logger_.log(p.priority + ' ' + p.value.toString() + ' ' + p.valid);
}
1265 ... true
1413 S..N. false
1265 ... false
92 S..N. true
1734 .........E false
59 ... false
75 ...B false
92 S..N. false

为什么队列没有按预期顺序(从小到大)返回值。

谢谢!

事实证明,在我的部分代码中,我传递了一个列表而不是列表的长度,这搞砸了一切。我修复了此错误,优先级队列按预期工作!

最新更新