Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
andrasq committed Apr 24, 2021
1 parent a3e0008 commit 283e099
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ Todo

- might be more efficient to periodically gc the heap on a timer instead of checking
on every remove
- hashify([array]), toArray(), fromArray() (emulate the common `hash` methods)


Related Work
Expand Down
2 changes: 2 additions & 0 deletions qheap.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,14 @@ Heap.prototype.pop = Heap.prototype.remove;
Heap.prototype.dequeue = Heap.prototype.remove;

// builder, not initializer: appends items, not replaces
// FIXME: more useful to re-initialize from array
Heap.prototype.fromArray = function fromArray( array, base, bound ) {
var base = base || 0;
var bound = bound || array.length;
for (var i=base; i<bound; i++) this.insert(array[i]);
}

// FIXME: more useful to return sorted values
Heap.prototype.toArray = function toArray( limit ) {
limit = typeof limit === 'number' ? limit + 1 : this.length + 1;
return this._list.slice(1, limit);
Expand Down

0 comments on commit 283e099

Please sign in to comment.