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FastPriorityQueue.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/fastpriorityqueue@0.8.0/FastPriorityQueue.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/**\n * FastPriorityQueue.js : a fast heap-based priority queue  in JavaScript.\n * (c) the authors\n * Licensed under the Apache License, Version 2.0.\n *\n * Speed-optimized heap-based priority queue for modern browsers and JavaScript engines.\n *\n * Usage :\n         Installation (in shell, if you use node):\n         $ npm install fastpriorityqueue\n\n         Running test program (in JavaScript):\n\n         // var FastPriorityQueue = require(\"fastpriorityqueue\");// in node\n         var x = new FastPriorityQueue();\n         x.add(1);\n         x.add(0);\n         x.add(5);\n         x.add(4);\n         x.add(3);\n         x.peek(); // should return 0, leaves x unchanged\n         x.size; // should return 5, leaves x unchanged\n         while(!x.isEmpty()) {\n           console.log(x.poll());\n         } // will print 0 1 3 4 5\n         x.trim(); // (optional) optimizes memory usage\n */\n'use strict';\n\nvar defaultcomparator = function(a, b) {\n  return a < b;\n};\n\n// the provided comparator function should take a, b and return *true* when a < b\nfunction FastPriorityQueue(comparator) {\n  if (!(this instanceof FastPriorityQueue)) return new FastPriorityQueue(comparator);\n  this.array = [];\n  this.size = 0;\n  this.compare = comparator || defaultcomparator;\n}\n\n// copy the priority queue into another, and return it. Queue items are shallow-copied.\n// Runs in `O(n)` time.\nFastPriorityQueue.prototype.clone = function() {\n  var fpq = new FastPriorityQueue(this.compare);\n  fpq.size = this.size;\n  fpq.array = this.array.slice(0, this.size);\n  return fpq;\n};\n\n// Add an element into the queue\n// runs in O(log n) time\nFastPriorityQueue.prototype.add = function(myval) {\n  var i = this.size;\n  this.array[this.size] = myval;\n  this.size += 1;\n  var p;\n  var ap;\n  while (i > 0) {\n    p = (i - 1) >> 1;\n    ap = this.array[p];\n    if (!this.compare(myval, ap)) {\n      break;\n    }\n    this.array[i] = ap;\n    i = p;\n  }\n  this.array[i] = myval;\n};\n\n// replace the content of the heap by provided array and \"heapify it\"\nFastPriorityQueue.prototype.heapify = function(arr) {\n  this.array = arr;\n  this.size = arr.length;\n  var i;\n  for (i = this.size >> 1; i >= 0; i--) {\n    this._percolateDown(i);\n  }\n};\n\n// for internal use\nFastPriorityQueue.prototype._percolateUp = function(i, force) {\n  var myval = this.array[i];\n  var p;\n  var ap;\n  while (i > 0) {\n    p = (i - 1) >> 1;\n    ap = this.array[p];\n    // force will skip the compare\n    if (!force && !this.compare(myval, ap)) {\n      break;\n    }\n    this.array[i] = ap;\n    i = p;\n  }\n  this.array[i] = myval;\n};\n\n// for internal use\nFastPriorityQueue.prototype._percolateDown = function(i) {\n  var size = this.size;\n  var hsize = this.size >>> 1;\n  var ai = this.array[i];\n  var l;\n  var r;\n  var bestc;\n  while (i < hsize) {\n    l = (i << 1) + 1;\n    r = l + 1;\n    bestc = this.array[l];\n    if (r < size) {\n      if (this.compare(this.array[r], bestc)) {\n        l = r;\n        bestc = this.array[r];\n      }\n    }\n    if (!this.compare(bestc, ai)) {\n      break;\n    }\n    this.array[i] = bestc;\n    i = l;\n  }\n  this.array[i] = ai;\n};\n\n// internal\n// _removeAt(index) will remove the item at the given index from the queue,\n// retaining balance. returns the removed item, or undefined if nothing is removed.\nFastPriorityQueue.prototype._removeAt = function(index) {\n  if (index > this.size - 1 || index < 0) return undefined;\n\n  // impl1:\n  //this.array.splice(index, 1);\n  //this.heapify(this.array);\n  // impl2:\n  this._percolateUp(index, true);\n  return this.poll();\n};\n\n// remove(myval) will remove an item matching the provided value from the\n// queue, checked for equality by using the queue's comparator.\n// return true if removed, false otherwise.\nFastPriorityQueue.prototype.remove = function(myval) {\n  for (var i = 0; i < this.size; i++) {\n    if (!this.compare(this.array[i], myval) && !this.compare(myval, this.array[i])) {\n      // items match, comparator returns false both ways, remove item\n      this._removeAt(i);\n      return true;\n    }\n  }\n  return false;\n};\n\n// removeOne(callback) will execute the callback function for each item of the queue\n// and will remove the first item for which the callback will return true.\n// return the removed item, or undefined if nothing is removed.\nFastPriorityQueue.prototype.removeOne = function(callback) {\n  if (typeof callback !== \"function\") {\n    return undefined;\n  }\n  for (var i = 0; i < this.size; i++) {\n    if (callback(this.array[i])) {\n      return this._removeAt(i);\n    }\n  }\n};\n\n// remove(callback[, limit]) will execute the callback function for each item of\n// the queue and will remove each item for which the callback returns true, up to\n// a max limit of removed items if specified or no limit if unspecified.\n// return an array containing the removed items.\n// The callback function should be a pure function.\nFastPriorityQueue.prototype.removeMany = function(callback, limit) {\n  // Skip unnecessary processing for edge cases\n  if (typeof callback !== \"function\" || this.size < 1) {\n    return [];\n  }\n  limit = limit ? Math.min(limit, this.size) : this.size;\n\n  // Prepare the results container to hold up to the results limit\n  var resultSize = 0;\n  var result = new Array(limit);\n\n  // Prepare a temporary array to hold items we'll traverse through and need to keep\n  var tmpSize = 0;\n  var tmp = new Array(this.size);\n\n  while (resultSize < limit && !this.isEmpty()) {\n    // Dequeue items into either the results or our temporary array\n    var item = this.poll();\n    if (callback(item)) {\n      result[resultSize++] = item;\n    } else {\n      tmp[tmpSize++] = item;\n    }\n  }\n  // Update the result array with the exact number of results\n  result.length = resultSize;\n\n  // Re-add all the items we can keep\n  var i = 0;\n  while (i < tmpSize) {\n    this.add(tmp[i++]);\n  }\n\n  return result;\n};\n\n// Look at the top of the queue (one of the smallest elements) without removing it\n// executes in constant time\n//\n// Calling peek on an empty priority queue returns\n// the \"undefined\" value.\n// https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/undefined\n//\nFastPriorityQueue.prototype.peek = function() {\n  if (this.size == 0) return undefined;\n  return this.array[0];\n};\n\n// remove the element on top of the heap (one of the smallest elements)\n// runs in logarithmic time\n//\n// If the priority queue is empty, the function returns the\n// \"undefined\" value.\n// https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/undefined\n//\n// For long-running and large priority queues, or priority queues\n// storing large objects, you may  want to call the trim function\n// at strategic times to recover allocated memory.\nFastPriorityQueue.prototype.poll = function() {\n  if (this.size == 0) return undefined;\n  var ans = this.array[0];\n  if (this.size > 1) {\n    this.array[0] = this.array[--this.size];\n    this._percolateDown(0);\n  } else {\n    this.size -= 1;\n  }\n  return ans;\n};\n\n// This function adds the provided value to the heap, while removing\n// and returning one of the smallest elements (like poll). The size of the queue\n// thus remains unchanged.\nFastPriorityQueue.prototype.replaceTop = function(myval) {\n  if (this.size == 0) return undefined;\n  var ans = this.array[0];\n  this.array[0] = myval;\n  this._percolateDown(0);\n  return ans;\n};\n\n// recover unused memory (for long-running priority queues)\nFastPriorityQueue.prototype.trim = function() {\n  this.array = this.array.slice(0, this.size);\n};\n\n// Check whether the heap is empty\nFastPriorityQueue.prototype.isEmpty = function() {\n  return this.size === 0;\n};\n\n// iterate over the items in order, pass a callback that receives (item, index) as args.\n// TODO once we transpile, uncomment\n// if (Symbol && Symbol.iterator) {\n//   FastPriorityQueue.prototype[Symbol.iterator] = function*() {\n//     if (this.isEmpty()) return;\n//     var fpq = this.clone();\n//     while (!fpq.isEmpty()) {\n//       yield fpq.poll();\n//     }\n//   };\n// }\nFastPriorityQueue.prototype.forEach = function(callback) {\n  if (this.isEmpty() || typeof callback != 'function') return;\n  var i = 0;\n  var fpq = this.clone();\n  while (!fpq.isEmpty()) {\n    callback(fpq.poll(), i++);\n  }\n};\n\n// return the k 'smallest' elements of the queue as an array,\n// runs in O(k log k) time, the elements are not removed\n// from the priority queue.\nFastPriorityQueue.prototype.kSmallest = function(k) {\n  if ((this.size == 0) || (k<=0)) return [];\n  k = Math.min(this.size, k);\n  const newSize = Math.min(this.size, (2 ** (k - 1)) + 1);\n  if (newSize < 2) { return [this.peek()] }\n\n  const fpq = new FastPriorityQueue(this.compare);\n  fpq.size = newSize;\n  fpq.array = this.array.slice(0, newSize);\n\n  const smallest = new Array(k);\n  for (let i = 0; i < k; i++) {\n    smallest[i] = fpq.poll();\n  }\n  return smallest;\n}\n\nmodule.exports = FastPriorityQueue;\n"]}