Exemplo n.º 1
0
 public QuickSet(int initialCapacity, int tableSizePower, IUnmanagedMemoryPool pool, TEqualityComparer comparer)
 {
     pool.TakeAtLeast <T>(initialCapacity, out var span);
     pool.TakeAtLeast <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.TakeAtLeast <TKey>(initialCapacity, out var keySpan);
     pool.TakeAtLeast <TValue>(keySpan.Length, out var valueSpan);
     pool.TakeAtLeast <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.TakeAtLeast <T>(newSize, out var newSpan);
                pool.TakeAtLeast <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.TakeAtLeast <TKey>(newSize, out var newKeySpan);
                pool.TakeAtLeast <TValue>(newKeySpan.Length, out var newValueSpan);
                pool.TakeAtLeast <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.TakeAtLeast(minimumInitialCount, out Span);
     Count        = 0;
     CapacityMask = GetCapacityMask(Span.Length);
     FirstIndex   = 0;
     LastIndex    = CapacityMask;
     ValidateSpanCapacity(ref Span, CapacityMask);
 }
Exemplo n.º 6
0
        void InternalResize(int newSize, IUnmanagedMemoryPool pool)
        {
            var oldAvailableIds = availableIds;

            pool.TakeAtLeast(newSize, out availableIds);
            Debug.Assert(oldAvailableIds.Length != availableIds.Length, "Did you really mean to resize this? Nothing changed!");
            oldAvailableIds.CopyTo(0, ref availableIds, 0, availableIdCount);
            pool.Return(ref oldAvailableIds);
        }
Exemplo n.º 7
0
        public void Resize(int newSize, IUnmanagedMemoryPool pool)
        {
            var targetCapacity = pool.GetCapacityForCount <T>(newSize);

            if (targetCapacity != Span.Length)
            {
                var oldQueue = this;
                pool.TakeAtLeast <T>(newSize, out var newSpan);
                Resize(ref newSpan, out var oldSpan);
                oldQueue.Dispose(pool);
            }
        }
Exemplo n.º 8
0
 public void Return(int id, IUnmanagedMemoryPool pool)
 {
     Debug.Assert(availableIds.Allocated);
     if (availableIdCount == availableIds.Length)
     {
         var oldAvailableIds = availableIds;
         pool.TakeAtLeast(Math.Max(availableIdCount * 2, availableIds.Length), out availableIds);
         oldAvailableIds.CopyTo(0, ref availableIds, 0, availableIdCount);
         pool.Return(ref oldAvailableIds);
     }
     ReturnUnsafely(id);
 }
Exemplo n.º 9
0
 public IdPool(int initialCapacity, IUnmanagedMemoryPool pool)
 {
     nextIndex        = 0;
     availableIdCount = 0;
     pool.TakeAtLeast(initialCapacity, out availableIds);
 }