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

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

Issue 25931003: Make List.shuffle take an optional Random object to use. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comment. Created 7 years, 2 months 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/typed_data.dart ('k') | sdk/lib/_collection_dev/list.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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.dev; 5 part of dart._collection.dev;
6 6
7 7
8 // This is a hack to make @deprecated work in dart:io. Don't remove or use this, 8 // This is a hack to make @deprecated work in dart:io. Don't remove or use this,
9 // unless coordinated with either me or the core library team. Thanks! 9 // unless coordinated with either me or the core library team. Thanks!
10 // TODO(ajohnsen): Remove at the 11th of August 2013. 10 // TODO(ajohnsen): Remove at the 11th of August 2013.
(...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 951
952 static Iterable reversedList(List list) { 952 static Iterable reversedList(List list) {
953 return new ReversedListIterable(list); 953 return new ReversedListIterable(list);
954 } 954 }
955 955
956 static void sortList(List list, int compare(a, b)) { 956 static void sortList(List list, int compare(a, b)) {
957 if (compare == null) compare = Comparable.compare; 957 if (compare == null) compare = Comparable.compare;
958 Sort.sort(list, compare); 958 Sort.sort(list, compare);
959 } 959 }
960 960
961 static void shuffleList(List list) { 961 static void shuffleList(List list, Random random) {
962 Random random = new Random(); 962 if (random == null) random = new Random();
963 int length = list.length; 963 int length = list.length;
964 while (length > 1) { 964 while (length > 1) {
965 int pos = random.nextInt(length); 965 int pos = random.nextInt(length);
966 length -= 1; 966 length -= 1;
967 var tmp = list[length]; 967 var tmp = list[length];
968 list[length] = list[pos]; 968 list[length] = list[pos];
969 list[pos] = tmp; 969 list[pos] = tmp;
970 } 970 }
971 } 971 }
972 972
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 1094
1095 static Set setDifference(Set set, Set other, Set result) { 1095 static Set setDifference(Set set, Set other, Set result) {
1096 for (var element in set) { 1096 for (var element in set) {
1097 if (!other.contains(element)) { 1097 if (!other.contains(element)) {
1098 result.add(element); 1098 result.add(element);
1099 } 1099 }
1100 } 1100 }
1101 return result; 1101 return result;
1102 } 1102 }
1103 } 1103 }
OLDNEW
« no previous file with comments | « runtime/lib/typed_data.dart ('k') | sdk/lib/_collection_dev/list.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698