summaryrefslogtreecommitdiff
path: root/stringsort.c
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2008-11-14 22:27:04 +0000
committerMatt Turner <mattst88@gmail.com>2008-11-14 22:27:04 +0000
commit7225b0865e8c7697fce69224640142374b22364d (patch)
tree27fb27187a9f6010485a2f5bc0716ce1e0af7acd /stringsort.c
parent341997c711b8d0ba7edf70cced84762e2a82d996 (diff)
-- Remove numarrays member from structs in favor of a local variable
git-svn-id: svn://mattst88.com/svn/cleanbench/trunk@43 0d43b9a7-5ab2-4d7b-af9d-f64450cef757
Diffstat (limited to 'stringsort.c')
-rw-r--r--stringsort.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/stringsort.c b/stringsort.c
index 57a18d5..c102b54 100644
--- a/stringsort.c
+++ b/stringsort.c
@@ -15,10 +15,10 @@
********************/
static clock_t DoStringSortIteration(unsigned char *arraybase,
- unsigned int numarrays,
+ unsigned int num_arrays,
unsigned long arraysize);
static unsigned long *LoadStringArray(unsigned char *strarray,
- unsigned int numarrays,
+ unsigned int num_arrays,
unsigned long *strings,
unsigned long arraysize);
static void stradjust(unsigned long *optrarray,
@@ -53,19 +53,20 @@ void DoStringSort(void)
clock_t total_time = 0;
int iterations = 0;
+ int num_arrays = 1;
+
if (strsortstruct->adjust == FALSE) {
strsortstruct->adjust = TRUE;
/*
** Initialize the number of arrays.
*/
- strsortstruct->numarrays = 1;
while (1) {
/*
** Allocate space for array. We'll add an extra 100
** bytes to protect memory as strings move around
** (this can happen during string adjustment)
*/
- arraybase = realloc(arraybase, (strsortstruct->arraysize + 100) * strsortstruct->numarrays);
+ arraybase = realloc(arraybase, (strsortstruct->arraysize + 100) * num_arrays);
if (!arraybase) {
fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
exit(1);
@@ -77,18 +78,18 @@ void DoStringSort(void)
** minimum, then de-allocate the array, reallocate a
** an additional array, and try again.
*/
- if (DoStringSortIteration(arraybase, strsortstruct->numarrays, strsortstruct->arraysize) > MINIMUM_TICKS) {
+ if (DoStringSortIteration(arraybase, num_arrays, strsortstruct->arraysize) > MINIMUM_TICKS) {
break;
}
- ++strsortstruct->numarrays;
+ ++num_arrays;
}
} else {
/*
** We don't have to perform self adjustment code.
** Simply allocate the space for the array.
*/
- arraybase = malloc((strsortstruct->arraysize + 100) * strsortstruct->numarrays);
+ arraybase = malloc((strsortstruct->arraysize + 100) * num_arrays);
if (!arraybase) {
fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
exit(1);
@@ -96,8 +97,8 @@ void DoStringSort(void)
}
do {
- total_time += DoStringSortIteration(arraybase, strsortstruct->numarrays, strsortstruct->arraysize);
- iterations += strsortstruct->numarrays;
+ total_time += DoStringSortIteration(arraybase, num_arrays, strsortstruct->arraysize);
+ iterations += num_arrays;
} while (total_time < MINIMUM_SECONDS * CLOCKS_PER_SEC);
free(arraybase);
@@ -114,7 +115,7 @@ void DoStringSort(void)
** array.
*/
static clock_t
-DoStringSortIteration(unsigned char *arraybase, unsigned int numarrays,unsigned long arraysize)
+DoStringSortIteration(unsigned char *arraybase, unsigned int num_arrays,unsigned long arraysize)
{
unsigned long *optrarray; /* Offset pointer array */
clock_t start, stop;
@@ -126,7 +127,7 @@ DoStringSortIteration(unsigned char *arraybase, unsigned int numarrays,unsigned
/*
** Load up the array(s) with random numbers
*/
- optrarray=LoadStringArray(arraybase,numarrays,&nstrings,arraysize);
+ optrarray=LoadStringArray(arraybase,num_arrays,&nstrings,arraysize);
/*
** Set temp base pointers...they will be modified as the
@@ -137,7 +138,7 @@ DoStringSortIteration(unsigned char *arraybase, unsigned int numarrays,unsigned
start = clock();
- for(i = 0; i < numarrays; i++) {
+ for(i = 0; i < num_arrays; i++) {
StrHeapSort(tempobase, tempsbase, nstrings, 0L, nstrings - 1);
tempobase += nstrings; /* Advance base pointers */
tempsbase += arraysize+100;
@@ -160,7 +161,7 @@ DoStringSortIteration(unsigned char *arraybase, unsigned int numarrays,unsigned
** routine builds one array, then copies it into the others.
*/
static unsigned long *LoadStringArray(unsigned char *strarray, /* String array */
- unsigned int numarrays, /* # of arrays */
+ unsigned int num_arrays, /* # of arrays */
unsigned long *nstrings, /* # of strings */
unsigned long arraysize) /* Size of array */
{
@@ -235,7 +236,7 @@ do
*/
k=1;
tempsbase=strarray;
-while(k<numarrays)
+while(k<num_arrays)
{ tempsbase+=arraysize+100; /* Set base */
for(l=0;l<arraysize;l++)
tempsbase[l]=strarray[l];
@@ -246,7 +247,7 @@ while(k<numarrays)
** Now the array is full, allocate enough space for an
** offset pointer array.
*/
-optrarray = malloc(*nstrings * sizeof(unsigned long) * numarrays);
+optrarray = malloc(*nstrings * sizeof(unsigned long) * num_arrays);
if (!optrarray) {
/* FIXME: add error message */
free(strarray);
@@ -270,7 +271,7 @@ for(j=0;j<*nstrings;j++)
*/
k=1;
tempobase=optrarray;
-while(k<numarrays)
+while(k<num_arrays)
{ tempobase+=*nstrings;
for(l=0;l<*nstrings;l++)
tempobase[l]=optrarray[l];