Mercurial > hg > truffle
comparison src/share/vm/utilities/quickSort.cpp @ 10136:cc12becb22e7
Merge
author | dcubed |
---|---|
date | Sun, 21 Apr 2013 21:05:02 -0700 |
parents | 5a9fa2ba85f0 |
children | f9be75d21404 e76dd894b984 |
comparison
equal
deleted
inserted
replaced
10134:a527ddd44e07 | 10136:cc12becb22e7 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
28 | 28 |
29 #ifndef PRODUCT | 29 #ifndef PRODUCT |
30 | 30 |
31 #include "runtime/os.hpp" | 31 #include "runtime/os.hpp" |
32 #include "utilities/quickSort.hpp" | 32 #include "utilities/quickSort.hpp" |
33 #include "memory/allocation.hpp" | |
34 #include "memory/allocation.inline.hpp" | |
35 #include <stdlib.h> | 33 #include <stdlib.h> |
36 | 34 |
37 static int test_comparator(int a, int b) { | 35 static int test_comparator(int a, int b) { |
38 if (a == b) { | 36 if (a == b) { |
39 return 0; | 37 return 0; |
187 } | 185 } |
188 | 186 |
189 // test sorting random arrays | 187 // test sorting random arrays |
190 for (int i = 0; i < 1000; i++) { | 188 for (int i = 0; i < 1000; i++) { |
191 int length = os::random() % 100; | 189 int length = os::random() % 100; |
192 int* test_array = NEW_C_HEAP_ARRAY(int, length, mtInternal); | 190 int* test_array = new int[length]; |
193 int* expected_array = NEW_C_HEAP_ARRAY(int, length, mtInternal); | 191 int* expected_array = new int[length]; |
194 for (int j = 0; j < length; j++) { | 192 for (int j = 0; j < length; j++) { |
195 // Choose random values, but get a chance of getting duplicates | 193 // Choose random values, but get a chance of getting duplicates |
196 test_array[j] = os::random() % (length * 2); | 194 test_array[j] = os::random() % (length * 2); |
197 expected_array[j] = test_array[j]; | 195 expected_array[j] = test_array[j]; |
198 } | 196 } |
210 sort(test_array, length, test_even_odd_comparator, true); | 208 sort(test_array, length, test_even_odd_comparator, true); |
211 assert(compare_arrays(test_array, expected_array, length), "Sorting identical arrays rendered different results"); | 209 assert(compare_arrays(test_array, expected_array, length), "Sorting identical arrays rendered different results"); |
212 sort(test_array, length, test_even_odd_comparator, true); | 210 sort(test_array, length, test_even_odd_comparator, true); |
213 assert(compare_arrays(test_array, expected_array, length), "Sorting already sorted array changed order of elements - not idempotent"); | 211 assert(compare_arrays(test_array, expected_array, length), "Sorting already sorted array changed order of elements - not idempotent"); |
214 | 212 |
215 FREE_C_HEAP_ARRAY(int, test_array, mtInternal); | 213 delete[] test_array; |
216 FREE_C_HEAP_ARRAY(int, expected_array, mtInternal); | 214 delete[] expected_array; |
217 } | 215 } |
218 } | 216 } |
219 | 217 |
220 #endif | 218 #endif |