Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,9 @@
#ifndef _CSEQUENCE_H
#define _CSEQUENCE_H
#include <stdlib.h>
void setfillconst(double c);
void fillwithconst(double *v, int n);
void fillwithrrange(double *v, int n);
void shuffledrange(double *v, int n);
#endif

View file

@ -0,0 +1,31 @@
#include "csequence.h"
static double fill_constant;
void setfillconst(double c)
{
fill_constant = c;
}
void fillwithconst(double *v, int n)
{
while( --n >= 0 ) v[n] = fill_constant;
}
void fillwithrrange(double *v, int n)
{
int on = n;
while( --on >= 0 ) v[on] = n - on;
}
void shuffledrange(double *v, int n)
{
int on = n;
fillwithrrange(v, n);
while( --n >= 0 ) {
int r = rand() % on;
double t = v[n];
v[n] = v[r];
v[r] = t;
}
}

View file

@ -0,0 +1,39 @@
#ifndef _WRITETIMINGS_H
#define _WRITETIMINGS_H
#include "sorts.h"
#include "csequence.h"
#include "timeit.h"
/* we repeat the same MEANREPEAT times, and get the mean; this *should*
give "better" results ... */
#define MEANREPEAT 10.0
#define BUFLEN 128
#define MAKEACTION(ALGO) \
int action_ ## ALGO (int size) { \
ALGO ## _sort(tobesorted, size); \
return 0; }
#define MAKEPIECE(N) { #N , action_ ## N }
int action_bubble(int size);
int action_shell(int size);
int action_quick(int size);
int action_insertion(int size);
int action_merge(int size);
int doublecompare( const void *a, const void *b );
int action_qsort(int size);
int get_the_longest(int *a);
struct testpiece
{
const char *name;
int (*action)(int);
};
typedef struct testpiece testpiece_t;
struct seqdef
{
const char *name;
void (*seqcreator)(double *, int);
};
typedef struct seqdef seqdef_t;
#endif

View file

@ -0,0 +1,104 @@
#include <stdio.h>
#include <stdlib.h>
#include "writetimings.h"
double *tobesorted = NULL;
const char *bname = "data_";
const char *filetempl = "%s%s_%s.dat";
int datlengths[] = {100, 200, 300, 500, 1000, 5000, 10000, 50000, 100000};
testpiece_t testpieces[] =
{
// MAKEPIECE(bubble),
MAKEPIECE(shell),
MAKEPIECE(merge),
MAKEPIECE(insertion),
MAKEPIECE(quick),
MAKEPIECE(qsort),
{ NULL, NULL }
};
seqdef_t seqdefs[] =
{
{ "c1", fillwithconst },
{ "rr", fillwithrrange },
{ "sr", shuffledrange },
{ NULL, NULL }
};
MAKEACTION(bubble)
MAKEACTION(insertion)
MAKEACTION(quick)
MAKEACTION(shell)
int action_merge(int size)
{
double *res = merge_sort(tobesorted, size);
free(res); /* unluckly this affects performance */
return 0;
}
int doublecompare( const void *a, const void *b )
{
if ( *(const double *)a < *(const double *)b ) return -1;
else return *(const double *)a > *(const double *)b;
}
int action_qsort(int size)
{
qsort(tobesorted, size, sizeof(double), doublecompare);
return 0;
}
int get_the_longest(int *a)
{
int r = *a;
while( *a > 0 ) {
if ( *a > r ) r = *a;
a++;
}
return r;
}
int main()
{
int i, j, k, z, lenmax;
char buf[BUFLEN];
FILE *out;
double thetime;
lenmax = get_the_longest(datlengths);
printf("Bigger data set has %d elements\n", lenmax);
tobesorted = malloc(sizeof(double)*lenmax);
if ( tobesorted == NULL ) return 1;
setfillconst(1.0);
for(i=0; testpieces[i].name != NULL; i++) {
for(j=0; seqdefs[j].name != NULL; j++) {
snprintf(buf, BUFLEN, filetempl, bname, testpieces[i].name,
seqdefs[j].name);
out = fopen(buf, "w");
if ( out == NULL ) goto severe;
printf("Producing data for sort '%s', created data type '%s'\n",
testpieces[i].name, seqdefs[j].name);
for(k=0; datlengths[k] > 0; k++) {
printf("\tNumber of elements: %d\n", datlengths[k]);
thetime = 0.0;
seqdefs[j].seqcreator(tobesorted, datlengths[k]);
fprintf(out, "%d ", datlengths[k]);
for(z=0; z < MEANREPEAT; z++) {
thetime += time_it(testpieces[i].action, datlengths[k]);
}
thetime /= MEANREPEAT;
fprintf(out, "%.8lf\n", thetime);
}
fclose(out);
}
}
severe:
free(tobesorted);
return 0;
}

View file

@ -0,0 +1,30 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "polifitgsl.h"
#define MAXNUMOFDATA 100
double x[MAXNUMOFDATA], y[MAXNUMOFDATA];
double cf[2];
int main()
{
int i, nod;
int r;
for(i=0; i < MAXNUMOFDATA; i++)
{
r = scanf("%lf %lf\n", &x[i], &y[i]);
if ( (r == EOF) || (r < 2) ) break;
x[i] = log10(x[i]);
y[i] = log10(y[i]);
}
nod = i;
polynomialfit(nod, 2, x, y, cf);
printf("C0 = %lf\nC1 = %lf\n", cf[0], cf[1]);
return 0;
}