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
The shiftUp operation is performed unconditionally whilst a child and parent's value can indeed match, thus executing an upwards shift inefficiently if the element removed was next-to-last in the tree and its children had an equal value to it.
Example:
// If the swapped account is in the heap, restore the invariant: its value can be smaller or larger than the removed value.if (rank <= _heap.size) {
if (_removedValue >getAccount(_heap, rank).value) shiftDown(_heap, rank);
elseshiftUp(_heap, rank);
}
Recommendation:
We advise the else statement to be adjusted to an else if (_removedValue < getAccount(_heap, rank).value) one, with the getAccount(_heap, rank).value value being cached to a local variable within the upper-most if clause to avoid the duplicate read gas cost between the if and else if conditional evaluations.
The text was updated successfully, but these errors were encountered:
These changes seems unlikely to save gas in our case: the amounts will all be different because of the interests earn. So even if 2 person supply exactly the same amount, if one does so one block after the other, the amounts will be different.
HOG-07C: Removal Upward Shift Optimization
Description:
The
shiftUp
operation is performed unconditionally whilst a child and parent's value can indeed match, thus executing an upwards shift inefficiently if the element removed was next-to-last in the tree and its children had an equal value to it.Example:
Recommendation:
We advise the
else
statement to be adjusted to anelse if (_removedValue < getAccount(_heap, rank).value)
one, with thegetAccount(_heap, rank).value
value being cached to a local variable within the upper-mostif
clause to avoid the duplicate read gas cost between theif
andelse if
conditional evaluations.The text was updated successfully, but these errors were encountered: