code: function StablePriorityQueue(comparator) {
      this.array = [];
      this.size = 0;
      this.runningcounter = 0;
      this.compare = comparator || defaultcomparator;
      this.stable_compare = function(a, b) {
        var cmp = this.compare(a.value,b.value);
        return (cmp < 0) || ( (cmp == 0) && (a.counter < b.counter) );
      }
  }
docs: the provided comparator function should take a, b and return a negative number when a < b and equality when a == b