I'm trying to implement the shrinking operation for a circular buffer. The buffer has a start pointer( m_start ) and stores the number of elements( m_numelements). When the buffer is full I just purge the old value.
Say we have a array of size 16. m_start = 9 m_numelements = 11.
I want to shrink this array into an array of size 8( Can discard elements ).
The constraint here is that m_start( 9 ) of the old array should map to the m_start % new capacity ( 9 % 8 = 1 ) of the new array.
I tried writing the code but ended up with a lot of if-else ladder. Any efficient implementation for this ?