look-alike
Version:
A simple-yet-powerful KD-tree library for NodeJS, with support for lightning-fast k-Nearest Neighbour queries. Supports normalization, weights, key and filter parameters
67 lines (53 loc) • 1.42 kB
JavaScript
// Generated by CoffeeScript 1.6.3
(function() {
var BPQ, Heap;
Heap = require('heap');
BPQ = (function() {
var _cmp;
_cmp = function(a, b) {
return a.priority - b.priority;
};
function BPQ(size) {
this.size = size;
this.queue = new Heap(_cmp);
}
BPQ.prototype.insert = function(array, priority) {
var obj, _i, _len, _results;
if (!array.length) {
array = [array];
}
_results = [];
for (_i = 0, _len = array.length; _i < _len; _i++) {
obj = array[_i];
_results.push(this.queue.push({
obj: obj,
priority: priority
}));
}
return _results;
};
BPQ.prototype.getObjects = function() {
var tmp, x, _i, _len, _results;
tmp = Heap.nsmallest(this.queue.toArray(), this.size, _cmp);
_results = [];
for (_i = 0, _len = tmp.length; _i < _len; _i++) {
x = tmp[_i];
_results.push(x.obj);
}
return _results;
};
BPQ.prototype.getMaxPriority = function() {
var tmp;
tmp = Heap.nsmallest(this.queue.toArray(), this.size, _cmp);
return tmp.pop().priority;
};
BPQ.prototype.getMinPriority = function() {
return this.queue.top().priority;
};
BPQ.prototype.getSize = function() {
return this.queue.size();
};
return BPQ;
})();
module.exports = BPQ;
}).call(this);