Example #1
0
 /// <summary>
 /// Creates a new instance of <see cref="PooledIntegerSet"/>.
 /// </summary>
 /// <param name="pool">A <see cref="DynamicArrayPool{Int32}"/> instance from which the memory
 /// for this set should be allocated.</param>
 /// <param name="capacity">The initial capacity to allocate for this set.</param>
 public PooledIntegerSet(DynamicArrayPool <int> pool, int capacity = 0)
 {
     m_pool  = pool;
     m_token = pool.allocate((capacity > 0) ? DataStructureUtil.nextPowerOf2(capacity - 1) : 4);
     m_pool.getSpan(m_token).Fill(EMPTY_SLOT);
     m_count = 0;
 }
Example #2
0
        public void nextPowerOf2Test(int num)
        {
            int nextPowerOf2 = DataStructureUtil.nextPowerOf2(num);

            Assert.NotEqual(0, nextPowerOf2);
            Assert.True((nextPowerOf2 & (nextPowerOf2 - 1)) == 0, $"Expected {nextPowerOf2} to be a power of 2.");
            Assert.True(nextPowerOf2 >= num, $"Expected {nextPowerOf2} to be >= {num}");

            uint upperBound = (uint)Math.Max(num, 1) * 2;

            Assert.True((uint)nextPowerOf2 < upperBound, $"Expected {nextPowerOf2} to be < {upperBound}.");
        }