Skip to content

Commit

Permalink
feat(heap): clean the constructor and remove insert data
Browse files Browse the repository at this point in the history
  • Loading branch information
khaledosama999 committed Mar 1, 2021
1 parent beb5a86 commit 1417814
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/binary-heap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ abstract class BinaryHeap<T, U> {

protected extractor: (element: T) => U

public constructor(extractor: (element: T) => U, iterator?: IterableIterator<T>) {
public constructor(extractor: (element: T) => U) {
this.array = [];
this.extractor = extractor;

this.insertMany(iterator);
}

public insert(element: T) {
Expand Down Expand Up @@ -40,6 +38,14 @@ abstract class BinaryHeap<T, U> {
}
}

public delete(fn: (x:T)=>boolean) {
for (let index = 0; index < this.array.length; index += 1) {
if (fn(this.array[index])) {

}
}
}

protected parent(index: number) {
return Math.max(Math.floor((index - 1) / 2), 0);
}
Expand Down

0 comments on commit 1417814

Please sign in to comment.