/************ ** strsift ** ************* ** Pass this function: ** 1) A pointer to an array of offset pointers ** 2) A pointer to a string array ** 3) The number of elements in the string array ** 4) Offset within which to sort. ** Sift the array within the bounds of those offsets (thus ** building a heap). */ private static void strsift(string[] array, int i, int j) { int k; string temp; while ((i + i) <= j) { k = i + i; if (k < j) { //array[k].CompareTo(array[k+1]); if (StringOrdinalComparer.Compare(array[k], array[k + 1]) < 0) { ++k; } } //if(array[i]<array[k]) if (StringOrdinalComparer.Compare(array[i], array[k]) < 0) { temp = array[k]; array[k] = array[i]; array[i] = temp; i = k; } else { i = j + 1; } } return; }
/************************** ** DoStringSortIteration ** *************************** ** This routine executes one iteration of the string ** sort benchmark. It returns the number of ticks ** Note that this routine also builds the offset pointer ** array. */ private static int DoStringSortIteration(string[][] arraybase, int numarrays, int arraysize) { long elapsed; /* Elapsed ticks */ int i; /* ** Load up the array(s) with random numbers */ LoadStringArray(arraybase, arraysize, numarrays); /* ** Start the stopwatch */ elapsed = ByteMark.StartStopwatch(); /* ** Execute heapsorts */ for (i = 0; i < numarrays; i++) { // StrHeapSort(tempobase,tempsbase,nstrings,0L,nstrings-1); StrHeapSort(arraybase[i], 0, arraysize - 1); } /* ** Record elapsed time */ elapsed = ByteMark.StopStopwatch(elapsed); #if DEBUG for (i = 0; i < arraysize - 1; i++) { /* ** Compare strings to check for proper ** sort. */ if (StringOrdinalComparer.Compare(arraybase[0][i + 1], arraybase[0][i]) < 0) { Console.Write("Error in StringSort! arraybase[0][{0}]='{1}', arraybase[0][{2}]='{3}\n", i, arraybase[0][i], i + 1, arraybase[0][i + 1]); break; } } #endif return((int)elapsed); }