Mercurial > projects > dstep
annotate dstep/internal/collection/Array.d @ 16:19885b43130e
Huge update, the bridge actually works now
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sun, 03 Jan 2010 22:06:11 +0100 |
parents | 033d260cfc9b |
children |
rev | line source |
---|---|
1 | 1 /** |
2 * Copyright: Copyright (c) 2008-2009 Jacob Carlborg. | |
3 * Authors: Jacob Carlborg | |
4 * Version: Initial created: 2008 | |
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) | |
6 */ | |
7 module dstep.internal.collection.Array; | |
8 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
9 version (Tango) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
10 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
11 static import tango.core.Array; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
12 import tango.stdc.string : memmove; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
13 static import tango.text.Util; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
14 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
15 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
16 else |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
17 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
18 version = Phobos; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
19 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
20 import std.c.string : memmove; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
21 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
22 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
23 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
24 * Inserts the specified element at the specified position in the array. Shifts the |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
25 * element currently at that position (if any) and any subsequent elements to the right. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
26 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
27 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
28 * arr = the array to insert the element into |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
29 * index = the index at which the specified element is to be inserted |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
30 * element = the element to be inserted |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
31 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
32 * Returns: the modified array |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
33 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
34 * Throws: AssertException if the length of the array is 0 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
35 * Throws: AssertException if the $(D_PARAM index) argument is |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
36 * greater than the length of this array. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
37 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
38 T[] insert (T, U = size_t) (ref T[] arr, U index, T element) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
39 in |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
40 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
41 assert(arr.length > 0, "dstep.internal.collection.Array.insert: The length of the array was 0"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
42 assert(index <= arr.length, "dstep.internal.collection.Array.insert: The index was greater than the length of the array"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
43 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
44 body |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
45 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
46 if (index == arr.length) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
47 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
48 arr ~= element; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
49 return arr; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
50 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
51 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
52 else if (index == 0) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
53 arr = element ~ arr; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
54 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
55 else |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
56 arr = arr[0 .. index] ~ element ~ arr[index .. $]; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
57 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
58 return arr; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
59 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
60 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
61 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
62 * Inserts the specified elements at the specified position in the array. Shifts the |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
63 * element currently at that position (if any) and any subsequent elements to the right. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
64 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
65 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
66 * arr = the array to insert the element into |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
67 * index = the index at which the specified element is to be inserted |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
68 * element = the element to be inserted |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
69 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
70 * Returns: the modified array |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
71 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
72 * Throws: AssertException if the length of the array is 0 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
73 * Throws: AssertException if the $(D_PARAM index) argument is |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
74 * not less or equal than the length of this array. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
75 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
76 T[] insert (T, U = size_t) (ref T[] arr, U index, T[] element) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
77 in |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
78 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
79 assert(arr.length > 0, "dstep.internal.collection.Array.insert: The length of the array was 0"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
80 assert(index <= arr.length, "dstep.internal.collection.Array.insert: The index was greater than the length of the array"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
81 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
82 body |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
83 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
84 if (index == arr.length) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
85 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
86 arr ~= element; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
87 return arr; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
88 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
89 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
90 else if (index == 0) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
91 arr = element ~ arr; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
92 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
93 else |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
94 arr = arr[0 .. index] ~ element ~ arr[index .. $]; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
95 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
96 return arr; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
97 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
98 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
99 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
100 * Inserts the specified element at the specified position in the array. Shifts the |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
101 * element currently at that position (if any) and any subsequent elements to the right. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
102 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
103 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
104 * arr = the array to add the element to |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
105 * index = the index at which the specified element is to be inserted |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
106 * element = the element to be inserted |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
107 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
108 * Returns: the modified array |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
109 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
110 * Throws: AssertException if the length of the array is 0 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
111 * Throws: AssertException if the $(D_PARAM index) argument is |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
112 * not less than the length of this array. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
113 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
114 T[] add (T, U = size_t) (ref T[] arr, U index, T element) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
115 in |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
116 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
117 assert(arr.length > 0, "dstep.internal.collection.Array.add: The length of the array was 0"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
118 assert(index <= arr.length, "dstep.internal.collection.Array.add: The index was greater than the length of the array"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
119 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
120 body |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
121 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
122 return insert(arr, index, element); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
123 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
124 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
125 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
126 * Appends the specified element to the end of the array. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
127 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
128 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
129 * arr = the array to add the element to |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
130 * element = element to be appended to this list |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
131 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
132 * Returns: the modified array |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
133 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
134 T[] add (T) (ref T[] arr, T element) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
135 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
136 return arr ~= element; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
137 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
138 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
139 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
140 * Removes the element at the specified position in the array if it could find it and |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
141 * returns it. Shifts any subsequent elements to the left. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
142 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
143 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
144 * arr = the array to remove the element from |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
145 * index = the index of the element to be removed |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
146 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
147 * Returns: the element that was removed |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
148 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
149 * Throws: AssertException if the length of the array is 0 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
150 * Throws: AssertException if the $(D_PARAM index) argument is |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
151 * not less than the length of this array. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
152 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
153 T remove (T, U = size_t) (ref T[] arr, U index) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
154 in |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
155 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
156 assert(arr.length > 0, "dstep.internal.collection.Array.remove: The length of the array was 0"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
157 assert(index < arr.length, "dstep.internal.collection.Array.remove: The index was greater than the length of the array"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
158 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
159 body |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
160 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
161 T ret = arr[index]; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
162 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
163 if (index == 0) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
164 arr = arr[1 .. $]; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
165 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
166 else if (index == arr.length - 1) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
167 arr = arr[0 .. $ - 1]; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
168 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
169 else |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
170 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
171 if (index < arr.length - 1) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
172 memmove(&arr[index], &arr[index + 1], T.sizeof * (arr.length - index - 1)); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
173 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
174 arr.length = arr.length - 1; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
175 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
176 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
177 return ret; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
178 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
179 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
180 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
181 * Removes the specified element from the array if it could find it and returns it. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
182 * Shifts any subsequent elements to the left. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
183 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
184 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
185 * arr = the array to remove the element from |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
186 * element = the element to be removed |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
187 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
188 * Returns: the element that was removed or T.max |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
189 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
190 * Throws: AssertException if the length of the array is 0 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
191 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
192 T remove (T) (ref T[] arr, T element) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
193 in |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
194 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
195 assert(arr.length > 0, "dstep.internal.collection.Array.remove: The length of the array was 0"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
196 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
197 out (result) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
198 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
199 assert(result is element); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
200 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
201 body |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
202 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
203 size_t index = arr.indexOf(element); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
204 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
205 if (index == size_t.max) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
206 return T.max; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
207 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
208 return arr.remove(index); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
209 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
210 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
211 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
212 * Returns the index of the first occurrence of the specified element in the array, or |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
213 * U.max if the array does not contain the element. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
214 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
215 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
216 * arr = the array to get the index of the element from |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
217 * element = the element to find |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
218 * start = the index where to begin the search |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
219 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
220 * Returns: the index of the element or U.max if it's not in the array |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
221 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
222 * Throws: AssertException if the length of the array is 0 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
223 * Throws: AssertException if the return value is greater or |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
224 * equal to the length of the array. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
225 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
226 U indexOf (T, U = size_t) (T[] arr, T element, U start = 0) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
227 in |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
228 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
229 assert(arr.length > 0, "dstep.internal.collection.Array.indexOf: The length of the array was 0"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
230 assert(start >= 0, "dstep.internal.collection.Array.indexOf: The start index was less than 0"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
231 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
232 body |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
233 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
234 version (Tango) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
235 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
236 U index = tango.text.Util.locate(arr, element, start); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
237 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
238 if (index == arr.length) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
239 index = U.max; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
240 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
241 return index; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
242 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
243 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
244 else |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
245 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
246 if (start > arr.length) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
247 start = arr.length; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
248 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
249 for (U i = start; i < arr.length; i++) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
250 if (arr[i] == element) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
251 return i; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
252 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
253 return U.max; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
254 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
255 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
256 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
257 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
258 * Returns $(D_KEYWORD true) if the array contains the specified element. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
259 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
260 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
261 * arr = the array to check if it contains the element |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
262 * element = the element whose presence in the array is to be tested |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
263 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
264 * Returns: $(D_KEYWORD true) if the array contains the specified element |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
265 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
266 * Throws: AssertException if the length of the array is 0 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
267 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
268 bool contains (T) (T[] arr, T element) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
269 in |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
270 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
271 assert(arr.length > 0, "dstep.internal.collection.Array.contains: The length of the array was 0"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
272 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
273 body |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
274 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
275 return arr.indexOf!(T, size_t)(element) < size_t.max; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
276 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
277 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
278 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
279 * Returns $(D_KEYWORD true) if this array contains no elements. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
280 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
281 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
282 * arr = the array to check if it's empty |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
283 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
284 * Returns: $(D_KEYWORD true) if this array contains no elements |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
285 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
286 bool isEmpty (T) (T[] arr) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
287 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
288 return arr.length == 0; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
289 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
290 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
291 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
292 * Returns $(D_KEYWORD true) if this array contains no elements. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
293 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
294 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
295 * arr = the array to check if it's empty |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
296 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
297 * Returns: $(D_KEYWORD true) if this array contains no elements |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
298 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
299 alias isEmpty empty; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
300 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
301 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
302 * Removes all of the elements from this array. The array will be empty after this call |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
303 * returns. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
304 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
305 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
306 * arr = the array to clear |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
307 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
308 * Returns: the cleared array |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
309 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
310 * Throws: AssertException if length of the return array isn't 0 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
311 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
312 T[] clear (T) (T[] arr) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
313 out (result) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
314 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
315 assert(result.length == 0, "dstep.internal.collection.Array.clear: The length of the resulting array was not 0"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
316 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
317 body |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
318 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
319 return arr.length = 0; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
320 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
321 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
322 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
323 * Returns the element at the specified position in the array. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
324 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
325 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
326 * arr = the array to get the element from |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
327 * index = index of the element to return |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
328 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
329 * Returns: the element at the specified position in the array |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
330 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
331 * Throws: AssertException if the length of the array is 0 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
332 * Throws: AssertException if the $(D_PARAM index) argument is |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
333 * not less than the length of this array. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
334 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
335 T get (T, U = size_t) (T[] arr, U index) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
336 in |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
337 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
338 assert(arr.length > 0, "dstep.internal.collection.Array.get: The length of the array was 0"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
339 assert(index < arr.length, "dstep.internal.collection.Array.get: The index was greater than the length of the array"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
340 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
341 body |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
342 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
343 return arr[index]; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
344 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
345 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
346 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
347 * Returns the index of the last occurrence of the specifed element |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
348 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
349 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
350 * arr = the array to get the index of the element from |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
351 * element = the element to find the index of |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
352 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
353 * Returns: the index of the last occurrence of the element in the |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
354 * specified array, or U.max |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
355 * if the element does not occur. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
356 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
357 * Throws: AssertException if the length of the array is 0 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
358 * Throws: AssertException if the return value is less than -1 or |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
359 * greater than the length of the array - 1. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
360 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
361 U lastIndexOf (T, U = size_t) (T[] arr, T element) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
362 in |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
363 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
364 assert(arr.length > 0, "dstep.internal.collection.Array.lastIndexOf: The length of the array was 0"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
365 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
366 body |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
367 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
368 version (Tango) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
369 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
370 U index = tango.text.Util.locatePrior(arr, element); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
371 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
372 if (index == arr.length) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
373 return U.max; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
374 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
375 return index; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
376 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
377 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
378 else |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
379 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
380 foreach_reverse (i, e ; arr) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
381 if (e is element) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
382 return i; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
383 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
384 return U.max; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
385 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
386 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
387 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
388 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
389 * Returns the number of elements in the specified array. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
390 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
391 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
392 * arr = the array to get the number of elements from |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
393 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
394 * Returns: the number of elements in this list |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
395 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
396 U size (T, U = size_t) (T[] arr) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
397 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
398 return arr.length; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
399 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
400 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
401 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
402 * Finds the first occurence of element in arr |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
403 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
404 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
405 * arr = the array to find the element in |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
406 * element = the element to find |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
407 * start = at which position to start finding |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
408 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
409 * Returns: the index of the first match or U.max if no match was found. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
410 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
411 alias indexOf find; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
412 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
413 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
414 * Replaces a section of $(D_PARAM arr) with elements starting at $(D_PARAM pos) ending |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
415 * $(D_PARAM n) elements after |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
416 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
417 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
418 * arr = the array to do the replace in |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
419 * pos = position within the array of the first element of the section to be replaced |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
420 * n = length of the section to be replaced within the array |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
421 * elements = the elements to replace with |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
422 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
423 * Throws: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
424 * AssertException if pos is greater than the length of the array |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
425 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
426 * Returns: the array |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
427 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
428 T[] replace (T, U = size_t) (ref T[] arr, U pos, U n, T[] elements) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
429 in |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
430 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
431 assert(pos <= arr.length, "dstep.internal.collection.Array.replace: The position was greter than the length of the array"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
432 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
433 body |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
434 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
435 U i; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
436 U nr = n; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
437 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
438 if (nr > arr.length) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
439 nr = arr.length - 1; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
440 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
441 if (nr == elements.length) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
442 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
443 U eIndex; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
444 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
445 for (i = pos, eIndex = 0; i <= nr; i++, eIndex++) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
446 arr[i] = elements[eIndex]; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
447 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
448 return arr; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
449 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
450 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
451 else if (elements.length == 0) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
452 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
453 U index = pos + n; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
454 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
455 if (index >= arr.length) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
456 index = arr.length; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
457 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
458 return arr = arr[0 .. pos] ~ arr[index .. $]; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
459 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
460 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
461 else |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
462 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
463 U eIndex; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
464 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
465 for (i = pos, eIndex = 0; eIndex < nr && i < arr.length && eIndex < elements.length; i++, eIndex++) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
466 arr[i] = elements[eIndex]; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
467 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
468 // no positions left and elements are left in elements, insert elements |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
469 if (eIndex < elements.length) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
470 return arr = arr[0 .. i] ~ elements[eIndex .. $] ~ arr[i .. $]; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
471 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
472 // positions left to replace but no elements, remove those positions |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
473 else if (nr > eIndex) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
474 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
475 U index = pos + nr; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
476 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
477 if (index >= arr.length) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
478 index = arr.length; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
479 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
480 return arr = arr[0 .. pos + eIndex] ~ arr[index .. $]; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
481 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
482 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
483 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
484 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
485 return arr; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
486 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
487 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
488 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
489 * Erases a part of the array content, shortening the length of the array. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
490 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
491 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
492 * arr = the array to erase elements from |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
493 * start = the position within the array of the first element to be erased |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
494 * n = amount of elements to be removed. It may remove less elements if the |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
495 * end of the array is reached before the n elements have been erased. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
496 * The default value of n indicates that all the elements until the end |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
497 * of the array should be erased. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
498 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
499 * Throws: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
500 * AssertException if pos is greater than the length of the array |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
501 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
502 * Returns: the array |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
503 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
504 T[] erase (T, U = size_t) (ref T[] arr, U start = 0, U n = U.max) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
505 in |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
506 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
507 assert(start <= arr.length, "dstep.internal.collection.Array.erase: The start position was greater than the length of the array"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
508 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
509 body |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
510 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
511 U end; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
512 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
513 if (n == U.max) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
514 end = arr.length; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
515 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
516 else |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
517 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
518 end = start + n; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
519 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
520 if (end > arr.length) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
521 end = arr.length; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
522 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
523 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
524 return arr = arr[0 .. start] ~ arr[end .. $]; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
525 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
526 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
527 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
528 * Compares to arrays. Returns 0 if the content matches, less than zero |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
529 * if a is "less" than b, or greater than zero where a is "bigger". |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
530 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
531 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
532 * a = the first array |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
533 * b = the second array |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
534 * end = the index where the comparision will end |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
535 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
536 * Returns: Returns 0 if the content matches, less than zero if a is |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
537 * "less" than b, or greater than zero where a is "bigger". |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
538 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
539 int compare (T, U = size_t) (T[] a, T[] b, U end = U.max) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
540 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
541 U ia = end; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
542 U ib = end; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
543 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
544 if (ia > a.length) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
545 ia = a.length; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
546 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
547 if (ib > b.length) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
548 ib = b.length; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
549 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
550 return typeid(T[]).compare(&a[0 .. ia], &b[0 .. ib]); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
551 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
552 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
553 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
554 * Compares the content of the given array to the content of a comparing |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
555 * array, which is formed according to the arguments passed. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
556 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
557 * The function returns 0 if all the elements in the compared contents compare |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
558 * equal, a negative value if the first element that does not match compares to |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
559 * less in the array than in the comparing array, and a positive value in |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
560 * the opposite case. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
561 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
562 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
563 * a = the first array to compare with |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
564 * pos = position of the beginning of the compared slice, i.e. the first element in the array (in a) to be compared against the comparing array. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
565 * n = length of the compared slice. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
566 * b = array with the content to be used as comparing array. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
567 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
568 * Returns: 0 if the compared array are equal, otherwise a number different from 0 is returned, with its sign indicating whether the array is considered greater than the comparing array passed as parameter (positive sign), or smaller (negative sign). |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
569 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
570 * Throws: AssertException if pos is specified with a position greater than the length of the corresponding array |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
571 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
572 int compare (T, U = size_t) (T[] a, size_t pos, size_t n, T[] b) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
573 in |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
574 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
575 assert(pos <= b.length); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
576 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
577 body |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
578 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
579 U end = pos + n; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
580 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
581 if (end > b.length) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
582 end = b.length; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
583 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
584 return typeid(T[]).compare(&b[pos .. end], &a[0 .. $]); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
585 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
586 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
587 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
588 * Reserves the given amount of allocated storage for the given array. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
589 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
590 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
591 * a = the array to reserve allocated storage for |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
592 * capacity = the amount of allocated storage to be reserved |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
593 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
594 void reserve (T) (ref T[] a, size_t amount = 0) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
595 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
596 a = (new T[amount])[0 .. 0]; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
597 } |