Skip to content

Commit

Permalink
refactor: Move static methods to the top
Browse files Browse the repository at this point in the history
  • Loading branch information
the-spyke committed Dec 4, 2020
1 parent a2e3b2d commit 584401b
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions packages/undercut-collections/src/heap.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,13 @@ const EMPTY_ITEM = {};
/**
* @template T
*/
class Heap {
/**
* @param {(a: T, b: T) => number} comparator
*/
constructor(comparator) {
assertFunctor(comparator, `comparator`);

/** @type {Array<T>} */
this.$items = [];
this.$comparator = comparator;
}

export class Heap {
/**
* @param {number} index
* @returns {number}
*/
static getParentIndex(index) {
return Math.trunc((index - 1) / 2);
return index < 1 ? -1 : Math.trunc((index - 1) / 2);
}

/**
Expand All @@ -44,6 +33,17 @@ class Heap {
return 2 * index + 2;
}

/**
* @param {(a: T, b: T) => number} comparator
*/
constructor(comparator) {
assertFunctor(comparator, `comparator`);

/** @type {Array<T>} */
this.$items = [];
this.$comparator = comparator;
}

get isEmpty() {
return this.size === 0;
}
Expand Down

0 comments on commit 584401b

Please sign in to comment.