Mercurial > projects > ldc
annotate tango/lib/compiler/llvmdc/qsort2.d @ 339:385a18242485 trunk
[svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
Fixed issues with slice initialization (!!!) of multidimensional static arrays.
Attempt to fix issue with referencing nested 'this' pointers introduced in DMD 1.033 merge.
author | lindquist |
---|---|
date | Sun, 13 Jul 2008 01:29:49 +0200 |
parents | d9d5d59873d8 |
children |
rev | line source |
---|---|
132 | 1 |
2 /* | |
3 * Placed into Public Domain | |
4 * written by Walter Bright | |
5 * www.digitalmars.com | |
6 * | |
7 * This is a public domain version of qsort.d. | |
8 * All it does is call C's qsort(), but runs a little slower since | |
9 * it needs to synchronize a global variable. | |
10 */ | |
11 | |
12 /* | |
13 * Modified by Sean Kelly <sean@f4.ca> for use with Tango. | |
14 */ | |
15 | |
16 //debug=qsort; | |
17 | |
18 private import tango.stdc.stdlib; | |
19 | |
20 struct Array | |
21 { | |
22 size_t length; | |
23 void* ptr; | |
24 } | |
25 | |
26 private TypeInfo tiglobal; | |
27 | |
28 extern (C) int cmp(void* p1, void* p2) | |
29 { | |
30 return tiglobal.compare(p1, p2); | |
31 } | |
32 | |
270
d9d5d59873d8
[svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
lindquist
parents:
132
diff
changeset
|
33 extern (C) Array _adSort(Array a, TypeInfo ti) |
132 | 34 { |
35 synchronized | |
36 { | |
37 tiglobal = ti; | |
38 tango.stdc.stdlib.qsort(a.ptr, a.length, cast(size_t)ti.tsize(), &cmp); | |
39 } | |
270
d9d5d59873d8
[svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
lindquist
parents:
132
diff
changeset
|
40 return a; |
132 | 41 } |
42 | |
43 | |
44 | |
45 unittest | |
46 { | |
47 debug(qsort) printf("array.sort.unittest()\n"); | |
48 | |
49 int a[] = new int[10]; | |
50 | |
51 a[0] = 23; | |
52 a[1] = 1; | |
53 a[2] = 64; | |
54 a[3] = 5; | |
55 a[4] = 6; | |
56 a[5] = 5; | |
57 a[6] = 17; | |
58 a[7] = 3; | |
59 a[8] = 0; | |
60 a[9] = -1; | |
61 | |
62 a.sort; | |
63 | |
64 for (int i = 0; i < a.length - 1; i++) | |
65 { | |
66 //printf("i = %d", i); | |
67 //printf(" %d %d\n", a[i], a[i + 1]); | |
68 assert(a[i] <= a[i + 1]); | |
69 } | |
70 } |