Skip to content

Commit

Permalink
feat(CV-0): cleanup for floating points
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-jonathan committed Sep 18, 2023
1 parent c58efcf commit 645de35
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/structures/Heap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export type Heap<T> = {

export const heapParent = (index: number): number | never => {
assert(0 <= index, 'index must be 0 or greater')
return (index - 1) / 2
return Math.floor((index - 1) / 2)
}

export const heapLeft = (index: number): number | never => {
Expand Down Expand Up @@ -97,7 +97,7 @@ export const heapMaxHeapify = <T>(nodes: T[], size: number, index: number): void
export const createMaxHeap = <T>(nodes: T[]): Heap<T> => {
const size = nodes.length

for (let i = size / 2 - 1; 0 <= i; --i) {
for (let i = Math.floor(size / 2); 0 <= i; --i) {
heapMaxHeapify(nodes, size, i)
}

Expand Down

0 comments on commit 645de35

Please sign in to comment.