add update() function to PriorityQueue
This commit is contained in:
parent
8217b0697a
commit
e60ec9a751
1 changed files with 29 additions and 0 deletions
29
lib/riemann/dash/public/vendor/PriorityQueue.js
vendored
29
lib/riemann/dash/public/vendor/PriorityQueue.js
vendored
|
@ -51,6 +51,35 @@ PriorityQueue.prototype = {
|
|||
this._maitain();
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Update priority of something in the queue. Will silently add it if it
|
||||
* doesn't already exist.
|
||||
*
|
||||
* @param mixed value
|
||||
* @param integer priority
|
||||
* @return void
|
||||
*/
|
||||
update: function(value, priority) {
|
||||
known = false;
|
||||
idx = 0;
|
||||
|
||||
this._queue.forEach(function() {
|
||||
if (JSON.stringify(this._queue[idx].value) === JSON.stringify(value)) {
|
||||
this._queue[idx].priority = priority;
|
||||
known = true;
|
||||
return;
|
||||
}
|
||||
idx++;
|
||||
}, this);
|
||||
|
||||
if (!known) {
|
||||
this._queue.push(new QueueItem(value, priority));
|
||||
}
|
||||
this._queue.sort(this.compare());
|
||||
this._maitain();
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes the most important item and return its value.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue