So I am trying to make a resizeable binary buffer where I am allocating a block of memory + 0.30% extra bytes so that if new data comes in that is larger than the current index. I can bit shift my buffer so that I can fit that data at its specified offset in the buffer. The problem with this is that the offset for each index after that needs to be updated based on the number of bits that were shifted. A naive solution might be to iterate through all the next offsets and increment by the number of bits shifted to make the new offsets. This can be slow though. It's important to note that since we could bit shift at different locations one index might have a more bit shifted value than another. For example, the zero index will never need be incremented since it's offset will always be zero. Whereas the last value in the buffer will need to take into a count of all the times we bit shifted. The one in the middle might need to take into account a value less than that. What algorithm can I use to efficiently calculate this?