summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjonsykkel <jonrevold@gmail.com>2020-04-05 04:01:06 +0200
committerjonsykkel <jonrevold@gmail.com>2020-04-05 04:01:06 +0200
commit1516b56e05f18dcf41b64ad909af120f55929685 (patch)
tree04ae9d17b740c473fe2dac520b317d5a98394a70
parentb2b31f9b12e2ce07902106a0e95118d469cf45ab (diff)
downloadct_sequence-1516b56e05f18dcf41b64ad909af120f55929685.tar.gz
vork
-rw-r--r--src/main.c79
1 files changed, 49 insertions, 30 deletions
diff --git a/src/main.c b/src/main.c
index 59ee7e8..207d96a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -12,12 +12,9 @@
uint64_t t;
static ftimer_t ft;
-static uint64_t n;
static algo_t *algo;
-static void (*nump)(void);
-
void fuk(char const *fmt,...){
va_list args;
va_start(args,fmt);
@@ -29,23 +26,17 @@ void fuk(char const *fmt,...){
}
static void perse(int p){
- //char buf[FMTFTIME_BUFSIZE];
- ftime_t t;
- float f;
-
- t = ftimer_time(&ft);
- f = (float)t/FTIME_SEC;
- //fmtftime(buf,t);
- //printf("%12s %3u%%\n",buf,p);
+ ftime_t t = ftimer_time(&ft);
+ float f = (float)t/FTIME_SEC;
printf("%9.3f\t%3u%%\n",f,p);
fflush(stdout);
}
-static void numper(void){
+static void calc_fast(uint64_t n){
algo->loop(1,n);
}
-static void numper_p(void){
+static void calc_perse(uint64_t n){
uint64_t agurk;
uint64_t outer;
uint64_t last;
@@ -63,45 +54,73 @@ static void numper_p(void){
}
}
+static void usake(void){
+ printf("usake: numper [-p] <n>\n");
+ printf(" -p display progress percentage\n");
+ printf(" -a<n> use algorithm n\n");
+ fflush(stdout);
+ exit(0);
+}
+
int main(int argc,char **argv){
+ size_t algo_n;
+ uint64_t n;
+ void (*calc)(uint64_t n);
+
#ifdef _WIN32
SetPriorityClass(GetCurrentProcess(),REALTIME_PRIORITY_CLASS);
#endif
- nump = numper;
+ calc = calc_fast;
+ algo_n = -1;
if(argc < 2){
- printf("usake: numper [-p] <n>\n");
- printf(" -p display progress percentage\n");
- printf(" -aN force usage of algo N\n");
- fflush(stdout);
- exit(0);
+ usake();
}
+ #define OPT(O) (strcmp(argv[x],O) == 0)
for(int x = 1;x < argc-1;x++){
- if(strcmp(argv[x],"-p") == 0){
- nump = numper_p;
- continue;
+ if(OPT("-p")){
+ calc = calc_perse;
+ }else if(argv[x][0] == '-' && argv[x][1] == 'a'){
+ algo_n = (size_t)argv[x][2]-(size_t)'0';
+ if(algo_n > 9){
+ printf("unrecognized algorithm\n");
+ algo_n = -1;
+ }
+ }else{
+ printf("unrecognized option: %s\n",argv[x]);
}
-
- printf("unrecognized option: %s\n",argv[x]);
}
n = strtoull(argv[argc-1],0,10);
+ if((int64_t)n <= 0) usake();
+
+ if(algo_n != (size_t)-1){
+ switch(algo_n){
+ case 1: algo = &a1; break;
+ case 3: algo = &a3; break;
+ default:
+ printf("unurecognized algorithm: %zu\n",algo_n);
+ algo_n = -1;
+ }
+ }
- if(n <= a1.nmax){
- algo = &a1;
- }else{
- algo = &a3;
+ if(algo_n == (size_t)-1){
+ if(n <= a1.nmax){
+ algo = &a1;
+ }else{
+ algo = &a3;
+ }
}
- printf("algo = %s\n",algo->name);
+ printf("algo = %s\n", algo->name);
printf("n = %llu\n",n);
fflush(stdout);
algo->init(n);
ftimer_init(&ft);
- nump();
+ calc(n);
printf("t = %llu\n",t);
fflush(stdout);