betterAddProduct Write a method in your Warehouse class to further optimize addProduct. As of now, it’s possible that an item is removed from a full sector to make room for a new product, even if there are other sectors which are not full. If the current sector is not full, add the product as normal. Otherwise perform a linear probing-like operation to try to find a non-full sector (if the current one is full). Keep incrementing the sector until you either find one with space, or you return to your original sector. If you get to Sector 9, wrap around to Sector 0. If you found a new sector with space, add the product into this sector. In a real-world scenario we would have to make sure to change the ID in our system and make sure it doesn’t conflict with an existing one. In this assignment that is not necessary since the output only contains the name. If you returned to the original sector, perform eviction and add the product as normal.
betterAddProduct Write a method in your Warehouse class to further optimize addProduct. As of now, it’s possible that an item is removed from a full sector to make room for a new product, even if there are other sectors which are not full. If the current sector is not full, add the product as normal. Otherwise perform a linear probing-like operation to try to find a non-full sector (if the current one is full). Keep incrementing the sector until you either find one with space, or you return to your original sector. If you get to Sector 9, wrap around to Sector 0. If you found a new sector with space, add the product into this sector. In a real-world scenario we would have to make sure to change the ID in our system and make sure it doesn’t conflict with an existing one. In this assignment that is not necessary since the output only contains the name. If you returned to the original sector, perform eviction and add the product as normal.
Step by step
Solved in 3 steps