You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This call should not always happen here, as it can cause the compare function to be called with undefined values while the compare function should only receive whatever the generic heap value type is.
This is causing an issue for me when constructing a MinHeap with heapify as I'm storing key-value pairs in a length-2 array. My compare function ((a, b) => a[0] - b[0]) is being called even though indexOutOfBounds is true, which causes undefined to be passed as b, causing TypeError: Cannot read property '0' of undefined.
I'm talking about this call: https://github.com/jeffzh4ng/iruka/blob/02acaa0c621a6db9e874d6a7b4cc1bf2fd87f99a/src/data-structures/priority-queues/min-binary-heap.ts#L161
This call should not always happen here, as it can cause the compare function to be called with undefined values while the compare function should only receive whatever the generic heap value type is.
This is causing an issue for me when constructing a MinHeap with heapify as I'm storing key-value pairs in a length-2 array. My compare function (
(a, b) => a[0] - b[0]
) is being called even thoughindexOutOfBounds
is true, which causes undefined to be passed asb
, causingTypeError: Cannot read property '0' of undefined
.Inlining the function call fixes it:
Alternatively the bound check can be put in the
while
conditionThe text was updated successfully, but these errors were encountered: