OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of dart.collection; | 5 part of dart.collection; |
6 | 6 |
7 /** | 7 /** |
8 * Abstract implementation of a list. | 8 * Abstract implementation of a list. |
9 * | 9 * |
10 * All operations are defined in terms of `length`, `operator[]`, | 10 * All operations are defined in terms of `length`, `operator[]`, |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 } | 294 } |
295 | 295 |
296 void sort([int compare(E a, E b)]) { | 296 void sort([int compare(E a, E b)]) { |
297 if (compare == null) { | 297 if (compare == null) { |
298 var defaultCompare = Comparable.compare; | 298 var defaultCompare = Comparable.compare; |
299 compare = defaultCompare; | 299 compare = defaultCompare; |
300 } | 300 } |
301 Sort.sort(this, compare); | 301 Sort.sort(this, compare); |
302 } | 302 } |
303 | 303 |
304 void shuffle() { | |
305 Random random = new Random(); | |
rakudrama
2013/09/26 13:33:25
This needs to be an optional parameter to assist i
floitsch
2013/09/26 14:25:22
I don't think that the additional parameter is wor
| |
306 int length = this.length; | |
307 while (--length > 0) { | |
308 int pos = random.nextInt(length); | |
309 var tmp = this[length] | |
310 this[length] = this[pos]; | |
311 list[pos] = tmp; | |
312 } | |
313 } | |
314 | |
304 Map<int, E> asMap() { | 315 Map<int, E> asMap() { |
305 return new ListMapView(this); | 316 return new ListMapView(this); |
306 } | 317 } |
307 | 318 |
308 void _rangeCheck(int start, int end) { | 319 void _rangeCheck(int start, int end) { |
309 if (start < 0 || start > this.length) { | 320 if (start < 0 || start > this.length) { |
310 throw new RangeError.range(start, 0, this.length); | 321 throw new RangeError.range(start, 0, this.length); |
311 } | 322 } |
312 if (end < start || end > this.length) { | 323 if (end < start || end > this.length) { |
313 throw new RangeError.range(end, start, this.length); | 324 throw new RangeError.range(end, start, this.length); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
486 result.writeAll(this, ', '); | 497 result.writeAll(this, ', '); |
487 result.write(']'); | 498 result.write(']'); |
488 } finally { | 499 } finally { |
489 assert(identical(_toStringList.last, this)); | 500 assert(identical(_toStringList.last, this)); |
490 _toStringList.removeLast(); | 501 _toStringList.removeLast(); |
491 } | 502 } |
492 | 503 |
493 return result.toString(); | 504 return result.toString(); |
494 } | 505 } |
495 } | 506 } |
OLD | NEW |