1 // Written in the D programming language.
4 This module defines generic containers.
8 To implement the different containers both struct and class based
9 approaches have been used. $(REF make, std,_container,util) allows for
10 uniform construction with either approach.
14 // Construct a red-black tree and an array both containing the values 1, 2, 3.
15 // RedBlackTree should typically be allocated using `new`
16 RedBlackTree!int rbTree = new RedBlackTree!int(1, 2, 3);
17 // But `new` should not be used with Array
18 Array!int array = Array!int(1, 2, 3);
19 // `make` hides the differences
20 RedBlackTree!int rbTree2 = make!(RedBlackTree!int)(1, 2, 3);
21 Array!int array2 = make!(Array!int)(1, 2, 3);
24 Note that $(D make) can infer the element type from the given arguments.
28 auto rbTree = make!RedBlackTree(1, 2, 3); // RedBlackTree!int
29 auto array = make!Array("1", "2", "3"); // Array!string
34 All containers have reference semantics, which means that after
35 assignment both variables refer to the same underlying data.
37 To make a copy of a _container, use the $(D c._dup) _container primitive.
39 import std.container, std.range;
40 Array!int originalArray = make!(Array!int)(1, 2, 3);
41 Array!int secondArray = originalArray;
42 assert(equal(originalArray[], secondArray[]));
44 // changing one instance changes the other one as well!
45 originalArray[0] = 12;
46 assert(secondArray[0] == 12);
48 // secondArray now refers to an independent copy of originalArray
49 secondArray = originalArray.dup;
51 // assert that originalArray has not been affected
52 assert(originalArray[0] == 12);
55 $(B Attention:) If the _container is implemented as a class, using an
56 uninitialized instance can cause a null pointer dereference.
61 RedBlackTree!int rbTree;
62 rbTree.insert(5); // null pointer dereference
65 Using an uninitialized struct-based _container will work, because the struct
66 intializes itself upon use; however, up to this point the _container will not
67 have an identity and assignment does not create two references to the same
73 // create an uninitialized array
75 // array2 does _not_ refer to array1
76 Array!int array2 = array1;
77 array2.insertBack(42);
78 // thus array1 will not be affected
81 // after initialization reference semantics work as expected
83 // now affects array2 as well
87 It is therefore recommended to always construct containers using
88 $(REF make, std,_container,util).
90 This is in fact necessary to put containers into another _container.
91 For example, to construct an $(D Array) of ten empty $(D Array)s, use
92 the following that calls $(D make) ten times.
95 import std.container, std.range;
97 auto arrOfArrs = make!Array(generate!(() => make!(Array!int)).take(10));
102 This module consists of the following submodules:
106 The $(MREF std, _container, array) module provides
107 an array type with deterministic control of memory, not reliant on
108 the GC unlike built-in arrays.
111 The $(MREF std, _container, binaryheap) module
112 provides a binary heap implementation that can be applied to any
113 user-provided random-access range.
116 The $(MREF std, _container, dlist) module provides
117 a doubly-linked list implementation.
120 The $(MREF std, _container, rbtree) module
121 implements red-black trees.
124 The $(MREF std, _container, slist) module
125 implements singly-linked lists.
128 The $(MREF std, _container, util) module contains
129 some generic tools commonly used by _container implementations.
133 The_primary_range_of_a_container:
135 While some _containers offer direct access to their elements e.g. via
136 $(D opIndex), $(D c.front) or $(D c.back), access
137 and modification of a _container's contents is generally done through
138 its primary $(MREF_ALTTEXT range, std, range) type,
139 which is aliased as $(D C.Range). For example, the primary range type of
140 $(D Array!int) is $(D Array!int.Range).
142 If the documentation of a member function of a _container takes
143 a parameter of type $(D Range), then it refers to the primary range type of
144 this _container. Oftentimes $(D Take!Range) will be used, in which case
145 the range refers to a span of the elements in the _container. Arguments to
146 these parameters $(B must) be obtained from the same _container instance
147 as the one being worked with. It is important to note that many generic range
148 algorithms return the same range type as their input range.
151 import std.algorithm.comparison : equal;
152 import std.algorithm.iteration : find;
153 import std.container;
154 import std.range : take;
156 auto array = make!Array(1, 2, 3);
158 // `find` returns an Array!int.Range advanced to the element "2"
159 array.linearRemove(array[].find(2));
161 assert(array[].equal([1]));
163 array = make!Array(1, 2, 3);
165 // the range given to `linearRemove` is a Take!(Array!int.Range)
166 // spanning just the element "2"
167 array.linearRemove(array[].find(2).take(1));
169 assert(array[].equal([1, 3]));
172 When any $(MREF_ALTTEXT range, std, range) can be passed as an argument to
173 a member function, the documention usually refers to the parameter's templated
177 import std.algorithm.comparison : equal;
178 import std.container;
179 import std.range : iota;
181 auto array = make!Array(1, 2);
183 // the range type returned by `iota` is completely unrelated to Array,
184 // which is fine for Array.insertBack:
185 array.insertBack(iota(3, 10));
187 assert(array[].equal([1, 2, 3, 4, 5, 6, 7, 8, 9]));
190 Container_primitives:
192 Containers do not form a class hierarchy, instead they implement a
193 common set of primitives (see table below). These primitives each guarantee
194 a specific worst case complexity and thus allow generic code to be written
195 independently of the _container implementation.
197 For example the primitives $(D c.remove(r)) and $(D c.linearRemove(r)) both
198 remove the sequence of elements in range $(D r) from the _container $(D c).
199 The primitive $(D c.remove(r)) guarantees
200 $(BIGOH n$(SUBSCRIPT r) log n$(SUBSCRIPT c)) complexity in the worst case and
201 $(D c.linearRemove(r)) relaxes this guarantee to $(BIGOH n$(SUBSCRIPT c)).
203 Since a sequence of elements can be removed from a $(MREF_ALTTEXT doubly linked list,std,_container,dlist)
204 in constant time, $(D DList) provides the primitive $(D c.remove(r))
205 as well as $(D c.linearRemove(r)). On the other hand
206 $(MREF_ALTTEXT Array, std,_container, array) only offers $(D c.linearRemove(r)).
208 The following table describes the common set of primitives that containers
209 implement. A _container need not implement all primitives, but if a
210 primitive is implemented, it must support the syntax described in the $(B
211 syntax) column with the semantics described in the $(B description) column, and
212 it must not have a worst-case complexity worse than denoted in big-O notation in
213 the $(BIGOH ·) column. Below, $(D C) means a _container type, $(D c) is
214 a value of _container type, $(D n$(SUBSCRIPT x)) represents the effective length of
215 value $(D x), which could be a single element (in which case $(D n$(SUBSCRIPT x)) is
216 $(D 1)), a _container, or a range.
218 $(BOOKTABLE Container primitives,
221 $(TH $(BIGOH ·))
226 $(TDNW $(D n$(SUBSCRIPT x)))
227 $(TD Creates a _container of type $(D C) from either another _container or a range.
228 The created _container must not be a null reference even if x is empty.)
232 $(TDNW $(D n$(SUBSCRIPT c)))
233 $(TD Returns a duplicate of the _container.)
237 $(TDNW $(D n$(SUBSCRIPT c) + n$(SUBSCRIPT x)))
238 $(TD Returns the concatenation of $(D c) and $(D r). $(D x) may be a single
239 element or an input range.)
243 $(TDNW $(D n$(SUBSCRIPT c) + n$(SUBSCRIPT x)))
244 $(TD Returns the concatenation of $(D x) and $(D c). $(D x) may be a
245 single element or an input range type.)
247 $(LEADINGROWN 3, Iteration
252 $(TD The primary range type associated with the _container.)
256 $(TDNW $(D log n$(SUBSCRIPT c)))
258 iterating over the entire _container, in a _container-defined order.)
261 $(TDNW $(D c[a .. b]))
262 $(TDNW $(D log n$(SUBSCRIPT c)))
263 $(TD Fetches a portion of the _container from key $(D a) to key $(D b).)
265 $(LEADINGROWN 3, Capacity
270 $(TD Returns $(D true) if the _container has no elements, $(D false) otherwise.)
274 $(TDNW $(D log n$(SUBSCRIPT c)))
275 $(TD Returns the number of elements in the _container.)
278 $(TDNW $(D c.length = n))
279 $(TDNW $(D n$(SUBSCRIPT c) + n))
280 $(TD Forces the number of elements in the _container to $(D n).
281 If the _container ends up growing, the added elements are initialized
282 in a _container-dependent manner (usually with $(D T.init)).)
285 $(TD $(D c.capacity))
286 $(TDNW $(D log n$(SUBSCRIPT c)))
287 $(TD Returns the maximum number of elements that can be stored in the
288 _container without triggering a reallocation.)
291 $(TD $(D c.reserve(x)))
292 $(TD $(D n$(SUBSCRIPT c)))
293 $(TD Forces $(D capacity) to at least $(D x) without reducing it.)
295 $(LEADINGROWN 3, Access
299 $(TDNW $(D log n$(SUBSCRIPT c)))
300 $(TD Returns the first element of the _container, in a _container-defined order.)
303 $(TDNW $(D c.moveFront))
304 $(TDNW $(D log n$(SUBSCRIPT c)))
305 $(TD Destructively reads and returns the first element of the
306 _container. The slot is not removed from the _container; it is left
307 initialized with $(D T.init). This routine need not be defined if $(D
308 front) returns a $(D ref).)
311 $(TDNW $(D c.front = v))
312 $(TDNW $(D log n$(SUBSCRIPT c)))
313 $(TD Assigns $(D v) to the first element of the _container.)
317 $(TDNW $(D log n$(SUBSCRIPT c)))
318 $(TD Returns the last element of the _container, in a _container-defined order.)
321 $(TDNW $(D c.moveBack))
322 $(TDNW $(D log n$(SUBSCRIPT c)))
323 $(TD Destructively reads and returns the last element of the
324 _container. The slot is not removed from the _container; it is left
325 initialized with $(D T.init). This routine need not be defined if $(D
326 front) returns a $(D ref).)
329 $(TDNW $(D c.back = v))
330 $(TDNW $(D log n$(SUBSCRIPT c)))
331 $(TD Assigns $(D v) to the last element of the _container.)
335 $(TDNW $(D log n$(SUBSCRIPT c)))
336 $(TD Provides indexed access into the _container. The index type is
337 _container-defined. A _container may define several index types (and
338 consequently overloaded indexing).)
341 $(TDNW $(D c.moveAt(x)))
342 $(TDNW $(D log n$(SUBSCRIPT c)))
343 $(TD Destructively reads and returns the value at position $(D x). The slot
344 is not removed from the _container; it is left initialized with $(D
348 $(TDNW $(D c[x] = v))
349 $(TDNW $(D log n$(SUBSCRIPT c)))
350 $(TD Sets element at specified index into the _container.)
353 $(TDNW $(D c[x] $(I op)= v))
354 $(TDNW $(D log n$(SUBSCRIPT c)))
355 $(TD Performs read-modify-write operation at specified index into the
358 $(LEADINGROWN 3, Operations
362 $(TDNW $(D log n$(SUBSCRIPT c)))
363 $(TD Returns nonzero if e is found in $(D c).)
366 $(TDNW $(D c.lowerBound(v)))
367 $(TDNW $(D log n$(SUBSCRIPT c)))
368 $(TD Returns a range of all elements strictly less than $(D v).)
371 $(TDNW $(D c.upperBound(v)))
372 $(TDNW $(D log n$(SUBSCRIPT c)))
373 $(TD Returns a range of all elements strictly greater than $(D v).)
376 $(TDNW $(D c.equalRange(v)))
377 $(TDNW $(D log n$(SUBSCRIPT c)))
378 $(TD Returns a range of all elements in $(D c) that are equal to $(D v).)
380 $(LEADINGROWN 3, Modifiers
384 $(TDNW $(D n$(SUBSCRIPT c) + n$(SUBSCRIPT x)))
385 $(TD Appends $(D x) to $(D c). $(D x) may be a single element or an input range type.)
388 $(TDNW $(D c.clear()))
389 $(TDNW $(D n$(SUBSCRIPT c)))
390 $(TD Removes all elements in $(D c).)
393 $(TDNW $(D c.insert(x)))
394 $(TDNW $(D n$(SUBSCRIPT x) * log n$(SUBSCRIPT c)))
395 $(TD Inserts $(D x) in $(D c) at a position (or positions) chosen by $(D c).)
398 $(TDNW $(D c.stableInsert(x)))
399 $(TDNW $(D n$(SUBSCRIPT x) * log n$(SUBSCRIPT c)))
400 $(TD Same as $(D c.insert(x)), but is guaranteed to not invalidate any ranges.)
403 $(TDNW $(D c.linearInsert(v)))
404 $(TDNW $(D n$(SUBSCRIPT c)))
405 $(TD Same as $(D c.insert(v)) but relaxes complexity to linear.)
408 $(TDNW $(D c.stableLinearInsert(v)))
409 $(TDNW $(D n$(SUBSCRIPT c)))
410 $(TD Same as $(D c.stableInsert(v)) but relaxes complexity to linear.)
413 $(TDNW $(D c.removeAny()))
414 $(TDNW $(D log n$(SUBSCRIPT c)))
415 $(TD Removes some element from $(D c) and returns it.)
418 $(TDNW $(D c.stableRemoveAny()))
419 $(TDNW $(D log n$(SUBSCRIPT c)))
420 $(TD Same as $(D c.removeAny()), but is guaranteed to not invalidate any
424 $(TDNW $(D c.insertFront(v)))
425 $(TDNW $(D log n$(SUBSCRIPT c)))
426 $(TD Inserts $(D v) at the front of $(D c).)
429 $(TDNW $(D c.stableInsertFront(v)))
430 $(TDNW $(D log n$(SUBSCRIPT c)))
431 $(TD Same as $(D c.insertFront(v)), but guarantees no ranges will be
435 $(TDNW $(D c.insertBack(v)))
436 $(TDNW $(D log n$(SUBSCRIPT c)))
437 $(TD Inserts $(D v) at the back of $(D c).)
440 $(TDNW $(D c.stableInsertBack(v)))
441 $(TDNW $(D log n$(SUBSCRIPT c)))
442 $(TD Same as $(D c.insertBack(v)), but guarantees no ranges will be
446 $(TDNW $(D c.removeFront()))
447 $(TDNW $(D log n$(SUBSCRIPT c)))
448 $(TD Removes the element at the front of $(D c).)
451 $(TDNW $(D c.stableRemoveFront()))
452 $(TDNW $(D log n$(SUBSCRIPT c)))
453 $(TD Same as $(D c.removeFront()), but guarantees no ranges will be
457 $(TDNW $(D c.removeBack()))
458 $(TDNW $(D log n$(SUBSCRIPT c)))
459 $(TD Removes the value at the back of $(D c).)
462 $(TDNW $(D c.stableRemoveBack()))
463 $(TDNW $(D log n$(SUBSCRIPT c)))
464 $(TD Same as $(D c.removeBack()), but guarantees no ranges will be
468 $(TDNW $(D c.remove(r)))
469 $(TDNW $(D n$(SUBSCRIPT r) * log n$(SUBSCRIPT c)))
470 $(TD Removes range $(D r) from $(D c).)
473 $(TDNW $(D c.stableRemove(r)))
474 $(TDNW $(D n$(SUBSCRIPT r) * log n$(SUBSCRIPT c)))
475 $(TD Same as $(D c.remove(r)), but guarantees iterators are not
479 $(TDNW $(D c.linearRemove(r)))
480 $(TDNW $(D n$(SUBSCRIPT c)))
481 $(TD Removes range $(D r) from $(D c).)
484 $(TDNW $(D c.stableLinearRemove(r)))
485 $(TDNW $(D n$(SUBSCRIPT c)))
486 $(TD Same as $(D c.linearRemove(r)), but guarantees iterators are not
490 $(TDNW $(D c.removeKey(k)))
491 $(TDNW $(D log n$(SUBSCRIPT c)))
492 $(TD Removes an element from $(D c) by using its key $(D k).
493 The key's type is defined by the _container.)
502 Source: $(PHOBOSSRC std/_container/package.d)
504 Copyright: Red-black tree code copyright (C) 2008- by Steven Schveighoffer. Other code
505 copyright 2010- Andrei Alexandrescu. All rights reserved by the respective holders.
507 License: Distributed under the Boost Software License, Version 1.0.
508 (See accompanying file LICENSE_1_0.txt or copy at $(HTTP
509 boost.org/LICENSE_1_0.txt)).
511 Authors: Steven Schveighoffer, $(HTTP erdani.com, Andrei Alexandrescu)
514 module std.container;
516 public import std.container.array;
517 public import std.container.binaryheap;
518 public import std.container.dlist;
519 public import std.container.rbtree;
520 public import std.container.slist;
525 /* The following documentation and type $(D TotalContainer) are
526 intended for developers only.
528 $(D TotalContainer) is an unimplemented container that illustrates a
529 host of primitives that a container may define. It is to some extent
530 the bottom of the conceptual container hierarchy. A given container
531 most often will choose to only implement a subset of these primitives,
532 and define its own additional ones. Adhering to the standard primitive
533 names below allows generic code to work independently of containers.
535 Things to remember: any container must be a reference type, whether
536 implemented as a $(D class) or $(D struct). No primitive below
537 requires the container to escape addresses of elements, which means
538 that compliant containers can be defined to use reference counting or
539 other deterministic memory management techniques.
541 A container may choose to define additional specific operations. The
542 only requirement is that those operations bear different names than
543 the ones below, lest user code gets confused.
545 Complexity of operations should be interpreted as "at least as good
546 as". If an operation is required to have $(BIGOH n) complexity, it
547 could have anything lower than that, e.g. $(BIGOH log(n)). Unless
548 specified otherwise, $(D n) inside a $(BIGOH) expression stands for
549 the number of elements in the container.
551 struct TotalContainer(T)
554 If the container has a notion of key-value mapping, $(D KeyType)
555 defines the type of the key of the container.
560 If the container has a notion of multikey-value mapping, $(D
561 KeyTypes[k]), where $(D k) is a zero-based unsigned number, defines
562 the type of the $(D k)th key of the container.
564 A container may define both $(D KeyType) and $(D KeyTypes), e.g. in
565 the case it has the notion of primary/preferred key.
567 alias KeyTypes = AliasSeq!T;
570 If the container has a notion of key-value mapping, $(D ValueType)
571 defines the type of the value of the container. Typically, a map-style
572 container mapping values of type $(D K) to values of type $(D V)
573 defines $(D KeyType) to be $(D K) and $(D ValueType) to be $(D V).
578 Defines the container's primary range, which embodies one of the
579 ranges defined in $(MREF std,range).
581 Generally a container may define several types of ranges.
588 @property bool empty()
593 @property ref T front() //ref return optional
598 @property void front(T value) //Only when front does not return by ref
613 @property ref T back() //ref return optional
618 @property void back(T value) //Only when front does not return by ref
633 T opIndex(size_t i) //ref return optional
638 void opIndexAssign(size_t i, T value) //Only when front does not return by ref
643 T opIndexUnary(string op)(size_t i) //Only when front does not return by ref
648 void opIndexOpAssign(string op)(size_t i, T value) //Only when front does not return by ref
658 @property size_t length()
665 Property returning $(D true) if and only if the container has no
668 Complexity: $(BIGOH 1)
670 @property bool empty()
676 Returns a duplicate of the container. The elements themselves are not
677 transitively duplicated.
679 Complexity: $(BIGOH n).
681 @property TotalContainer dup()
687 Returns the number of elements in the container.
689 Complexity: $(BIGOH log(n)).
691 @property size_t length()
697 Returns the maximum number of elements the container can store without
698 (a) allocating memory, (b) invalidating iterators upon insertion.
700 Complexity: $(BIGOH log(n)).
702 @property size_t capacity()
708 Ensures sufficient capacity to accommodate $(D n) elements.
710 Postcondition: $(D capacity >= n)
712 Complexity: $(BIGOH log(e - capacity)) if $(D e > capacity), otherwise
715 void reserve(size_t e)
721 Returns a range that iterates over all elements of the container, in a
722 container-defined order. The container should choose the most
723 convenient and fast method of iteration for $(D opSlice()).
725 Complexity: $(BIGOH log(n))
733 Returns a range that iterates the container between two
736 Complexity: $(BIGOH log(n))
738 Range opSlice(size_t a, size_t b)
744 Forward to $(D opSlice().front) and $(D opSlice().back), respectively.
746 Complexity: $(BIGOH log(n))
748 @property ref T front() //ref return optional
753 @property void front(T value) //Only when front does not return by ref
763 @property ref T back() //ref return optional
768 @property void back(T value) //Only when front does not return by ref
779 Indexing operators yield or modify the value at a specified index.
781 ref T opIndex(KeyType) //ref return optional
786 void opIndexAssign(KeyType i, T value) //Only when front does not return by ref
791 T opIndexUnary(string op)(KeyType i) //Only when front does not return by ref
796 void opIndexOpAssign(string op)(KeyType i, T value) //Only when front does not return by ref
807 $(D k in container) returns true if the given key is in the container.
809 bool opBinaryRight(string op)(KeyType k) if (op == "in")
815 Returns a range of all elements containing $(D k) (could be empty or a
818 Range equalRange(KeyType k)
824 Returns a range of all elements with keys less than $(D k) (could be
825 empty or a singleton range). Only defined by containers that store
826 data sorted at all times.
828 Range lowerBound(KeyType k)
834 Returns a range of all elements with keys larger than $(D k) (could be
835 empty or a singleton range). Only defined by containers that store
836 data sorted at all times.
838 Range upperBound(KeyType k)
844 Returns a new container that's the concatenation of $(D this) and its
845 argument. $(D opBinaryRight) is only defined if $(D Stuff) does not
846 define $(D opBinary).
848 Complexity: $(BIGOH n + m), where m is the number of elements in $(D
851 TotalContainer opBinary(string op)(Stuff rhs) if (op == "~")
857 TotalContainer opBinaryRight(string op)(Stuff lhs) if (op == "~")
863 Forwards to $(D insertAfter(this[], stuff)).
865 void opOpAssign(string op)(Stuff stuff) if (op == "~")
871 Removes all contents from the container. The container decides how $(D
872 capacity) is affected.
874 Postcondition: $(D empty)
876 Complexity: $(BIGOH n)
884 Sets the number of elements in the container to $(D newSize). If $(D
885 newSize) is greater than $(D length), the added elements are added to
886 unspecified positions in the container and initialized with $(D
889 Complexity: $(BIGOH abs(n - newLength))
891 Postcondition: $(D _length == newLength)
893 @property void length(size_t newLength)
899 Inserts $(D stuff) in an unspecified position in the
900 container. Implementations should choose whichever insertion means is
901 the most advantageous for the container, but document the exact
902 behavior. $(D stuff) can be a value convertible to the element type of
903 the container, or a range of values convertible to it.
905 The $(D stable) version guarantees that ranges iterating over the
906 container are never invalidated. Client code that counts on
907 non-invalidating insertion should use $(D stableInsert). Such code would
908 not compile against containers that don't support it.
910 Returns: The number of elements added.
912 Complexity: $(BIGOH m * log(n)), where $(D m) is the number of
913 elements in $(D stuff)
915 size_t insert(Stuff)(Stuff stuff)
920 size_t stableInsert(Stuff)(Stuff stuff)
926 Same as $(D insert(stuff)) and $(D stableInsert(stuff)) respectively,
927 but relax the complexity constraint to linear.
929 size_t linearInsert(Stuff)(Stuff stuff)
934 size_t stableLinearInsert(Stuff)(Stuff stuff)
940 Picks one value in an unspecified position in the container, removes
941 it from the container, and returns it. Implementations should pick the
942 value that's the most advantageous for the container. The stable version
943 behaves the same, but guarantees that ranges iterating over the container
944 are never invalidated.
946 Precondition: $(D !empty)
948 Returns: The element removed.
950 Complexity: $(BIGOH log(n)).
963 Inserts $(D value) to the front or back of the container. $(D stuff)
964 can be a value convertible to the container's element type or a range
965 of values convertible to it. The stable version behaves the same, but
966 guarantees that ranges iterating over the container are never
969 Returns: The number of elements inserted
971 Complexity: $(BIGOH log(n)).
973 size_t insertFront(Stuff)(Stuff stuff)
978 size_t stableInsertFront(Stuff)(Stuff stuff)
983 size_t insertBack(Stuff)(Stuff stuff)
988 size_t stableInsertBack(T value)
994 Removes the value at the front or back of the container. The stable
995 version behaves the same, but guarantees that ranges iterating over
996 the container are never invalidated. The optional parameter $(D
997 howMany) instructs removal of that many elements. If $(D howMany > n),
998 all elements are removed and no exception is thrown.
1000 Precondition: $(D !empty)
1002 Complexity: $(BIGOH log(n)).
1009 void stableRemoveFront()
1019 void stableRemoveBack()
1025 Removes $(D howMany) values at the front or back of the
1026 container. Unlike the unparameterized versions above, these functions
1027 do not throw if they could not remove $(D howMany) elements. Instead,
1028 if $(D howMany > n), all elements are removed. The returned value is
1029 the effective number of elements removed. The stable version behaves
1030 the same, but guarantees that ranges iterating over the container are
1033 Returns: The number of elements removed
1035 Complexity: $(BIGOH howMany * log(n)).
1037 size_t removeFront(size_t howMany)
1042 size_t stableRemoveFront(size_t howMany)
1047 size_t removeBack(size_t howMany)
1052 size_t stableRemoveBack(size_t howMany)
1058 Removes all values corresponding to key $(D k).
1060 Complexity: $(BIGOH m * log(n)), where $(D m) is the number of
1061 elements with the same key.
1063 Returns: The number of elements removed.
1065 size_t removeKey(KeyType k)
1071 Inserts $(D stuff) before, after, or instead range $(D r), which must
1072 be a valid range previously extracted from this container. $(D stuff)
1073 can be a value convertible to the container's element type or a range
1074 of objects convertible to it. The stable version behaves the same, but
1075 guarantees that ranges iterating over the container are never
1078 Returns: The number of values inserted.
1080 Complexity: $(BIGOH n + m), where $(D m) is the length of $(D stuff)
1082 size_t insertBefore(Stuff)(Range r, Stuff stuff)
1087 size_t stableInsertBefore(Stuff)(Range r, Stuff stuff)
1092 size_t insertAfter(Stuff)(Range r, Stuff stuff)
1097 size_t stableInsertAfter(Stuff)(Range r, Stuff stuff)
1102 size_t replace(Stuff)(Range r, Stuff stuff)
1107 size_t stableReplace(Stuff)(Range r, Stuff stuff)
1113 Removes all elements belonging to $(D r), which must be a range
1114 obtained originally from this container. The stable version behaves the
1115 same, but guarantees that ranges iterating over the container are
1118 Returns: A range spanning the remaining elements in the container that
1119 initially were right after $(D r).
1121 Complexity: $(BIGOH m * log(n)), where $(D m) is the number of
1124 Range remove(Range r)
1129 Range stableRemove(Range r)
1135 Same as $(D remove) above, but has complexity relaxed to linear.
1137 Returns: A range spanning the remaining elements in the container that
1138 initially were right after $(D r).
1140 Complexity: $(BIGOH n)
1142 Range linearRemove(Range r)
1147 Range stableLinearRemove(Range r)
1155 TotalContainer!int test;