Esempio n. 1
0
 ///<summary>A modified copy with more incremental rebuilding performed (in order to eventually discard garbage).</summary>
 private DropCollectStack <T> IterRebuild()
 {
     return
         // iteratively transfer from _itemsTraverser to _partialReversedItems
         (!_itemsTraverser.IsEmpty ? With(
              itemsTraverser: _itemsTraverser.Pop(),
              partialReversedItems: _partialReversedItems.Push(_itemsTraverser.Peek))
          // then iteratively transfer from _partialReversedItems to _partialRebuiltItems
       : !_partialReversedItems.IsEmpty ? With(
              partialReversedItems: _partialReversedItems.Pop(),
              partialRebuiltItems: _partialRebuiltItems.Push(_partialReversedItems.Peek()))
          // then, if there are new items, place them in _itemsTraverser for iterative transfer
       : _items.Count > _partialRebuiltItems.Count ? With(
              itemsTraverser: _items.Pop().KeepOnly(_items.Count - _partialRebuiltItems.Count - 1),
              partialReversedItems: _partialReversedItems.Push(_items.Peek))
          // if there were no new items, then we've finished rebuilding and can use the result
       : new DropCollectStack <T>(_partialRebuiltItems, _partialRebuiltItems));
 }
Esempio n. 2
0
        ///<summary>A modified copy with some more rebuilding work done.</summary>
        private Queue <T> IterRebuild()
        {
            switch (_incomingTraverser.Count)
            {
            case 0: return(With(ready: _partialOutgoing, reStack: DropStack <T> .Empty, reFeed: _incoming.UnderlyingStack));

            case 1: return(With(ready: _partialOutgoing.Push(_incomingTraverser.Peek), reStack: DropStack <T> .Empty, reFeed: _incoming.UnderlyingStack));

            default: return(With(reStack: _partialOutgoing.Push(_incomingTraverser.Peek), reFeed: _incomingTraverser.Pop()));
            }
        }