summaryrefslogtreecommitdiff
path: root/numsort.c
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2008-11-12 03:18:32 +0000
committerMatt Turner <mattst88@gmail.com>2008-11-12 03:18:32 +0000
commite618b16d4cc89e46ec4bac40af34a93790a17f8e (patch)
tree280aec8bfeafc746e375c05eb9a7d83bb6cdbaf8 /numsort.c
parent974755deb9bbea37752d2202844a1f485e59c8e7 (diff)
-- Cleanup fpemulation.c
-- Begin cleaning numsort.c git-svn-id: svn://mattst88.com/svn/cleanbench/trunk@9 0d43b9a7-5ab2-4d7b-af9d-f64450cef757
Diffstat (limited to 'numsort.c')
-rw-r--r--numsort.c94
1 files changed, 33 insertions, 61 deletions
diff --git a/numsort.c b/numsort.c
index 936b390..5756a31 100644
--- a/numsort.c
+++ b/numsort.c
@@ -25,24 +25,16 @@
** Not so; the routine returns # of iterations per sec.
*/
-void DoNumSort(void)
-{
-SortStruct *numsortstruct; /* Local pointer to global struct */
-long *arraybase; /* Base pointers of array */
-long accumtime; /* Accumulated time */
-double iterations; /* Iteration counter */
-char *errorcontext; /* Error context string pointer */
-int systemerror; /* For holding error codes */
+void DoNumSort(void) {
+ /* Error context string pointer */
+ const char *errorcontext = "CPU:Numeric Sort";
+ /* Local pointer to global struct */
+ SortStruct * numsortstruct = &global_numsortstruct;
-/*
-** Link to global structure
-*/
-numsortstruct=&global_numsortstruct;
-
-/*
-** Set the error context string.
-*/
-errorcontext="CPU:Numeric Sort";
+ long accumtime; /* Accumulated time */
+ double iterations; /* Iteration counter */
+ long *arraybase; /* Base pointers of array */
+ int systemerror; /* For holding error codes */
/*
** See if we need to do self adjustment code.
@@ -105,8 +97,8 @@ else
** All's well if we get here. Repeatedly perform sorts until the
** accumulated elapsed time is greater than # of seconds requested.
*/
-accumtime=0L;
-iterations=(double)0.0;
+accumtime = 0L;
+iterations = 0.0;
do {
accumtime+=DoNumSortIteration(arraybase,
@@ -127,11 +119,6 @@ numsortstruct->sortspersec=iterations *
if(numsortstruct->adjust==0)
numsortstruct->adjust=1;
-#ifdef DEBUG
-if (numsort_status==0) printf("Numeric sort: OK\n");
-numsort_status=0;
-#endif
-return;
}
/***********************
@@ -167,21 +154,6 @@ for(i=0;i<numarrays;i++)
** Get elapsed time
*/
elapsed=StopStopwatch(elapsed);
-#ifdef DEBUG
-{
- for(i=0;i<arraysize-1;i++)
- { /*
- ** Compare to check for proper
- ** sort.
- */
- if(arraybase[i+1]<arraybase[i])
- { printf("Sort Error\n");
- numsort_status=1;
- break;
- }
- }
-}
-#endif
return(elapsed);
}
@@ -264,29 +236,29 @@ return;
** Peforms the sift operation on a numeric array,
** constructing a heap in the array.
*/
-static void NumSift(long *array, /* Array of numbers */
- unsigned long i, /* Minimum of array */
- unsigned long j) /* Maximum of array */
+static void NumSift(long *array,/* Array of numbers */
+ unsigned long i, /* Minimum of array */
+ unsigned long j) /* Maximum of array */
{
-unsigned long k;
-long temp; /* Used for exchange */
+ unsigned long k;
+ unsigned long temp; /* Used for exchange */
-while((i+i)<=j)
-{
- k=i+i;
- if(k<j)
- if(array[k]<array[k+1L])
- ++k;
- if(array[i]<array[k])
- {
- temp=array[k];
- array[k]=array[i];
- array[i]=temp;
- i=k;
- }
- else
- i=j+1;
-}
-return;
+ while ( ( i + i ) <= j ) {
+ k = i + i;
+ if ( k < j ) {
+ if ( array[k] < array[k+1L] ) {
+ ++k;
+ }
+ }
+
+ if ( array[i] < array[k] ) {
+ temp = array[k];
+ array[k] = array[i];
+ array[i] = temp;
+ i = k;
+ } else {
+ i = j + 1;
+ }
+ }
}