Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #965: collections.diff

File collections.diff, 33.0 kB (added by schveiguy, 9 months ago)
  • CircularSeq.d

    old new  
    111111         * Time complexity: O(1). 
    112112         * See_Also: tango.util.collection.impl.Collection.Collection.elements 
    113113        **/ 
    114         public final GuardIterator!(T) elements() 
     114        public final DispensableIterator!(T) dispensableElements() 
    115115        { 
    116116                return new CellIterator!(T)(this); 
    117117        } 
     
    356356        public final void removeHead() 
    357357        { 
    358358                if (firstCell().isSingleton()) 
    359                    list = null; 
     359                    list = null; 
    360360                else 
    361                    
    362                    auto n = list.next(); 
    363                    list.unlink(); 
    364                    list = n; 
    365                    
     361               
     362                    auto n = list.next(); 
     363                    list.unlink(); 
     364                    list = n; 
     365               
    366366                decCount(); 
    367367        } 
    368368 
     
    404404        public final void removeTail() 
    405405        { 
    406406                auto l = lastCell(); 
     407                l.unlink(); 
    407408                if (l is list) 
    408409                    list = null; 
    409                 else 
    410                    l.unlink(); 
    411410                decCount(); 
    412411        } 
    413412 
     
    650649                    } 
    651650        } 
    652651 
     652        private final void remove_(CLCellT cell) 
     653        { 
     654            assert(cell !is null); 
     655            if(cell is list) 
     656            { 
     657              if(list.isSingleton()) 
     658                list = null; 
     659              else 
     660                list = list.next; 
     661            } 
     662            cell.unlink(); 
     663            decCount(); 
     664        } 
    653665 
     666 
    654667        /** 
    655668         * helper for replace * 
    656669        **/ 
     
    716729        static class CellIterator(T) : AbstractIterator!(T) 
    717730        { 
    718731                private CLCellT cell; 
     732                private CLCellT prev; 
    719733 
    720734                public this (CircularSeq seq) 
    721735                { 
     
    727741                { 
    728742                        decRemaining(); 
    729743                        auto v = cell.element(); 
     744                        prev = cell; 
    730745                        cell = cell.next(); 
    731746                        return v; 
    732747                } 
     
    743758                            } 
    744759                        return result; 
    745760                } 
     761 
     762                public void remove() 
     763                { 
     764                    // remove prev 
     765                  checkCorrupted(); 
     766                    if(prev is null) 
     767                      removeError(); 
     768                    (cast(CircularSeq)dispenser).remove_(prev); 
     769                    prev = null; 
     770                    updateMutation(); 
     771                } 
    746772        } 
    747773} 
    748774 
  • TreeMap.d

    old new  
    157157         * Time complexity: O(1). 
    158158         * See_Also: tango.util.collection.impl.Collection.Collection.elements 
    159159        **/ 
    160         public final GuardIterator!(T) elements() 
     160        public final DispensableIterator!(T) dispensableElements() 
    161161        { 
    162                 return keys(); 
     162                return new MapIterator!(K, T)(this); 
    163163        } 
    164164 
    165165        /*********************************************************************** 
     
    545545                   } 
    546546        } 
    547547 
     548        private final void remove_(RBPairT node) 
     549        { 
     550          tree = cast(RBPairT)node.remove(tree); 
     551          decCount(); 
     552        } 
     553 
    548554        // ImplementationCheckable methods 
    549555 
    550556        /** 
     
    585591        private static class MapIterator(K, V) : AbstractMapIterator!(K, V) 
    586592        { 
    587593                private RBPairT pair; 
     594                private RBPairT prev; 
    588595 
    589596                public this (TreeMap map) 
    590597                { 
     
    605612                { 
    606613                        decRemaining(); 
    607614                        auto v = pair.element(); 
     615                        prev = pair; 
    608616                        pair = cast(RBPairT) pair.successor(); 
    609617                        return v; 
    610618                } 
     
    635643                            } 
    636644                        return result; 
    637645                } 
     646 
     647                void remove() 
     648                { 
     649                  checkCorrupted(); 
     650                  if(prev is null) 
     651                    removeError(); 
     652                  (cast(TreeMap)dispenser).remove_(prev); 
     653                  updateMutation(); 
     654                  prev = null; 
     655                } 
    638656        } 
    639657} 
    640658 
  • model/GuardIterator.d

    old new  
    3131public interface GuardIterator(V) : Iterator!(V) 
    3232{ 
    3333        /** 
    34          * Return true if the collection that constructed this enumeration 
    35          * has been detectably modified since construction of this enumeration. 
    36          * Ability and precision of detection of this condition can vary 
    37          * across collection class implementations. 
     34         * Return true if the iterator is no longer valid.  This means that 
     35         * you can no longer use the iterator.  This can happen if the 
     36         * underlying object is changed in a way besides using the remove 
     37         * method. 
     38         * 
    3839         * more() is false whenever corrupted is true. 
    3940         * 
    4041         * Returns: true if detectably corrupted. 
     
    4445 
    4546        /** 
    4647         * Return the number of elements in the enumeration that have 
    47          * not yet been traversed. When corrupted() is true, this  
    48          * number may (or may not) be greater than zero even if more()  
    49          * is false. Exception recovery mechanics may be able to 
    50          * use this as an indication that recovery of some sort is 
    51          * warranted. However, it is not necessarily a foolproof indication. 
     48         * not yet been traversed.  If the iterator cannot determine the 
     49         * number of elements left, this returns -1. 
    5250         * <P> 
    5351         * You can also use it to pack enumerations into arrays. For example: 
    5452         * <PRE> 
     
    7674        int opApply (int delegate (inout K key, inout V value) dg);         
    7775} 
    7876 
     77 
     78public interface DispensableIterator(V) : GuardIterator!(V) 
     79{ 
     80        /** 
     81         * Remove the element just retrieved with get().  This does not cause 
     82         * this iterator to become corrupted,  but may cause other iterators 
     83         * to do so. 
     84         */ 
     85        public void remove(); 
     86} 
  • model/Dispenser.d

    old new  
    1515module tango.util.collection.model.Dispenser; 
    1616 
    1717private import  tango.util.collection.model.View, 
     18                tango.util.collection.model.GuardIterator, 
    1819                tango.util.collection.model.Iterator; 
    1920 
    2021/** 
     
    158159        **/ 
    159160 
    160161        public void remove (T element); 
     162 
     163        /** 
     164         * Return an iterator that can also be used to remove elements 
     165         */ 
     166        public DispensableIterator!(T) dispensableElements(); 
    161167} 
    162168 
    163169 
  • impl/AbstractIterator.d

    old new  
    1717 
    1818private import  tango.core.Exception; 
    1919 
    20 private import  tango.util.collection.model.View
     20private import  tango.util.collection.model.Dispenser
    2121                tango.util.collection.model.GuardIterator; 
    2222                 
    2323 
     
    3232 * <P> For an introduction to this package see <A HREF="index.html"> Overview </A>. 
    3333**/ 
    3434 
    35 public abstract class AbstractIterator(T) : GuardIterator!(T) 
     35public abstract class AbstractIterator(T) : DispensableIterator!(T) 
    3636{ 
    3737        /** 
    3838         * The collection being enumerated 
    3939        **/ 
    4040 
    41         private View!(T) view
     41        protected Dispenser!(T) dispenser
    4242 
    4343        /** 
    4444         * The version number of the collection we got upon construction 
     
    4848 
    4949        /** 
    5050         * The number of elements we think we have left. 
    51          * Initialized to view.size() upon construction 
     51         * Initialized to dispenser.size() upon construction 
    5252        **/ 
    5353 
    5454        private uint togo; 
    5555         
    5656 
    57         protected this (View!(T) v
     57        protected this (Dispenser!(T) d
    5858        { 
    59                 view = v
    60                 togo = v.size(); 
    61                 mutation = v.mutation(); 
     59                dispenser = d
     60                togo = d.size(); 
     61                mutation = d.mutation(); 
    6262        } 
    6363 
    6464        /** 
     
    6767         * See_Also: tango.util.collection.impl.Collection.CollectionIterator.corrupted 
    6868        **/ 
    6969 
    70         public final bool corrupted() 
     70        final public bool corrupted() 
    7171        { 
    72                 return mutation != view.mutation; 
     72                return mutation != dispenser.mutation; 
    7373        } 
    7474 
    7575        /** 
     
    8686         * Return true if remaining > 0 and not corrupted 
    8787         * See_Also: tango.util.collection.model.Iterator.more 
    8888        **/ 
    89         public final bool more() 
     89        public bool more() 
    9090        { 
    91                 return togo > 0 && mutation is view.mutation
     91                return togo > 0 && !corrupted()
    9292        } 
    9393 
    9494        /** 
     95         *  Call this after remove is called to keep this iterator in sync 
     96         *  with the underlying collection 
     97         */ 
     98        protected void updateMutation() 
     99        { 
     100                mutation++; 
     101        } 
     102 
     103        /** 
    95104         * Subclass utility.  
    96105         * Tries to decrement togo, raising exceptions 
    97          * if it is already zero or if corrupted() 
     106         * if it is already zero or if invalid() 
    98107         * Always call as the first line of get. 
    99108        **/ 
    100109        protected final void decRemaining() 
    101110        { 
    102                 if (mutation != view.mutation) 
    103                     throw new CorruptedIteratorException ("Collection modified during iteration"); 
    104  
    105                 if (togo is 0) 
     111          checkCorrupted(); 
     112                if (togo == 0) 
    106113                    throw new NoSuchElementException ("exhausted enumeration"); 
    107114 
    108115                --togo; 
    109116        } 
     117 
     118        protected final void checkCorrupted() 
     119        { 
     120                if (corrupted) 
     121                    throw new CorruptedIteratorException ("Collection modified during iteration"); 
     122 
     123        } 
     124 
     125        protected final void removeError() 
     126        { 
     127          throw new NoSuchElementException("remove called before get"); 
     128        } 
    110129} 
    111130 
    112131 
     
    114133{ 
    115134        abstract V get (inout K key); 
    116135 
    117         protected this (View!(V) c) 
     136        protected this (Dispenser!(V) c) 
    118137        { 
    119138                super (c); 
    120139        } 
  • impl/Collection.d

    old new  
    2222 
    2323private import  tango.util.collection.model.View, 
    2424                tango.util.collection.model.Iterator, 
     25                tango.util.collection.model.GuardIterator, 
    2526                tango.util.collection.model.Dispenser; 
    2627 
    2728/******************************************************************************* 
     
    626627        ************************************************************************/ 
    627628 
    628629        abstract T take(); 
     630 
     631        /** 
     632         * Implements tango.util.collection.impl.Collection.Collection.elements 
     633         * Time complexity: O(1). 
     634         * See_Also: tango.util.collection.impl.Collection.Collection.elements 
     635        **/ 
     636        public final GuardIterator!(T) elements() 
     637        { 
     638                return dispensableElements(); 
     639        } 
    629640} 
    630641 
    631642 
  • HashSet.d

    old new  
    4242 
    4343        alias SetCollection!(T).remove     remove; 
    4444        alias SetCollection!(T).removeAll  removeAll; 
     45        alias SetCollection!(T).add        add; 
    4546 
    4647 
    4748        // instance variables 
     
    212213         * Time complexity: O(1). 
    213214         * See_Also: tango.util.collection.impl.Collection.Collection.elements 
    214215        **/ 
    215         public final GuardIterator!(T) elements() 
     216        public final DispensableIterator!(T) dispensableElements() 
    216217        { 
    217218                return new CellIterator!(T)(this); 
    218219        } 
     
    273274                            trail = n; 
    274275                            } 
    275276                         else 
    276                             trail.next(n); 
     277                            trail.unlinkNext(); 
    277278                         return ; 
    278279                         }  
    279280                      else 
     
    361362        // Helper methods 
    362363 
    363364        /** 
     365         *  remove the cell at target whose previous node is at prev.  If prev 
     366         *  is null, then assume target is the first element in idx 
     367         */ 
     368        private final void remove_(LLCellT prev, LLCellT target, int idx) 
     369        { 
     370            if(prev is null) 
     371                table[idx] = target.next; 
     372            else 
     373                prev.unlinkNext(); 
     374            decCount(); 
     375        } 
     376 
     377        /** 
    364378         * Check to see if we are past load factor threshold. If so, resize 
    365379         * so that we are at half of the desired threshold. 
    366380         * Also while at it, check to see if we are empty so can just 
     
    515529        { 
    516530                private int             row; 
    517531                private LLCellT         cell; 
     532                private LLCellT         prev; 
     533                private bool            cellRemoved; 
    518534                private LLCellT[]       table; 
    519535 
    520536                public this (HashSet set) 
    521537                { 
    522538                        super (set); 
    523539                        table = set.table; 
     540                        cellRemoved = true; 
    524541                } 
    525542 
    526543                public final T get() 
    527544                { 
    528545                        decRemaining(); 
    529  
     546                        if(cell) 
     547                        { 
     548                          prev = cell; 
     549                          cell = cell.next(); 
     550                        } 
    530551                        while (cell is null) 
    531                                cell = table [row++]; 
     552                        { 
     553                          prev = null; 
     554                          cell = table [row++]; 
     555                        } 
    532556 
     557                        cellRemoved = false; 
    533558                        auto v = cell.element(); 
    534                         cell = cell.next(); 
    535559                        return v; 
    536560                } 
    537561 
     
    547571                            } 
    548572                        return result; 
    549573                } 
     574                 
     575                void remove() 
     576                { 
     577                    checkCorrupted(); 
     578                    if(cellRemoved) 
     579                        removeError(); 
     580                    (cast(HashSet)dispenser).remove_(prev, cell, row - 1); 
     581                    updateMutation(); 
     582                    cellRemoved = true; 
     583                    cell = prev; 
     584                    if(cell is null) 
     585                        row--; 
     586                    prev = null; 
     587                } 
    550588        } 
    551589} 
    552590 
  • HashMap.d

    old new  
    255255         
    256256        ************************************************************************/ 
    257257         
    258         public final GuardIterator!(V) elements() 
     258        public final DispensableIterator!(V) dispensableElements() 
    259259        { 
    260                 return keys(); 
     260                return new MapIterator!(K, V)(this); 
    261261        } 
    262262 
    263263        /*********************************************************************** 
     
    767767                    } 
    768768        } 
    769769 
     770        /** 
     771         *  remove the cell at target whose previous node is at prev.  If prev 
     772         *  is null, then assume target is the first element in idx 
     773         */ 
     774        private final void remove_(LLPairT prev, LLPairT target, int idx) 
     775        { 
     776            if(prev is null) 
     777                table[idx] = cast(LLPairT)target.next; 
     778            else 
     779                prev.unlinkNext(); 
     780            decCount(); 
     781        } 
     782 
    770783        /*********************************************************************** 
    771784 
    772785        ************************************************************************/ 
     
    890903        { 
    891904                private int             row; 
    892905                private LLPairT         pair; 
     906                private LLPairT         prev; 
     907                private bool            pairRemoved; 
    893908                private LLPairT[]       table; 
    894909 
    895910                public this (HashMap map) 
    896911                { 
    897912                        super (map); 
    898913                        table = map.table; 
     914                        pairRemoved = true; 
    899915                } 
    900916 
    901917                public final V get(inout K key) 
     
    908924                public final V get() 
    909925                { 
    910926                        decRemaining(); 
    911  
    912927                        if (pair) 
    913                             pair = cast(LLPairT) pair.next(); 
     928                        { 
     929                          prev = pair; 
     930                          pair = cast(LLPairT) pair.next(); 
     931                        } 
    914932 
    915933                        while (pair is null) 
    916                                pair = table [row++]; 
     934                        { 
     935                          prev = null; 
     936                          pair = table [row++]; 
     937                        } 
    917938 
     939                        pairRemoved = false; 
    918940                        return pair.element(); 
    919941                } 
    920942 
     
    944966                            } 
    945967                        return result; 
    946968                } 
     969 
     970                void remove() 
     971                { 
     972                  checkCorrupted(); 
     973                  if(pairRemoved) 
     974                    removeError(); 
     975                  (cast(HashMap)dispenser).remove_(prev, pair, row - 1); 
     976                  updateMutation(); 
     977                  pairRemoved = true; 
     978                  pair = prev; 
     979                  if(pair is null) 
     980                    row--; 
     981                  prev = null; 
     982                } 
    947983        } 
    948984} 
    949985 
  • LinkSeq.d

    old new  
    129129         * Time complexity: O(1). 
    130130         * See_Also: tango.util.collection.impl.Collection.Collection.elements 
    131131        **/ 
    132         public final GuardIterator!(T) elements() 
     132        public final DispensableIterator!(T) dispensableElements() 
    133133        { 
    134134                return new CellIterator!(T)(this); 
    135135        } 
     
    601601                            trail = n; 
    602602                            } 
    603603                         else 
    604                             trail.next(n); 
     604                            trail.unlinkNext(); 
    605605 
    606606                         if (!allOccurrences || count is 0) 
    607607                             return ; 
     
    616616                      } 
    617617        } 
    618618 
     619        private final void removeNext_(LLCellT trail) 
     620        { 
     621          if(trail is null) 
     622            list = list.next; 
     623          else 
     624            trail.unlinkNext(); 
     625          decCount(); 
     626        } 
    619627 
    620628        /** 
    621629         * Helper for replace 
     
    710718        private static class CellIterator(T) : AbstractIterator!(T) 
    711719        { 
    712720                private LLCellT cell; 
     721                private LLCellT prev; 
     722                private LLCellT trail; 
    713723 
    714724                public this (LinkSeq seq) 
    715725                { 
     
    721731                { 
    722732                        decRemaining(); 
    723733                        auto v = cell.element(); 
     734                        if(prev) 
     735                          trail = prev; 
     736                        prev = cell; 
    724737                        cell = cell.next(); 
    725738                        return v; 
    726739                } 
     
    737750                            } 
    738751                        return result; 
    739752                } 
     753 
     754                void remove() 
     755                { 
     756                  checkCorrupted(); 
     757                  if(prev is null) 
     758                    removeError(); 
     759                  (cast(LinkSeq)dispenser).removeNext_(trail); 
     760                  prev = null; 
     761                  updateMutation(); 
     762                } 
    740763        } 
    741764} 
    742765 
  • iterator/ArrayIterator.d

    old new  
    3434{ 
    3535        private T [] arr_; 
    3636        private int cur_; 
    37         private int size_; 
    3837 
    3938        /** 
    4039         * Build an enumeration that returns successive elements of the array 
     
    4342        { 
    4443                // arr_ = arr; cur_ = 0; size_ = arr._length; 
    4544                arr_ = arr; 
    46                 cur_ = -1; 
    47                 size_ = arr.length; 
     45                cur_ = 0; 
    4846        } 
    4947 
     48        public bool corrupted() 
     49        { 
     50          // 
     51          // no way of knowing 
     52          // 
     53          return false; 
     54        } 
     55 
    5056        /** 
    51          * Implements tango.util.collection.impl.Collection.CollectionIterator.remaining 
    52          * See_Also: tango.util.collection.impl.Collection.CollectionIterator.remaining 
     57          * this doesn't implement any interface, but is similar to 
     58          * GuardIterator's remaining.  It always returns the number of 
     59          * elements left. 
    5360        **/ 
    5461        public uint remaining() 
    5562        { 
    56                 return size_; 
     63                return arr_.length - cur_; 
    5764        } 
    5865 
    5966        /** 
     
    6269        **/ 
    6370        public bool more() 
    6471        { 
    65                 return size_ > 0
     72                return cur_ < arr_.length
    6673        } 
    6774 
    6875        /** 
    69          * Implements tango.util.collection.impl.Collection.CollectionIterator.corrupted. 
    70          * Always false. Inconsistency cannot be reliably detected for arrays 
    71          * Returns: false 
    72          * See_Also: tango.util.collection.impl.Collection.CollectionIterator.corrupted 
    73         **/ 
    74  
    75         public bool corrupted() 
    76         { 
    77                 return false; 
    78         } 
    79  
    80         /** 
    8176         * Implements tango.util.collection.model.Iterator.get(). 
    8277         * See_Also: tango.util.collection.model.Iterator.get() 
    8378        **/ 
    8479        public T get() 
    8580        { 
    86                 if (size_ > 0
     81                if (more
    8782                   { 
    88                    --size_; 
    89                    ++cur_; 
    90                    return arr_[cur_]; 
     83                   return arr_[cur_++]; 
    9184                   } 
    9285                throw new NoSuchElementException ("Exhausted Iterator"); 
    9386        } 
     
    9790        { 
    9891                int result; 
    9992 
    100                 for (auto i=size_; i--;
     93                while (more
    10194                    { 
    10295                    auto value = get(); 
    10396                    if ((result = dg(value)) != 0) 
  • ArraySeq.d

    old new  
    2323private import  tango.util.collection.impl.SeqCollection, 
    2424                tango.util.collection.impl.AbstractIterator; 
    2525 
     26private import  tango.core.Exception; 
    2627 
     28 
    2729/** 
    2830 * 
    2931 * Dynamically allocated and resized Arrays. 
     
    212214        } 
    213215 
    214216        /** 
    215          * Implements tango.util.collection.impl.Collection.Collection.elements 
     217         * Implements tango.util.collection.model.Dispenser.Dispenser.dispensableElements 
    216218         * Time complexity: O(1). 
    217          * See_Also: tango.util.collection.impl.Collection.Collection.elements 
     219         * See_Also: tango.util.collection.model.Dispenser.Dispenser.dispensableElements 
    218220        **/ 
    219         public final GuardIterator!(T) elements() 
     221        public final DispensableIterator!(T) dispensableElements() 
    220222        { 
    221223                return new ArrayIterator!(T)(this); 
    222224        } 
     
    864866        static class ArrayIterator(T) : AbstractIterator!(T) 
    865867        { 
    866868                private int row; 
    867                 private T[] array; 
     869                ArraySeq array; 
     870                bool prevRemoved; 
    868871 
    869872                public this (ArraySeq seq) 
    870873                { 
    871874                        super (seq); 
    872                         array = seq.array; 
     875                        this.array = seq; 
     876                        prevRemoved = true; 
    873877                } 
    874878 
    875879                public final T get() 
    876880                { 
    877881                        decRemaining(); 
     882                        prevRemoved = false; 
    878883                        return array[row++]; 
    879884                } 
    880885 
     
    890895                            } 
    891896                        return result; 
    892897                } 
     898                 
     899                public final void remove() 
     900                { 
     901                  checkCorrupted(); 
     902                        if(prevRemoved) 
     903                            removeError(); 
     904                        prevRemoved = true; 
     905                        array.removeAt(--row); 
     906                        updateMutation(); 
     907                } 
    893908        } 
     909 
    894910} 
    895911 
    896912 
  • ArrayBag.d

    old new  
    5757 
    5858        alias BagCollection!(T).remove     remove; 
    5959        alias BagCollection!(T).removeAll  removeAll; 
     60        alias BagCollection!(T).add        add; 
    6061 
    6162        /** 
    6263         * The default chunk size to use for buffers 
     
    255256         * Time complexity: O(1). 
    256257         * See_Also: tango.util.collection.impl.Collection.Collection.elements 
    257258        **/ 
    258         public final GuardIterator!(T) elements() 
     259        public final DispensableIterator!(T) dispensableElements() 
    259260        { 
    260261                return new ArrayIterator!(T)(this); 
    261262        } 
     
    432433                } 
    433434        } 
    434435 
     436        private final void remove_(CLCellT cell, int idx) 
     437        { 
     438            cell.element[idx] = tail.element[lastCount - 1]; 
     439            tail.element[lastCount - 1] = T.init; 
     440            shrink_(); 
     441        } 
     442 
    435443        private final void replace_(T oldElement, T newElement, bool allOccurrences) 
    436444        { 
    437445                if (!isValidArg(oldElement) || count is 0 || oldElement == (newElement)) 
     
    549557        { 
    550558                private CLCellT cell; 
    551559                private T[]     buff; 
     560                private bool prevRemoved; 
    552561                private int     index; 
    553562 
    554563                public this (ArrayBag bag) 
     
    558567                         
    559568                        if (cell) 
    560569                            buff = cell.element();   
     570                        prevRemoved = true; 
    561571                } 
    562572 
    563573                public final T get() 
     
    569579                           buff = cell.element(); 
    570580                           index = 0; 
    571581                           } 
     582                        prevRemoved = false; 
    572583                        return buff[index++]; 
    573584                } 
    574585 
     
    584595                            } 
    585596                        return result; 
    586597                } 
     598 
     599                void remove() 
     600                { 
     601                  checkCorrupted(); 
     602                    if(prevRemoved) 
     603                      removeError(); 
     604 
     605                    prevRemoved = true; 
     606 
     607                    if(index == 0) 
     608                    { 
     609                      // 
     610                      // skip to last element on previous link 
     611                      // 
     612                        cell = cell.prev; 
     613                        buff = cell.element; 
     614                        index = buff.length - 1; 
     615                    } 
     616                    else 
     617                        index--; 
     618                    (cast(ArrayBag)dispenser).remove_(cell, index); 
     619                    updateMutation(); 
     620                } 
    587621        } 
    588622} 
    589623 
  • TreeBag.d

    old new  
    3737 
    3838        alias BagCollection!(T).remove     remove; 
    3939        alias BagCollection!(T).removeAll  removeAll; 
     40        alias BagCollection!(T).add        add; 
    4041 
    4142 
    4243        // instance variables 
     
    151152         * Time complexity: O(1). 
    152153         * See_Also: tango.util.collection.impl.Collection.Collection.elements 
    153154        **/ 
    154         public final GuardIterator!(T) elements() 
     155        public final DispensableIterator!(T) dispensableElements() 
    155156        { 
    156157                return new CellIterator!(T)(this); 
    157158        } 
     
    379380                      } 
    380381        } 
    381382 
     383        private final void remove_(RBCellT node) 
     384        { 
     385          tree = node.remove(tree); 
     386          decCount(); 
     387        } 
     388 
    382389        private final void replace_(T oldElement, T newElement, bool allOccurrences) 
    383390        { 
    384391                if (!isValidArg(oldElement) || count is 0 || oldElement == newElement) 
     
    3