From 387db2b9b4ccad433d1770dd788125e5f3d18489 Mon Sep 17 00:00:00 2001 From: Pascal Date: Fri, 16 Sep 2016 17:07:18 +0200 Subject: [PATCH] add explicit group_dlog_clear using subgroup and clearing it would have corrupted the dlog pointers --- acb_dirichlet.h | 1 + acb_dirichlet/group_clear.c | 11 ----------- acb_dirichlet/group_dlog_precompute.c | 21 +++++++++++++++++++-- acb_dirichlet/test/t-chars.c | 2 ++ doc/source/acb_dirichlet.rst | 11 +++++++++-- 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/acb_dirichlet.h b/acb_dirichlet.h index 4735fd29..283147d0 100644 --- a/acb_dirichlet.h +++ b/acb_dirichlet.h @@ -72,6 +72,7 @@ void acb_dirichlet_group_init(acb_dirichlet_group_t G, ulong q); void acb_dirichlet_subgroup_init(acb_dirichlet_group_t H, const acb_dirichlet_group_t G, ulong h); void acb_dirichlet_group_clear(acb_dirichlet_group_t G); void acb_dirichlet_group_dlog_precompute(acb_dirichlet_group_t G, ulong num); +void acb_dirichlet_group_dlog_clear(acb_dirichlet_group_t G); /* properties of elements without log */ diff --git a/acb_dirichlet/group_clear.c b/acb_dirichlet/group_clear.c index 125a28ae..9864ad1c 100644 --- a/acb_dirichlet/group_clear.c +++ b/acb_dirichlet/group_clear.c @@ -15,17 +15,6 @@ void acb_dirichlet_group_clear(acb_dirichlet_group_t G) { - slong k; - - for (k = 0; k < G->num; k++) - { - if (G->P[k].dlog != NULL) - { - dlog_precomp_clear(G->P[k].dlog); - flint_free(G->P[k].dlog); - } - } - flint_free(G->P); flint_free(G->generators); flint_free(G->PHI); diff --git a/acb_dirichlet/group_dlog_precompute.c b/acb_dirichlet/group_dlog_precompute.c index 292efc7f..2ab1daf6 100644 --- a/acb_dirichlet/group_dlog_precompute.c +++ b/acb_dirichlet/group_dlog_precompute.c @@ -18,11 +18,28 @@ acb_dirichlet_prime_group_dlog_precompute(acb_dirichlet_prime_group_struct * P, dlog_precomp_modpe_init(P->dlog, P->g, P->p, P->e, P->pe.n, num); } - void acb_dirichlet_group_dlog_precompute(acb_dirichlet_group_t G, ulong num) { slong k; for (k = 0; k < G->num; k++) - acb_dirichlet_prime_group_dlog_precompute(&G->P[k], num); + { + if (G->P[k].dlog == NULL) + acb_dirichlet_prime_group_dlog_precompute(&G->P[k], num); + } +} + +void +acb_dirichlet_group_dlog_clear(acb_dirichlet_group_t G) +{ + slong k; + for (k = 0; k < G->num; k++) + { + if (G->P[k].dlog != NULL) + { + dlog_precomp_clear(G->P[k].dlog); + flint_free(G->P[k].dlog); + G->P[k].dlog = NULL; + } + } } diff --git a/acb_dirichlet/test/t-chars.c b/acb_dirichlet/test/t-chars.c index c5a4cbd0..a650aa95 100644 --- a/acb_dirichlet/test/t-chars.c +++ b/acb_dirichlet/test/t-chars.c @@ -140,6 +140,8 @@ int main() } + acb_dirichlet_group_dlog_clear(G); + acb_dirichlet_char_clear(chi); acb_dirichlet_char_clear(chi2); acb_dirichlet_conrey_clear(x); diff --git a/doc/source/acb_dirichlet.rst b/doc/source/acb_dirichlet.rst index 5ec85d71..40661bf7 100644 --- a/doc/source/acb_dirichlet.rst +++ b/doc/source/acb_dirichlet.rst @@ -76,11 +76,12 @@ logarithms. .. function:: void acb_dirichlet_subgroup_init(acb_dirichlet_group_t H, const acb_dirichlet_group_t G, ulong h) Given an already computed group *G* mod `q`, initialize its subgroup *H* - defined mod `h\mid q`. Precomputed discrete log tables are kept. + defined mod `h\mid q`. Precomputed discrete log tables are inherited. .. function:: void acb_dirichlet_group_clear(acb_dirichlet_group_t G) - Clears *G*. + Clears *G*. Remark this function does *not* clear the discrete logarithm + tables stored in *G* (which may be shared with another group). .. function:: void acb_dirichlet_group_dlog_precompute(acb_dirichlet_group_t G, ulong num) @@ -89,6 +90,12 @@ logarithms. If *num* gets very large, the entire group may be indexed. +.. function:: void acb_dirichlet_group_dlog_clear(acb_dirichlet_group_t G, ulong num) + + Clear discrete logarithm tables in *G*. When discrete logarithm tables are + shared with subgroups, those subgroups must be cleared before clearing the + tables. + Conrey elements -------------------------------------------------------------------------------