BEPUutilities2.ResourceManagement.BufferPool.GetPoolIndex C# (CSharp) Method

GetPoolIndex() public static method

Gets the exponent associated with the buffer pool which would hold the given count of elements.
public static GetPoolIndex ( int count ) : int
count int Element count to compute the batch index of.
return int
        public static int GetPoolIndex(int count)
        {
            Debug.Assert(count >= 0 && count < (1 << MaximumPoolIndex), "Count must be from 0 to " + ((1 << MaximumPoolIndex) - 1) + ", inclusive.");
            //We want the buffer which would fully contain the count, so it should be effectively Ceiling(Log(count)).
            //Doubling the value (and subtracting one, to avoid the already-a-power-of-two case) takes care of this.
            count = ((count > 0 ? count : 1) << 1) - 1;
            int log = 0;
            if ((count & 0xFFFF0000) > 0)
            {
                count >>= 16;
                log |= 16;
            }
            if ((count & 0xFF00) > 0)
            {
                count >>= 8;
                log |= 8;
            }
            if ((count & 0xF0) > 0)
            {
                count >>= 4;
                log |= 4;
            }
            if ((count & 0xC) > 0)
            {
                count >>= 2;
                log |= 2;
            }
            if ((count & 0x2) > 0)
            {
                log |= 1;
            }
            return log;
        }