summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjonsykkel <jonrevold@gmail.com>2020-04-03 22:44:34 +0200
committerjonsykkel <jonrevold@gmail.com>2020-04-03 22:44:34 +0200
commit21427fd699d2c80ee0f432bd60112a871cef157a (patch)
treed2782baddc518796e88d61ec01776d8125f1bd3f
parenta2e922d6a3f53baf9c15faf6152ed04da84386c4 (diff)
downloadct_sequence-21427fd699d2c80ee0f432bd60112a871cef157a.tar.gz
vork
-rw-r--r--makefile2
-rw-r--r--src/main.c97
2 files changed, 62 insertions, 37 deletions
diff --git a/makefile b/makefile
index 0a0ddbe..bf0de30 100644
--- a/makefile
+++ b/makefile
@@ -10,7 +10,7 @@ src_dir := src
CFLAGS := -std=c11 -fdata-sections -ffunction-sections -D_POSIX_C_SOURCE=200809L
CFLAGS += -pedantic -Wall -Wextra -Wcast-qual -Wstrict-aliasing -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wvla -Wno-parentheses -Wno-unused-variable -Wno-unused-function -Wno-unused-parameter -Wno-unused-label
LDFLAGS := -Wl,--gc-sections
-LDLIBS :=
+LDLIBS := -lokelib2
ARFLAGS := -rcs
compile = $(CC) $(CFLAGS) -MMD -c $< -o $@
diff --git a/src/main.c b/src/main.c
index 5e7cff3..0d8e5cf 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2,21 +2,42 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
+#include <okelib2/okelib2.h>
-typedef uint32_t uint_t;
-typedef int32_t int_t;
-#define BITS (sizeof(uint_t)*8)
+#define UINT40_MAX ((1ULL<<40)-1)
-static void primt(uint_t x,uint_t t){
- //printf("%llu: %llu\n",x+1,t);
- printf("%u: %u\n",x+1,t);
- //printf("%u\n",t);
+typedef struct uint40_t{
+ uint8_t n[5];
+}uint40_t;
+
+static void primt(uint64_t x,uint64_t t){
+ printf("%llu: %llu\n",x+1,t);
+}
+
+static uint64_t u40_to_u64(uint40_t x){
+ uint64_t r = 0;
+ memcpy(&r,&x,sizeof(x));
+ return r;
+}
+
+static uint40_t u64_to_u40(uint64_t x){
+ uint40_t r;
+ memcpy(&r,&x,sizeof(r));
+ return r;
+}
+
+static void perse(ftimer_t *ft,int p){
+ char buf[FMTFTIME_BUFSIZE];
+ ftime_t t = ftimer_time(ft);
+ fmtftime(buf,t);
+ printf("%12s %3u%%\n",buf,p);
+ fflush(stdout);
}
int main(int argc,char **argv){
- uint_t *h;
- uint_t t;
- uint_t max;
+ uint40_t *h;
+ uint64_t t;
+ uint64_t max;
/*
if(argc < 2){
@@ -27,42 +48,46 @@ int main(int argc,char **argv){
max = strtoull(argv[1],0,10);
*/
+ max = 5000000000;
max = 1000000000;
- h = calloc(sizeof(uint_t)*max,1);
- //h = malloc(sizeof(uint_t)*max);
+ //h = calloc(sizeof(uint_t)*max,1);
+ h = malloc(sizeof(uint40_t)*max);
if(!h){
printf("failed to allogate mamorY\n");
return 1;
}
- //memset(h,0xFF,sizeof(uint_t)*max);
+ memset(h,0xFF,sizeof(uint40_t)*max);
t = 0;
- for(uint_t x = 1;x < max;x++){
- /*
- if((int32int_t)h[t] >= 0){
- n = x-h[t];
- }else{
- n = 0;
+ ftimer_t ft;
+ uint64_t agurk = max/100;
+ uint64_t outer = max/agurk+1;
+ uint64_t last = max%agurk;
+ if(last == 0){
+ last = agurk;
+ outer--;
+ }
+
+ ftimer_init(&ft);
+ perse(&ft,0);
+ for(uint64_t y = 0;y < outer;y++){
+
+ uint64_t beg = y*agurk;
+ uint64_t end = beg+(y == outer-1 ? last : agurk);
+ if(y == 0) beg++;
+ //printf("%12llu -> %12llu\n",beg,end);
+
+ for(uint64_t x = beg;x < end;x++){
+ uint64_t ht;
+
+ ht = u40_to_u64(h[t]);
+ h[t] = u64_to_u40(x);
+ t = ht == UINT40_MAX ? 0 : x-ht;
}
- */
-
- uint_t z;
- uint_t ht;
-
- ht = h[t];
- z = (int_t)ht>>(BITS-1);
- h[t] = -x;
- t = z & (x+ht);
-
- /*
- uint_t ht;
- ht = h[t];
- h[t] = x;
- //t = ht == (uint_t)-1 ? 0 : x-ht;
- t = (int_t)ht < 0 ? 0 : x-ht;
- */
+
+ perse(&ft,(y+1)*100/outer);
}
primt(max-1,t);