Exemplo n.º 1
0
 public QuickSet(int initialCapacity, int tableSizePower, IUnmanagedMemoryPool pool, TEqualityComparer comparer)
 {
     pool.Take <T>(initialCapacity, out var span);
     pool.Take <int>(span.Length << tableSizePower, out var tableSpan);
     //No guarantee that the table is clean; clear it.
     tableSpan.Clear(0, tableSpan.Length);
     this = new QuickSet <T, TEqualityComparer>(ref span, ref tableSpan, comparer, tableSizePower);
 }
Exemplo n.º 2
0
 public QuickDictionary(int initialCapacity, int tableSizePower, IUnmanagedMemoryPool pool, TEqualityComparer comparer)
 {
     pool.Take <TKey>(initialCapacity, out var keySpan);
     pool.Take <TValue>(keySpan.Length, out var valueSpan);
     pool.Take <int>(keySpan.Length << tableSizePower, out var tableSpan);
     //No guarantee that the table is clean; clear it.
     tableSpan.Clear(0, tableSpan.Length);
     this = new QuickDictionary <TKey, TValue, TEqualityComparer>(ref keySpan, ref valueSpan, ref tableSpan, comparer, tableSizePower);
 }
Exemplo n.º 3
0
        public void Resize(int newSize, IUnmanagedMemoryPool pool)
        {
            var targetCapacity = pool.GetCapacityForCount <T>(newSize);

            if (targetCapacity != Span.Length)
            {
                var oldSet = this;
                pool.Take <T>(newSize, out var newSpan);
                pool.Take <int>(newSpan.Length << TablePowerOffset, out var newTableSpan);
                //There is no guarantee that the table retrieved from the pool is clean. Clear it!
                newTableSpan.Clear(0, newTableSpan.Length);
                Resize(ref newSpan, ref newTableSpan, out var oldSpan, out var oldTableSpan);
                oldSet.Dispose(pool);
            }
        }
Exemplo n.º 4
0
        public void Resize(int newSize, IUnmanagedMemoryPool pool)
        {
            var targetKeyCapacity = pool.GetCapacityForCount <TKey>(newSize);

            if (targetKeyCapacity != Keys.Length)
            {
                pool.Take <TKey>(newSize, out var newKeySpan);
                pool.Take <TValue>(newKeySpan.Length, out var newValueSpan);
                pool.Take <int>(newKeySpan.Length << TablePowerOffset, out var newTableSpan);
                //There is no guarantee that the table retrieved from the pool is clean. Clear it!
                newTableSpan.Clear(0, newTableSpan.Length);
                var oldDictionary = this;
                Resize(ref newKeySpan, ref newValueSpan, ref newTableSpan, out var oldKeySpan, out var oldValueSpan, out var oldTableSpan);
                oldDictionary.Dispose(pool);
            }
        }
Exemplo n.º 5
0
 public QuickQueue(int minimumInitialCount, IUnmanagedMemoryPool pool)
 {
     pool.Take(minimumInitialCount, out Span);
     Count        = 0;
     CapacityMask = GetCapacityMask(Span.Length);
     FirstIndex   = 0;
     LastIndex    = CapacityMask;
     ValidateSpanCapacity(ref Span, CapacityMask);
 }
Exemplo n.º 6
0
        public void Resize(int newSize, IUnmanagedMemoryPool pool)
        {
            var targetCapacity = pool.GetCapacityForCount <T>(newSize);

            if (targetCapacity != Span.Length)
            {
                var oldQueue = this;
                pool.Take <T>(newSize, out var newSpan);
                Resize(ref newSpan, out var oldSpan);
                oldQueue.Dispose(pool);
            }
        }