简体   繁体   中英

Google Closure Tools PriorityQueue wrong order

I've created a unique priority queue with an enqueue method like this:

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);
};

When I output the values they come out in a random order:

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

Why isn't the queue returning the values in the expected order (smallest to largest).

Thanks!

It turns out that in part of my code I was passing in a list instead of the length of the list and that screwed everything up. I fixed this error and the priority queue works as expected!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM