Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changeset 506

Show
Ignore:
Timestamp:
01/12/11 05:37:50 (14 years ago)
Author:
braddr
Message:

fix array sort

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/rt/qsort.d

    r433 r506  
    3737 
    3838private const int _maxspan = 7; // subarrays of _maxspan or fewer elements 
    3939                                // will be sorted by a simple insertion sort 
    4040 
    4141/* Adjust _maxspan according to relative cost of a swap and a compare.  Reduce 
    4242_maxspan (not less than 1) if a swap is very expensive such as when you have 
    4343an array of large structures to be sorted, rather than an array of pointers to 
    4444structures.  The default value is optimized for a high cost for compares. */ 
    4545 
    4646 
    47 extern (C) long _adSort(Array a, TypeInfo ti) 
     47extern (C) void[] _adSort(Array a, TypeInfo ti) 
    4848{ 
    4949  byte*[40] stack;              // stack 
    5050  byte* i, j;            // scan and limit pointers 
    5151  auto width = ti.tsize(); 
    5252 
    5353  auto base = cast(byte *)a.ptr; 
    5454  auto thresh = _maxspan * width;        // size of _maxspan elements in bytes 
    5555  auto sp = stack.ptr;                   // stack pointer 
    5656  auto limit = base + a.length * width;  // pointer past end of array 
    5757  while (1)                              // repeat until done then return 
     
    114114      i += width; 
    115115    } 
    116116 
    117117    if (sp > stack.ptr)                 // if any entries on stack... 
    118118    { 
    119119      sp -= 2;                          // pop the base and limit 
    120120      base = sp[0]; 
    121121      limit = sp[1]; 
    122122    } 
    123123    else                                // else stack empty, all done 
    124       return *cast(long*)(&a); 
     124      return *cast(void[]*)(&a); 
    125125  } 
    126126  assert(0); 
    127127} 
    128128 
    129129 
    130130unittest 
    131131{ 
    132132    debug(qsort) printf("array.sort.unittest()\n"); 
    133133 
    134134    int a[] = new int[10];