Esempio n. 1
0
 public void FixedAddRange(IEnumerable <T> collection, int?addCount = null)
 {
     AddRange(collection, addCount);
     if (Count <= MaximumSize)
     {
         return;
     }
     T[] removed
         = IsStack
                                                 ? DropRange((Count - MaximumSize) + Overhead)
                                                 : DequeueRange((Count - MaximumSize) + Overhead);
     if (SetCapacityOnFixedAddRange)
     {
         SetCapacity(MaximumSize);
     }
     OnRemoveOverhead?.Invoke(removed);
 }
Esempio n. 2
0
 public void FixedPush(T element)
 {
     if (Count >= MaximumSize)
     {
         Debug.Assert(
             Count == MaximumSize,
             $"{GetType().GetFriendlyName()}: the fixed-size Stack contains more elements ({Count}) "
             + $"than its MaximumSize ({MaximumSize}).");
         T[] removed = DropRange(Math.Min(Count, (Count - MaximumSize) + Overhead + 1));
         if (SetCapacityOnFixedAddRange)
         {
             SetCapacity(MaximumSize);
         }
         OnRemoveOverhead?.Invoke(removed);
     }
     Push(element);
 }
Esempio n. 3
0
 public void FixedAddRange(
     ISequenceView <T> collection,
     bool enumerateInOrder = false,
     int?addCount          = null,
     bool countInOrder     = false)
 {
     AddRange(collection, enumerateInOrder, addCount, countInOrder);
     if (Count <= MaximumSize)
     {
         return;
     }
     T[] removed
         = IsStack
                                                 ? DropRange((Count - MaximumSize) + Overhead)
                                                 : DequeueRange((Count - MaximumSize) + Overhead);
     if (SetCapacityOnFixedAddRange)
     {
         SetCapacity(MaximumSize);
     }
     OnRemoveOverhead?.Invoke(removed);
 }