comparison dwt/dwthelper/array.d @ 129:ad4e1fe71a5a

Fixed runtime errors
author Jacob Carlborg <doob@me.com>
date Sun, 18 Jan 2009 18:39:46 +0100
parents 38807a925e24
children 3d4579727e0e
comparison
equal deleted inserted replaced
128:07399639c0c8 129:ad4e1fe71a5a
23 * arr = the array to add the element to 23 * arr = the array to add the element to
24 * element = element to be appended to this list 24 * element = element to be appended to this list
25 * 25 *
26 * Returns: the modified array 26 * Returns: the modified array
27 * 27 *
28 * Throws: AssertException if the length of the array is 0
29 * Throws: AssertException if the element is null
30 */ 28 */
31 T[] add (T) (ref T[] arr, T element) 29 T[] add (T) (ref T[] arr, T element)
32 in
33 {
34 assert(arr.length > 0);
35 }
36 body
37 { 30 {
38 return arr ~= element; 31 return arr ~= element;
39 } 32 }
40 33
41 /** 34 /**
44 * Params: 37 * Params:
45 * arr = the array to add the element to 38 * arr = the array to add the element to
46 * element = element to be appended to this list 39 * element = element to be appended to this list
47 * 40 *
48 * Returns: the modified array 41 * Returns: the modified array
49 * 42 *
50 * Throws: AssertException if the length of the array is 0
51 * Throws: AssertException if the element is null
52 */ 43 */
53 alias add addElement; 44 alias add addElement;
54 45
55 /** 46 /**
56 * Gets the element at the specified index 47 * Gets the element at the specified index
62 * Returns: the element at the specified index 53 * Returns: the element at the specified index
63 */ 54 */
64 T elementAt (T) (T[] arr, int index) 55 T elementAt (T) (T[] arr, int index)
65 in 56 in
66 { 57 {
67 assert(arr.length > 0);
68 assert(index > -1 && index < arr.length); 58 assert(index > -1 && index < arr.length);
69 } 59 }
70 body 60 body
71 { 61 {
72 return arr[index]; 62 return arr[index];
105 * arr = the array to remove the element from 95 * arr = the array to remove the element from
106 * index = the index of the element to be removed 96 * index = the index of the element to be removed
107 * 97 *
108 * Returns: the element that was removed or $(D_CODE null) 98 * Returns: the element that was removed or $(D_CODE null)
109 * 99 *
110 * Throws: AssertException if the length of the array is 0
111 * Throws: AssertException if the $(D_CODE index) argument is 100 * Throws: AssertException if the $(D_CODE index) argument is
112 * negative or not less than the length of this array. 101 * negative or not less than the length of this array.
113 */ 102 */
114 T remove (T) (ref T[] arr, int index) 103 T remove (T) (ref T[] arr, int index)
115 in 104 in
116 { 105 {
117 assert(arr.length > 0);
118 assert(index > -1 && index < arr.length); 106 assert(index > -1 && index < arr.length);
119 } 107 }
120 body 108 body
121 { 109 {
122 T ret = arr[index]; 110 T ret = arr[index];
153 * Params: 141 * Params:
154 * arr = the array to remove the element from 142 * arr = the array to remove the element from
155 * element = the element to be removed 143 * element = the element to be removed
156 * 144 *
157 * Returns: the element that was removed or $(null null) 145 * Returns: the element that was removed or $(null null)
158 * 146 *
159 * Throws: AssertException if the length of the array is 0
160 */ 147 */
161 T remove (T) (ref T[] arr, T element) 148 T remove (T) (ref T[] arr, T element)
162 in
163 {
164 assert(arr.length > 0);
165 }
166 out (result) 149 out (result)
167 { 150 {
168 assert(result is element || result is null); 151 assert(result is element);
169 } 152 }
170 body 153 body
171 { 154 {
172 int index = arr.indexOf(element); 155 int index = arr.indexOf(element);
173 156
212 * element = the element to find 195 * element = the element to find
213 * start = the index of where to start searching from 196 * start = the index of where to start searching from
214 * 197 *
215 * Returns: the index of the element or -1 if it's not in the array 198 * Returns: the index of the element or -1 if it's not in the array
216 * 199 *
217 * Throws: AssertException if the length of the array is 0
218 * Throws: AssertException if the return value is less than -1 or 200 * Throws: AssertException if the return value is less than -1 or
219 * greater than the length of the array - 1. 201 * greater than the length of the array - 1.
220 */ 202 */
221 size_t indexOf (T, U = size_t) (T[] arr, T[] match, U start = 0) 203 size_t indexOf (T, U = size_t) (T[] arr, T[] match, U start = 0)
222 in 204 in
223 { 205 {
224 assert(arr.length > 0);
225 assert(start >= 0); 206 assert(start >= 0);
226 } 207 }
227 out (result) 208 out (result)
228 { 209 {
229 assert(result >= -1 && result < arr.length); 210 assert(result >= -1 && result < arr.length);
248 * element = the element to find 229 * element = the element to find
249 * start = the index of where to start searching from 230 * start = the index of where to start searching from
250 * 231 *
251 * Returns: the index of the element or -1 if it's not in the array 232 * Returns: the index of the element or -1 if it's not in the array
252 * 233 *
253 * Throws: AssertException if the length of the array is 0
254 * Throws: AssertException if the return value is less than -1 or 234 * Throws: AssertException if the return value is less than -1 or
255 * greater than the length of the array - 1. 235 * greater than the length of the array - 1.
256 */ 236 */
257 size_t indexOf (T, U = size_t) (T[] arr, T element, U start = 0) 237 size_t indexOf (T, U = size_t) (T[] arr, T element, U start = 0)
258 in 238 in
259 { 239 {
260 assert(arr.length > 0);
261 assert(start >= 0); 240 assert(start >= 0);
262 } 241 }
263 out (result) 242 out (result)
264 { 243 {
265 assert(result >= -1 && result < arr.length); 244 assert(result >= -1 && result < arr.length);