-
old function: 54 lines of code
- 29 lines of code, 25 blank lines, 0 comment lines
-
new function: 137 lines of code
- 117 lines of code, 16 blank lines, 4 comment lines
-
from 29 lines of code to 117 lines of code (4x the lines of code)
-
from linear time complexity O(n) to constant time O(1)
- input size is the number of items that the player is holding
-
gaining improved time complexity at the cost of worsened space complexity was a worthy trade-off
-
Significance:
- Now, it takes the same amount of time to remove 64 of any item from an inventory slot as it does to remove 1 item.
- (eg. removing a stack of 64 porkchops and removing a single porkchop take the same amount of time)
- 64 is the maximum “input size” for the number of items that a player is holding in the game
- Player must frequently place and remove items in inventory
- By changing the time complexity from linear time to constant time, we avoid up to 63 unnecessary iterations EVERY time the player picks up or removes items from inventory
- this saves on computer processing power