 |
|
File collections.diff, 33.0 kB
(added by schveiguy, 9 months ago)
|
|
-
CircularSeq.d
| old |
new |
|
| 111 | 111 | * Time complexity: O(1). |
|---|
| 112 | 112 | * See_Also: tango.util.collection.impl.Collection.Collection.elements |
|---|
| 113 | 113 | **/ |
|---|
| 114 | | public final GuardIterator!(T) elements() |
|---|
| | 114 | public final DispensableIterator!(T) dispensableElements() |
|---|
| 115 | 115 | { |
|---|
| 116 | 116 | return new CellIterator!(T)(this); |
|---|
| 117 | 117 | } |
| … | … | |
| 356 | 356 | public final void removeHead() |
|---|
| 357 | 357 | { |
|---|
| 358 | 358 | if (firstCell().isSingleton()) |
|---|
| 359 | | list = null; |
|---|
| | 359 | list = null; |
|---|
| 360 | 360 | 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 | } |
|---|
| 366 | 366 | decCount(); |
|---|
| 367 | 367 | } |
|---|
| 368 | 368 | |
| … | … | |
| 404 | 404 | public final void removeTail() |
|---|
| 405 | 405 | { |
|---|
| 406 | 406 | auto l = lastCell(); |
|---|
| | 407 | l.unlink(); |
|---|
| 407 | 408 | if (l is list) |
|---|
| 408 | 409 | list = null; |
|---|
| 409 | | else |
|---|
| 410 | | l.unlink(); |
|---|
| 411 | 410 | decCount(); |
|---|
| 412 | 411 | } |
|---|
| 413 | 412 | |
| … | … | |
| 650 | 649 | } |
|---|
| 651 | 650 | } |
|---|
| 652 | 651 | |
|---|
| | 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 | } |
|---|
| 653 | 665 | |
|---|
| | 666 | |
|---|
| 654 | 667 | /** |
|---|
| 655 | 668 | * helper for replace * |
|---|
| 656 | 669 | **/ |
| … | … | |
| 716 | 729 | static class CellIterator(T) : AbstractIterator!(T) |
|---|
| 717 | 730 | { |
|---|
| 718 | 731 | private CLCellT cell; |
|---|
| | 732 | private CLCellT prev; |
|---|
| 719 | 733 | |
|---|
| 720 | 734 | public this (CircularSeq seq) |
|---|
| 721 | 735 | { |
| … | … | |
| 727 | 741 | { |
|---|
| 728 | 742 | decRemaining(); |
|---|
| 729 | 743 | auto v = cell.element(); |
|---|
| | 744 | prev = cell; |
|---|
| 730 | 745 | cell = cell.next(); |
|---|
| 731 | 746 | return v; |
|---|
| 732 | 747 | } |
| … | … | |
| 743 | 758 | } |
|---|
| 744 | 759 | return result; |
|---|
| 745 | 760 | } |
|---|
| | 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 | } |
|---|
| 746 | 772 | } |
|---|
| 747 | 773 | } |
|---|
| 748 | 774 | |
-
TreeMap.d
| old |
new |
|
| 157 | 157 | * Time complexity: O(1). |
|---|
| 158 | 158 | * See_Also: tango.util.collection.impl.Collection.Collection.elements |
|---|
| 159 | 159 | **/ |
|---|
| 160 | | public final GuardIterator!(T) elements() |
|---|
| | 160 | public final DispensableIterator!(T) dispensableElements() |
|---|
| 161 | 161 | { |
|---|
| 162 | | return keys(); |
|---|
| | 162 | return new MapIterator!(K, T)(this); |
|---|
| 163 | 163 | } |
|---|
| 164 | 164 | |
|---|
| 165 | 165 | /*********************************************************************** |
| … | … | |
| 545 | 545 | } |
|---|
| 546 | 546 | } |
|---|
| 547 | 547 | |
|---|
| | 548 | private final void remove_(RBPairT node) |
|---|
| | 549 | { |
|---|
| | 550 | tree = cast(RBPairT)node.remove(tree); |
|---|
| | 551 | decCount(); |
|---|
| | 552 | } |
|---|
| | 553 | |
|---|
| 548 | 554 | // ImplementationCheckable methods |
|---|
| 549 | 555 | |
|---|
| 550 | 556 | /** |
| … | … | |
| 585 | 591 | private static class MapIterator(K, V) : AbstractMapIterator!(K, V) |
|---|
| 586 | 592 | { |
|---|
| 587 | 593 | private RBPairT pair; |
|---|
| | 594 | private RBPairT prev; |
|---|
| 588 | 595 | |
|---|
| 589 | 596 | public this (TreeMap map) |
|---|
| 590 | 597 | { |
| … | … | |
| 605 | 612 | { |
|---|
| 606 | 613 | decRemaining(); |
|---|
| 607 | 614 | auto v = pair.element(); |
|---|
| | 615 | prev = pair; |
|---|
| 608 | 616 | pair = cast(RBPairT) pair.successor(); |
|---|
| 609 | 617 | return v; |
|---|
| 610 | 618 | } |
| … | … | |
| 635 | 643 | } |
|---|
| 636 | 644 | return result; |
|---|
| 637 | 645 | } |
|---|
| | 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 | } |
|---|
| 638 | 656 | } |
|---|
| 639 | 657 | } |
|---|
| 640 | 658 | |
-
model/GuardIterator.d
| old |
new |
|
| 31 | 31 | public interface GuardIterator(V) : Iterator!(V) |
|---|
| 32 | 32 | { |
|---|
| 33 | 33 | /** |
|---|
| 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 | * |
|---|
| 38 | 39 | * more() is false whenever corrupted is true. |
|---|
| 39 | 40 | * |
|---|
| 40 | 41 | * Returns: true if detectably corrupted. |
| … | … | |
| 44 | 45 | |
|---|
| 45 | 46 | /** |
|---|
| 46 | 47 | * 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. |
|---|
| 52 | 50 | * <P> |
|---|
| 53 | 51 | * You can also use it to pack enumerations into arrays. For example: |
|---|
| 54 | 52 | * <PRE> |
| … | … | |
| 76 | 74 | int opApply (int delegate (inout K key, inout V value) dg); |
|---|
| 77 | 75 | } |
|---|
| 78 | 76 | |
|---|
| | 77 | |
|---|
| | 78 | public 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 |
|
| 15 | 15 | module tango.util.collection.model.Dispenser; |
|---|
| 16 | 16 | |
|---|
| 17 | 17 | private import tango.util.collection.model.View, |
|---|
| | 18 | tango.util.collection.model.GuardIterator, |
|---|
| 18 | 19 | tango.util.collection.model.Iterator; |
|---|
| 19 | 20 | |
|---|
| 20 | 21 | /** |
| … | … | |
| 158 | 159 | **/ |
|---|
| 159 | 160 | |
|---|
| 160 | 161 | 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(); |
|---|
| 161 | 167 | } |
|---|
| 162 | 168 | |
|---|
| 163 | 169 | |
-
impl/AbstractIterator.d
| old |
new |
|
| 17 | 17 | |
|---|
| 18 | 18 | private import tango.core.Exception; |
|---|
| 19 | 19 | |
|---|
| 20 | | private import tango.util.collection.model.View, |
|---|
| | 20 | private import tango.util.collection.model.Dispenser, |
|---|
| 21 | 21 | tango.util.collection.model.GuardIterator; |
|---|
| 22 | 22 | |
|---|
| 23 | 23 | |
| … | … | |
| 32 | 32 | * <P> For an introduction to this package see <A HREF="index.html"> Overview </A>. |
|---|
| 33 | 33 | **/ |
|---|
| 34 | 34 | |
|---|
| 35 | | public abstract class AbstractIterator(T) : GuardIterator!(T) |
|---|
| | 35 | public abstract class AbstractIterator(T) : DispensableIterator!(T) |
|---|
| 36 | 36 | { |
|---|
| 37 | 37 | /** |
|---|
| 38 | 38 | * The collection being enumerated |
|---|
| 39 | 39 | **/ |
|---|
| 40 | 40 | |
|---|
| 41 | | private View!(T) view; |
|---|
| | 41 | protected Dispenser!(T) dispenser; |
|---|
| 42 | 42 | |
|---|
| 43 | 43 | /** |
|---|
| 44 | 44 | * The version number of the collection we got upon construction |
| … | … | |
| 48 | 48 | |
|---|
| 49 | 49 | /** |
|---|
| 50 | 50 | * The number of elements we think we have left. |
|---|
| 51 | | * Initialized to view.size() upon construction |
|---|
| | 51 | * Initialized to dispenser.size() upon construction |
|---|
| 52 | 52 | **/ |
|---|
| 53 | 53 | |
|---|
| 54 | 54 | private uint togo; |
|---|
| 55 | 55 | |
|---|
| 56 | 56 | |
|---|
| 57 | | protected this (View!(T) v) |
|---|
| | 57 | protected this (Dispenser!(T) d) |
|---|
| 58 | 58 | { |
|---|
| 59 | | view = v; |
|---|
| 60 | | togo = v.size(); |
|---|
| 61 | | mutation = v.mutation(); |
|---|
| | 59 | dispenser = d; |
|---|
| | 60 | togo = d.size(); |
|---|
| | 61 | mutation = d.mutation(); |
|---|
| 62 | 62 | } |
|---|
| 63 | 63 | |
|---|
| 64 | 64 | /** |
| … | … | |
| 67 | 67 | * See_Also: tango.util.collection.impl.Collection.CollectionIterator.corrupted |
|---|
| 68 | 68 | **/ |
|---|
| 69 | 69 | |
|---|
| 70 | | public final bool corrupted() |
|---|
| | 70 | final public bool corrupted() |
|---|
| 71 | 71 | { |
|---|
| 72 | | return mutation != view.mutation; |
|---|
| | 72 | return mutation != dispenser.mutation; |
|---|
| 73 | 73 | } |
|---|
| 74 | 74 | |
|---|
| 75 | 75 | /** |
| … | … | |
| 86 | 86 | * Return true if remaining > 0 and not corrupted |
|---|
| 87 | 87 | * See_Also: tango.util.collection.model.Iterator.more |
|---|
| 88 | 88 | **/ |
|---|
| 89 | | public final bool more() |
|---|
| | 89 | public bool more() |
|---|
| 90 | 90 | { |
|---|
| 91 | | return togo > 0 && mutation is view.mutation; |
|---|
| | 91 | return togo > 0 && !corrupted(); |
|---|
| 92 | 92 | } |
|---|
| 93 | 93 | |
|---|
| 94 | 94 | /** |
|---|
| | 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 | /** |
|---|
| 95 | 104 | * Subclass utility. |
|---|
| 96 | 105 | * Tries to decrement togo, raising exceptions |
|---|
| 97 | | * if it is already zero or if corrupted() |
|---|
| | 106 | * if it is already zero or if invalid() |
|---|
| 98 | 107 | * Always call as the first line of get. |
|---|
| 99 | 108 | **/ |
|---|
| 100 | 109 | protected final void decRemaining() |
|---|
| 101 | 110 | { |
|---|
| 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) |
|---|
| 106 | 113 | throw new NoSuchElementException ("exhausted enumeration"); |
|---|
| 107 | 114 | |
|---|
| 108 | 115 | --togo; |
|---|
| 109 | 116 | } |
|---|
| | 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 | } |
|---|
| 110 | 129 | } |
|---|
| 111 | 130 | |
|---|
| 112 | 131 | |
| … | … | |
| 114 | 133 | { |
|---|
| 115 | 134 | abstract V get (inout K key); |
|---|
| 116 | 135 | |
|---|
| 117 | | protected this (View!(V) c) |
|---|
| | 136 | protected this (Dispenser!(V) c) |
|---|
| 118 | 137 | { |
|---|
| 119 | 138 | super (c); |
|---|
| 120 | 139 | } |
-
impl/Collection.d
| old |
new |
|
| 22 | 22 | |
|---|
| 23 | 23 | private import tango.util.collection.model.View, |
|---|
| 24 | 24 | tango.util.collection.model.Iterator, |
|---|
| | 25 | tango.util.collection.model.GuardIterator, |
|---|
| 25 | 26 | tango.util.collection.model.Dispenser; |
|---|
| 26 | 27 | |
|---|
| 27 | 28 | /******************************************************************************* |
| … | … | |
| 626 | 627 | ************************************************************************/ |
|---|
| 627 | 628 | |
|---|
| 628 | 629 | 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 | } |
|---|
| 629 | 640 | } |
|---|
| 630 | 641 | |
|---|
| 631 | 642 | |
-
HashSet.d
| old |
new |
|
| 42 | 42 | |
|---|
| 43 | 43 | alias SetCollection!(T).remove remove; |
|---|
| 44 | 44 | alias SetCollection!(T).removeAll removeAll; |
|---|
| | 45 | alias SetCollection!(T).add add; |
|---|
| 45 | 46 | |
|---|
| 46 | 47 | |
|---|
| 47 | 48 | // instance variables |
| … | … | |
| 212 | 213 | * Time complexity: O(1). |
|---|
| 213 | 214 | * See_Also: tango.util.collection.impl.Collection.Collection.elements |
|---|
| 214 | 215 | **/ |
|---|
| 215 | | public final GuardIterator!(T) elements() |
|---|
| | 216 | public final DispensableIterator!(T) dispensableElements() |
|---|
| 216 | 217 | { |
|---|
| 217 | 218 | return new CellIterator!(T)(this); |
|---|
| 218 | 219 | } |
| … | … | |
| 273 | 274 | trail = n; |
|---|
| 274 | 275 | } |
|---|
| 275 | 276 | else |
|---|
| 276 | | trail.next(n); |
|---|
| | 277 | trail.unlinkNext(); |
|---|
| 277 | 278 | return ; |
|---|
| 278 | 279 | } |
|---|
| 279 | 280 | else |
| … | … | |
| 361 | 362 | // Helper methods |
|---|
| 362 | 363 | |
|---|
| 363 | 364 | /** |
|---|
| | 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 | /** |
|---|
| 364 | 378 | * Check to see if we are past load factor threshold. If so, resize |
|---|
| 365 | 379 | * so that we are at half of the desired threshold. |
|---|
| 366 | 380 | * Also while at it, check to see if we are empty so can just |
| … | … | |
| 515 | 529 | { |
|---|
| 516 | 530 | private int row; |
|---|
| 517 | 531 | private LLCellT cell; |
|---|
| | 532 | private LLCellT prev; |
|---|
| | 533 | private bool cellRemoved; |
|---|
| 518 | 534 | private LLCellT[] table; |
|---|
| 519 | 535 | |
|---|
| 520 | 536 | public this (HashSet set) |
|---|
| 521 | 537 | { |
|---|
| 522 | 538 | super (set); |
|---|
| 523 | 539 | table = set.table; |
|---|
| | 540 | cellRemoved = true; |
|---|
| 524 | 541 | } |
|---|
| 525 | 542 | |
|---|
| 526 | 543 | public final T get() |
|---|
| 527 | 544 | { |
|---|
| 528 | 545 | decRemaining(); |
|---|
| 529 | | |
|---|
| | 546 | if(cell) |
|---|
| | 547 | { |
|---|
| | 548 | prev = cell; |
|---|
| | 549 | cell = cell.next(); |
|---|
| | 550 | } |
|---|
| 530 | 551 | while (cell is null) |
|---|
| 531 | | cell = table [row++]; |
|---|
| | 552 | { |
|---|
| | 553 | prev = null; |
|---|
| | 554 | cell = table [row++]; |
|---|
| | 555 | } |
|---|
| 532 | 556 | |
|---|
| | 557 | cellRemoved = false; |
|---|
| 533 | 558 | auto v = cell.element(); |
|---|
| 534 | | cell = cell.next(); |
|---|
| 535 | 559 | return v; |
|---|
| 536 | 560 | } |
|---|
| 537 | 561 | |
| … | … | |
| 547 | 571 | } |
|---|
| 548 | 572 | return result; |
|---|
| 549 | 573 | } |
|---|
| | 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 | } |
|---|
| 550 | 588 | } |
|---|
| 551 | 589 | } |
|---|
| 552 | 590 | |
-
HashMap.d
| old |
new |
|
| 255 | 255 | |
|---|
| 256 | 256 | ************************************************************************/ |
|---|
| 257 | 257 | |
|---|
| 258 | | public final GuardIterator!(V) elements() |
|---|
| | 258 | public final DispensableIterator!(V) dispensableElements() |
|---|
| 259 | 259 | { |
|---|
| 260 | | return keys(); |
|---|
| | 260 | return new MapIterator!(K, V)(this); |
|---|
| 261 | 261 | } |
|---|
| 262 | 262 | |
|---|
| 263 | 263 | /*********************************************************************** |
| … | … | |
| 767 | 767 | } |
|---|
| 768 | 768 | } |
|---|
| 769 | 769 | |
|---|
| | 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 | |
|---|
| 770 | 783 | /*********************************************************************** |
|---|
| 771 | 784 | |
|---|
| 772 | 785 | ************************************************************************/ |
| … | … | |
| 890 | 903 | { |
|---|
| 891 | 904 | private int row; |
|---|
| 892 | 905 | private LLPairT pair; |
|---|
| | 906 | private LLPairT prev; |
|---|
| | 907 | private bool pairRemoved; |
|---|
| 893 | 908 | private LLPairT[] table; |
|---|
| 894 | 909 | |
|---|
| 895 | 910 | public this (HashMap map) |
|---|
| 896 | 911 | { |
|---|
| 897 | 912 | super (map); |
|---|
| 898 | 913 | table = map.table; |
|---|
| | 914 | pairRemoved = true; |
|---|
| 899 | 915 | } |
|---|
| 900 | 916 | |
|---|
| 901 | 917 | public final V get(inout K key) |
| … | … | |
| 908 | 924 | public final V get() |
|---|
| 909 | 925 | { |
|---|
| 910 | 926 | decRemaining(); |
|---|
| 911 | | |
|---|
| 912 | 927 | if (pair) |
|---|
| 913 | | pair = cast(LLPairT) pair.next(); |
|---|
| | 928 | { |
|---|
| | 929 | prev = pair; |
|---|
| | 930 | pair = cast(LLPairT) pair.next(); |
|---|
| | 931 | } |
|---|
| 914 | 932 | |
|---|
| 915 | 933 | while (pair is null) |
|---|
| 916 | | pair = table [row++]; |
|---|
| | 934 | { |
|---|
| | 935 | prev = null; |
|---|
| | 936 | pair = table [row++]; |
|---|
| | 937 | } |
|---|
| 917 | 938 | |
|---|
| | 939 | pairRemoved = false; |
|---|
| 918 | 940 | return pair.element(); |
|---|
| 919 | 941 | } |
|---|
| 920 | 942 | |
| … | … | |
| 944 | 966 | } |
|---|
| 945 | 967 | return result; |
|---|
| 946 | 968 | } |
|---|
| | 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 | } |
|---|
| 947 | 983 | } |
|---|
| 948 | 984 | } |
|---|
| 949 | 985 | |
-
LinkSeq.d
| old |
new |
|
| 129 | 129 | * Time complexity: O(1). |
|---|
| 130 | 130 | * See_Also: tango.util.collection.impl.Collection.Collection.elements |
|---|
| 131 | 131 | **/ |
|---|
| 132 | | public final GuardIterator!(T) elements() |
|---|
| | 132 | public final DispensableIterator!(T) dispensableElements() |
|---|
| 133 | 133 | { |
|---|
| 134 | 134 | return new CellIterator!(T)(this); |
|---|
| 135 | 135 | } |
| … | … | |
| 601 | 601 | trail = n; |
|---|
| 602 | 602 | } |
|---|
| 603 | 603 | else |
|---|
| 604 | | trail.next(n); |
|---|
| | 604 | trail.unlinkNext(); |
|---|
| 605 | 605 | |
|---|
| 606 | 606 | if (!allOccurrences || count is 0) |
|---|
| 607 | 607 | return ; |
| … | … | |
| 616 | 616 | } |
|---|
| 617 | 617 | } |
|---|
| 618 | 618 | |
|---|
| | 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 | } |
|---|
| 619 | 627 | |
|---|
| 620 | 628 | /** |
|---|
| 621 | 629 | * Helper for replace |
| … | … | |
| 710 | 718 | private static class CellIterator(T) : AbstractIterator!(T) |
|---|
| 711 | 719 | { |
|---|
| 712 | 720 | private LLCellT cell; |
|---|
| | 721 | private LLCellT prev; |
|---|
| | 722 | private LLCellT trail; |
|---|
| 713 | 723 | |
|---|
| 714 | 724 | public this (LinkSeq seq) |
|---|
| 715 | 725 | { |
| … | … | |
| 721 | 731 | { |
|---|
| 722 | 732 | decRemaining(); |
|---|
| 723 | 733 | auto v = cell.element(); |
|---|
| | 734 | if(prev) |
|---|
| | 735 | trail = prev; |
|---|
| | 736 | prev = cell; |
|---|
| 724 | 737 | cell = cell.next(); |
|---|
| 725 | 738 | return v; |
|---|
| 726 | 739 | } |
| … | … | |
| 737 | 750 | } |
|---|
| 738 | 751 | return result; |
|---|
| 739 | 752 | } |
|---|
| | 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 | } |
|---|
| 740 | 763 | } |
|---|
| 741 | 764 | } |
|---|
| 742 | 765 | |
-
iterator/ArrayIterator.d
| old |
new |
|
| 34 | 34 | { |
|---|
| 35 | 35 | private T [] arr_; |
|---|
| 36 | 36 | private int cur_; |
|---|
| 37 | | private int size_; |
|---|
| 38 | 37 | |
|---|
| 39 | 38 | /** |
|---|
| 40 | 39 | * Build an enumeration that returns successive elements of the array |
| … | … | |
| 43 | 42 | { |
|---|
| 44 | 43 | // arr_ = arr; cur_ = 0; size_ = arr._length; |
|---|
| 45 | 44 | arr_ = arr; |
|---|
| 46 | | cur_ = -1; |
|---|
| 47 | | size_ = arr.length; |
|---|
| | 45 | cur_ = 0; |
|---|
| 48 | 46 | } |
|---|
| 49 | 47 | |
|---|
| | 48 | public bool corrupted() |
|---|
| | 49 | { |
|---|
| | 50 | // |
|---|
| | 51 | // no way of knowing |
|---|
| | 52 | // |
|---|
| | 53 | return false; |
|---|
| | 54 | } |
|---|
| | 55 | |
|---|
| 50 | 56 | /** |
|---|
| 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. |
|---|
| 53 | 60 | **/ |
|---|
| 54 | 61 | public uint remaining() |
|---|
| 55 | 62 | { |
|---|
| 56 | | return size_; |
|---|
| | 63 | return arr_.length - cur_; |
|---|
| 57 | 64 | } |
|---|
| 58 | 65 | |
|---|
| 59 | 66 | /** |
| … | … | |
| 62 | 69 | **/ |
|---|
| 63 | 70 | public bool more() |
|---|
| 64 | 71 | { |
|---|
| 65 | | return size_ > 0; |
|---|
| | 72 | return cur_ < arr_.length; |
|---|
| 66 | 73 | } |
|---|
| 67 | 74 | |
|---|
| 68 | 75 | /** |
|---|
| 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 | | /** |
|---|
| 81 | 76 | * Implements tango.util.collection.model.Iterator.get(). |
|---|
| 82 | 77 | * See_Also: tango.util.collection.model.Iterator.get() |
|---|
| 83 | 78 | **/ |
|---|
| 84 | 79 | public T get() |
|---|
| 85 | 80 | { |
|---|
| 86 | | if (size_ > 0) |
|---|
| | 81 | if (more) |
|---|
| 87 | 82 | { |
|---|
| 88 | | --size_; |
|---|
| 89 | | ++cur_; |
|---|
| 90 | | return arr_[cur_]; |
|---|
| | 83 | return arr_[cur_++]; |
|---|
| 91 | 84 | } |
|---|
| 92 | 85 | throw new NoSuchElementException ("Exhausted Iterator"); |
|---|
| 93 | 86 | } |
| … | … | |
| 97 | 90 | { |
|---|
| 98 | 91 | int result; |
|---|
| 99 | 92 | |
|---|
| 100 | | for (auto i=size_; i--;) |
|---|
| | 93 | while (more) |
|---|
| 101 | 94 | { |
|---|
| 102 | 95 | auto value = get(); |
|---|
| 103 | 96 | if ((result = dg(value)) != 0) |
-
ArraySeq.d
| old |
new |
|
| 23 | 23 | private import tango.util.collection.impl.SeqCollection, |
|---|
| 24 | 24 | tango.util.collection.impl.AbstractIterator; |
|---|
| 25 | 25 | |
|---|
| | 26 | private import tango.core.Exception; |
|---|
| 26 | 27 | |
|---|
| | 28 | |
|---|
| 27 | 29 | /** |
|---|
| 28 | 30 | * |
|---|
| 29 | 31 | * Dynamically allocated and resized Arrays. |
| … | … | |
| 212 | 214 | } |
|---|
| 213 | 215 | |
|---|
| 214 | 216 | /** |
|---|
| 215 | | * Implements tango.util.collection.impl.Collection.Collection.elements |
|---|
| | 217 | * Implements tango.util.collection.model.Dispenser.Dispenser.dispensableElements |
|---|
| 216 | 218 | * Time complexity: O(1). |
|---|
| 217 | | * See_Also: tango.util.collection.impl.Collection.Collection.elements |
|---|
| | 219 | * See_Also: tango.util.collection.model.Dispenser.Dispenser.dispensableElements |
|---|
| 218 | 220 | **/ |
|---|
| 219 | | public final GuardIterator!(T) elements() |
|---|
| | 221 | public final DispensableIterator!(T) dispensableElements() |
|---|
| 220 | 222 | { |
|---|
| 221 | 223 | return new ArrayIterator!(T)(this); |
|---|
| 222 | 224 | } |
| … | … | |
| 864 | 866 | static class ArrayIterator(T) : AbstractIterator!(T) |
|---|
| 865 | 867 | { |
|---|
| 866 | 868 | private int row; |
|---|
| 867 | | private T[] array; |
|---|
| | 869 | ArraySeq array; |
|---|
| | 870 | bool prevRemoved; |
|---|
| 868 | 871 | |
|---|
| 869 | 872 | public this (ArraySeq seq) |
|---|
| 870 | 873 | { |
|---|
| 871 | 874 | super (seq); |
|---|
| 872 | | array = seq.array; |
|---|
| | 875 | this.array = seq; |
|---|
| | 876 | prevRemoved = true; |
|---|
| 873 | 877 | } |
|---|
| 874 | 878 | |
|---|
| 875 | 879 | public final T get() |
|---|
| 876 | 880 | { |
|---|
| 877 | 881 | decRemaining(); |
|---|
| | 882 | prevRemoved = false; |
|---|
| 878 | 883 | return array[row++]; |
|---|
| 879 | 884 | } |
|---|
| 880 | 885 | |
| … | … | |
| 890 | 895 | } |
|---|
| 891 | 896 | return result; |
|---|
| 892 | 897 | } |
|---|
| | 898 | |
|---|
| | 899 | public final void remove() |
|---|
| | 900 | { |
|---|
| | 901 | checkCorrupted(); |
|---|
| | 902 | if(prevRemoved) |
|---|
| | 903 | removeError(); |
|---|
| | 904 | prevRemoved = true; |
|---|
| | 905 | array.removeAt(--row); |
|---|
| | 906 | updateMutation(); |
|---|
| | 907 | } |
|---|
| 893 | 908 | } |
|---|
| | 909 | |
|---|
| 894 | 910 | } |
|---|
| 895 | 911 | |
|---|
| 896 | 912 | |
-
ArrayBag.d
| old |
new |
|
| 57 | 57 | |
|---|
| 58 | 58 | alias BagCollection!(T).remove remove; |
|---|
| 59 | 59 | alias BagCollection!(T).removeAll removeAll; |
|---|
| | 60 | alias BagCollection!(T).add add; |
|---|
| 60 | 61 | |
|---|
| 61 | 62 | /** |
|---|
| 62 | 63 | * The default chunk size to use for buffers |
| … | … | |
| 255 | 256 | * Time complexity: O(1). |
|---|
| 256 | 257 | * See_Also: tango.util.collection.impl.Collection.Collection.elements |
|---|
| 257 | 258 | **/ |
|---|
| 258 | | public final GuardIterator!(T) elements() |
|---|
| | 259 | public final DispensableIterator!(T) dispensableElements() |
|---|
| 259 | 260 | { |
|---|
| 260 | 261 | return new ArrayIterator!(T)(this); |
|---|
| 261 | 262 | } |
| … | … | |
| 432 | 433 | } |
|---|
| 433 | 434 | } |
|---|
| 434 | 435 | |
|---|
| | 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 | |
|---|
| 435 | 443 | private final void replace_(T oldElement, T newElement, bool allOccurrences) |
|---|
| 436 | 444 | { |
|---|
| 437 | 445 | if (!isValidArg(oldElement) || count is 0 || oldElement == (newElement)) |
| … | … | |
| 549 | 557 | { |
|---|
| 550 | 558 | private CLCellT cell; |
|---|
| 551 | 559 | private T[] buff; |
|---|
| | 560 | private bool prevRemoved; |
|---|
| 552 | 561 | private int index; |
|---|
| 553 | 562 | |
|---|
| 554 | 563 | public this (ArrayBag bag) |
| … | … | |
| 558 | 567 | |
|---|
| 559 | 568 | if (cell) |
|---|
| 560 | 569 | buff = cell.element(); |
|---|
| | 570 | prevRemoved = true; |
|---|
| 561 | 571 | } |
|---|
| 562 | 572 | |
|---|
| 563 | 573 | public final T get() |
| … | … | |
| 569 | 579 | buff = cell.element(); |
|---|
| 570 | 580 | index = 0; |
|---|
| 571 | 581 | } |
|---|
| | 582 | prevRemoved = false; |
|---|
| 572 | 583 | return buff[index++]; |
|---|
| 573 | 584 | } |
|---|
| 574 | 585 | |
| … | … | |
| 584 | 595 | } |
|---|
| 585 | 596 | return result; |
|---|
| 586 | 597 | } |
|---|
| | 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 | } |
|---|
| 587 | 621 | } |
|---|
| 588 | 622 | } |
|---|
| 589 | 623 | |
-
TreeBag.d
| old |
new |
|
| 37 | 37 | |
|---|
| 38 | 38 | alias BagCollection!(T).remove remove; |
|---|
| 39 | 39 | alias BagCollection!(T).removeAll removeAll; |
|---|
| | 40 | alias BagCollection!(T).add add; |
|---|
| 40 | 41 | |
|---|
| 41 | 42 | |
|---|
| 42 | 43 | // instance variables |
| … | … | |
| 151 | 152 | * Time complexity: O(1). |
|---|
| 152 | 153 | * See_Also: tango.util.collection.impl.Collection.Collection.elements |
|---|
| 153 | 154 | **/ |
|---|
| 154 | | public final GuardIterator!(T) elements() |
|---|
| | 155 | public final DispensableIterator!(T) dispensableElements() |
|---|
| 155 | 156 | { |
|---|
| 156 | 157 | return new CellIterator!(T)(this); |
|---|
| 157 | 158 | } |
| … | … | |
| 379 | 380 | } |
|---|
| 380 | 381 | } |
|---|
| 381 | 382 | |
|---|
| | 383 | private final void remove_(RBCellT node) |
|---|
| | 384 | { |
|---|
| | 385 | tree = node.remove(tree); |
|---|
| | 386 | decCount(); |
|---|
| | 387 | } |
|---|
| | 388 | |
|---|
| 382 | 389 | private final void replace_(T oldElement, T newElement, bool allOccurrences) |
|---|
| 383 | 390 | { |
|---|
| 384 | 391 | if (!isValidArg(oldElement) || count is 0 || oldElement == newElement) |
| … | … | |
| 3 |
|---|
|