commit 88e5b3bb17ccec76736347320b4bcd2186d3e8ef
parent 4e5eeccd8049accf5604efad12cd2a9f11a1df2d
Author: olikru <olikru@tkruger.se>
Date: Tue, 7 May 2024 22:16:29 +0200
foobar
Diffstat:
6 files changed, 91 insertions(+), 7 deletions(-)
diff --git a/context.c b/context.c
@@ -0,0 +1,44 @@
+#include "context.h"
+
+void
+ctx_init(ctx_t *ctx)
+{
+ ctx->zs_alloc = INITIAL_NUMBER_OF_ZS;
+ ctx->nzs = 0;
+ _fmpz_vec_init(ctx->zs, ctx->zs_alloc);
+
+ ctx->qs_alloc = INITIAL_NUMBER_OF_QS;
+ ctx->nqs = 0;
+ _fmpq_vec_init(ctx->qs, ctx->qs_alloc);
+
+ ctx->primorial = NULL;
+ ctx->smallprimes = NULL;
+ ctx->nsmallprimes = 0;
+}
+
+void
+ctx_clear(ctx_t *ctx)
+{
+ _fmpz_vec_clear(ctx->zs, ctx->zs_alloc);
+ _fmpq_vec_clear(ctx->qs, ctx->qs_alloc);
+
+ if (ctx->primorial != NULL) {
+ fmpz_clear(ctx->primorial);
+ ctx->primorial = NULL;
+ }
+
+ if (ctx->smallprimes != NULL) {
+ _fmpz_vec_clear(ctx->smallprimes, ctx->nsmallprimes);
+ ctx->smallprimes = NULL;
+ }
+}
+
+void
+ctx_set_precomputed_primorial(ctx_t *ctx)
+{
+}
+
+void
+ctx_set_precomputed_smallprimes(ctx_t *ctx)
+{
+}
diff --git a/context.h b/context.h
@@ -0,0 +1,34 @@
+#ifndef CONTEXT_H
+#define CONTEXT_H
+
+#include <flint.h>
+#include <fmpz.h>
+#include <fmpz_vec.h>
+#include <fmpq.h>
+#include <fmpq_vec.h>
+
+#define INITIAL_NUMBER_OF_ZS 4
+#define INITIAL_NIMBER_OF_QS 4
+
+typedef struct _context_t {
+ fmpz *zs;
+ slong nzs;
+ slong zs_alloc;
+
+ fmpq *qs;
+ slong nqs;
+ slong qs_alloc;
+
+ fmpz_t *primorial;
+
+ fmpz *smallprimes;
+ slong nsmallprimes;
+} ctx_t;
+
+void ctx_init(ctx_t *ctx);
+void ctx_clear(ctx_t *ctx);
+
+void ctx_set_precomputed_primorial(ctx_t *ctx);
+void ctx_set_precomputed_smallprimes(ctx_t *ctx);
+
+#endif
diff --git a/pierre.c b/pierre.c
@@ -1,9 +1,3 @@
-#include <fmpz.h>
-#include <fmpz_vec.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-
#include "pierre.h"
void
diff --git a/pierre.h b/pierre.h
@@ -1,6 +1,12 @@
#ifndef _PIERRE_H_
#define _PIERRE_H_
+#include <fmpz.h>
+#include <fmpz_vec.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
#define FERMAT_CTX_NZS 1
typedef struct __fermat_ctx {
diff --git a/smallfactor.c b/smallfactor.c
@@ -1,5 +1,12 @@
#include "smallfactor.h"
+void
+euclidean_ctx_init(euclidean_ctx *ctx)
+{
+ fmpz_init2(ctx->primorial, NLIMBS_PRECOMPUTE_PRIMORIAL);
+ fmpz_from_digits();
+}
+
#define N_EIGHT_BIT_PRIMES 54
const uint64_t EIGHT_BIT_PRIMES[N_EIGHT_BIT_PRIMES] = {
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31,
diff --git a/smallfactor.h b/smallfactor.h
@@ -5,7 +5,6 @@
#include <fmpz.h>
#include <stdlib.h>
-#define SMALLFACTOR_PRIMORIAL_FILENAME ("assets/primorial16b.bin")
#define SMALLFACTOR_FOUND 1
#define SMALLFACTOR_NOT_FOUND 0