summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjon <jonrevold@gmail.com>2020-04-04 13:58:09 +0200
committerjon <jonrevold@gmail.com>2020-04-04 13:58:09 +0200
commit8c261693d340ce42c347149f2a4f19920f442dee (patch)
tree8328ab04c6091fa731aed80e42bb28f06d9953a5
parent60ca2e95652a7101e97076af549381868ad20aad (diff)
downloadct_sequence-8c261693d340ce42c347149f2a4f19920f442dee.tar.gz
a
-rw-r--r--makefile2
-rw-r--r--src/main.c70
2 files changed, 18 insertions, 54 deletions
diff --git a/makefile b/makefile
index 6616a61..ad41c66 100644
--- a/makefile
+++ b/makefile
@@ -56,7 +56,7 @@ ifneq ($(run),)
run_cmd := @echo "run $(bin)"
run_cmd += && cd bin
run_cmd += && echo "----------------------------------------------------------------"
- run_cmd += && time ./$(out_file) 5000000000
+ run_cmd += && time ./$(out_file) 100000000
run_cmd += ; echo "----------------------------------------------------------------"
run_cmd += && cd ..
endif
diff --git a/src/main.c b/src/main.c
index 7ea7a53..1c34da7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -4,16 +4,11 @@
#include <string.h>
#include <okelib2/okelib2.h>
-#define U40_MAX ((1ULL<<40)-1)
#define U32_MAX ((1ULL<<32)-1)
-typedef struct uint40_t{
- uint8_t n[5];
-}uint40_t;
-
static ftimer_t ft;
-static uint40_t *h40;
-static uint32_t *h32;
+static uint32_t *h;
+static uint8_t *h_ext;
static void fuk(char const *str){
printf("error!( %s\n",str);
@@ -21,18 +16,6 @@ static void fuk(char const *str){
exit(1);
}
-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(int p){
char buf[FMTFTIME_BUFSIZE];
ftime_t t = ftimer_time(&ft);
@@ -42,38 +25,20 @@ static void perse(int p){
}
static void init(uint64_t n){
- size_t h32_n;
- size_t h40_n;
-
- if(n > U32_MAX+1){
- h32_n = U32_MAX+1;
- h40_n = n-h32_n;
- h40 = malloc(sizeof(uint40_t)*h40_n);
- if(!h40) fuk("memory");
- memset(h40,0xFF,sizeof(uint40_t)*h40_n);
- }else{
- h32_n = n;
- h40_n = 0;
- }
- h32 = malloc(sizeof(uint32_t)*h32_n);
- if(!h32) fuk("memory");
- memset(h32,0xFF,sizeof(uint32_t)*h32_n);
+ h = malloc(sizeof(uint32_t)*n);
+ h_ext = malloc(sizeof(uint8_t)*n);
+ if(!h || !h_ext) fuk("memory");
+ memset(h, 0x00,sizeof(uint32_t)*n);
+ memset(h_ext, 0x00,sizeof(uint8_t)*n);
}
-static int load_store(uint64_t t,uint64_t in,uint64_t *out){
+static uint64_t load_store(uint64_t t,uint64_t in){
uint64_t r;
- int unsee;
- if(in > U32_MAX-1){
- r = u40_to_u64(h40[t]);
- unsee = r == U40_MAX;
- h40[t] = u64_to_u40(in);
- }else{
- r = h32[t];
- unsee = r == U32_MAX;
- h32[t] = in;
- }
- *out = r;
- return unsee;
+
+ r = h[t];
+ h[t] = in;
+
+ return r;
}
int main(int argc,char **argv){
@@ -89,7 +54,7 @@ int main(int argc,char **argv){
}
n = strtoull(argv[1],0,10);
- printf("n = %llu\n",n); fflush(stdout);
+ printf("n = %ju\n",n); fflush(stdout);
init(n);
t = 0;
@@ -110,11 +75,10 @@ int main(int argc,char **argv){
if(y == 0) beg++;
for(uint64_t x = beg;x < end;x++){
- uint64_t z;
- int unsee;
+ uint64_t z;
- unsee = load_store(t,x,&z);
- t = unsee ? 0 : x-z;
+ z = load_store(t,x);
+ t = z == 0 ? 0 : x-z;
}
perse((y+1)*100/outer);