OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 part of dart._collection.dev; | |
6 | |
7 class Lists { | |
8 static void copy(List src, int srcStart, | |
9 List dst, int dstStart, int count) { | |
10 if (srcStart < dstStart) { | |
11 for (int i = srcStart + count - 1, j = dstStart + count - 1; | |
12 i >= srcStart; i--, j--) { | |
13 dst[j] = src[i]; | |
14 } | |
15 } else { | |
16 for (int i = srcStart, j = dstStart; i < srcStart + count; i++, j++) { | |
17 dst[j] = src[i]; | |
18 } | |
19 } | |
20 } | |
21 | |
22 static bool areEqual(List a, var b) { | |
23 if (identical(a, b)) return true; | |
24 if (!(b is List)) return false; | |
25 int length = a.length; | |
26 if (length != b.length) return false; | |
27 | |
28 for (int i = 0; i < length; i++) { | |
29 if (!identical(a[i], b[i])) return false; | |
30 } | |
31 return true; | |
32 } | |
33 | |
34 /** | |
35 * Returns the index in the list [a] of the given [element], starting | |
36 * the search at index [startIndex] to [endIndex] (exclusive). | |
37 * Returns -1 if [element] is not found. | |
38 */ | |
39 static int indexOf(List a, | |
40 Object element, | |
41 int startIndex, | |
42 int endIndex) { | |
43 if (startIndex >= a.length) { | |
44 return -1; | |
45 } | |
46 if (startIndex < 0) { | |
47 startIndex = 0; | |
48 } | |
49 for (int i = startIndex; i < endIndex; i++) { | |
50 if (a[i] == element) { | |
51 return i; | |
52 } | |
53 } | |
54 return -1; | |
55 } | |
56 | |
57 /** | |
58 * Returns the last index in the list [a] of the given [element], starting | |
59 * the search at index [startIndex] to 0. | |
60 * Returns -1 if [element] is not found. | |
61 */ | |
62 static int lastIndexOf(List a, Object element, int startIndex) { | |
63 if (startIndex < 0) { | |
64 return -1; | |
65 } | |
66 if (startIndex >= a.length) { | |
67 startIndex = a.length - 1; | |
68 } | |
69 for (int i = startIndex; i >= 0; i--) { | |
70 if (a[i] == element) { | |
71 return i; | |
72 } | |
73 } | |
74 return -1; | |
75 } | |
76 | |
77 static void indicesCheck(List a, int start, int end) { | |
78 if (start < 0 || start > a.length) { | |
79 throw new RangeError.range(start, 0, a.length); | |
80 } | |
81 if (end != null && (end < start || end > a.length)) { | |
82 throw new RangeError.range(end, start, a.length); | |
83 } | |
84 } | |
85 | |
86 static void rangeCheck(List a, int start, int length) { | |
87 if (length < 0) { | |
88 throw new ArgumentError("negative length $length"); | |
89 } | |
90 if (start < 0 ) { | |
91 String message = "$start must be greater than or equal to 0"; | |
92 throw new RangeError(message); | |
93 } | |
94 if (start + length > a.length) { | |
95 String message = "$start + $length must be in the range [0..${a.length})"; | |
96 throw new RangeError(message); | |
97 } | |
98 } | |
99 } | |
OLD | NEW |