Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1004)

Side by Side Diff: sdk/lib/_collection_dev/arrays.dart

Issue 107333003: Fix an old TODO. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/lib/growable_array.dart ('k') | sdk/lib/_collection_dev/collection_dev.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 // TODO(ngeoffray): Rename to Lists.
8 class Arrays {
9 static void copy(List src, int srcStart,
10 List dst, int dstStart, int count) {
11 if (srcStart < dstStart) {
12 for (int i = srcStart + count - 1, j = dstStart + count - 1;
13 i >= srcStart; i--, j--) {
14 dst[j] = src[i];
15 }
16 } else {
17 for (int i = srcStart, j = dstStart; i < srcStart + count; i++, j++) {
18 dst[j] = src[i];
19 }
20 }
21 }
22
23 static bool areEqual(List a, var b) {
24 if (identical(a, b)) return true;
25 if (!(b is List)) return false;
26 int length = a.length;
27 if (length != b.length) return false;
28
29 for (int i = 0; i < length; i++) {
30 if (!identical(a[i], b[i])) return false;
31 }
32 return true;
33 }
34
35 /**
36 * Returns the index in the list [a] of the given [element], starting
37 * the search at index [startIndex] to [endIndex] (exclusive).
38 * Returns -1 if [element] is not found.
39 */
40 static int indexOf(List a,
41 Object element,
42 int startIndex,
43 int endIndex) {
44 if (startIndex >= a.length) {
45 return -1;
46 }
47 if (startIndex < 0) {
48 startIndex = 0;
49 }
50 for (int i = startIndex; i < endIndex; i++) {
51 if (a[i] == element) {
52 return i;
53 }
54 }
55 return -1;
56 }
57
58 /**
59 * Returns the last index in the list [a] of the given [element], starting
60 * the search at index [startIndex] to 0.
61 * Returns -1 if [element] is not found.
62 */
63 static int lastIndexOf(List a, Object element, int startIndex) {
64 if (startIndex < 0) {
65 return -1;
66 }
67 if (startIndex >= a.length) {
68 startIndex = a.length - 1;
69 }
70 for (int i = startIndex; i >= 0; i--) {
71 if (a[i] == element) {
72 return i;
73 }
74 }
75 return -1;
76 }
77
78 static void indicesCheck(List a, int start, int end) {
79 if (start < 0 || start > a.length) {
80 throw new RangeError.range(start, 0, a.length);
81 }
82 if (end != null && (end < start || end > a.length)) {
83 throw new RangeError.range(end, start, a.length);
84 }
85 }
86
87 static void rangeCheck(List a, int start, int length) {
88 if (length < 0) {
89 throw new ArgumentError("negative length $length");
90 }
91 if (start < 0 ) {
92 String message = "$start must be greater than or equal to 0";
93 throw new RangeError(message);
94 }
95 if (start + length > a.length) {
96 String message = "$start + $length must be in the range [0..${a.length})";
97 throw new RangeError(message);
98 }
99 }
100 }
OLDNEW
« no previous file with comments | « runtime/lib/growable_array.dart ('k') | sdk/lib/_collection_dev/collection_dev.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698