Add cyclic group abstraction, with test code. Separate off exponentation
[u/mdw/catacomb] / pfilt.c
diff --git a/pfilt.c b/pfilt.c
index 4b58304..e3d1d3d 100644 (file)
--- a/pfilt.c
+++ b/pfilt.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: pfilt.c,v 1.3 2000/08/15 21:44:27 mdw Exp $
+ * $Id: pfilt.c,v 1.5 2004/04/01 12:50:09 mdw Exp $
  *
  * Finding and testing prime numbers
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: pfilt.c,v $
+ * Revision 1.5  2004/04/01 12:50:09  mdw
+ * Add cyclic group abstraction, with test code.  Separate off exponentation
+ * functions for better static linking.  Fix a buttload of bugs on the way.
+ * Generally ensure that negative exponents do inversion correctly.  Add
+ * table of standard prime-field subgroups.  (Binary field subgroups are
+ * currently unimplemented but easy to add if anyone ever finds a good one.)
+ *
+ * Revision 1.4  2000/10/08 12:14:57  mdw
+ * Remove vestiges of @primorial@.
+ *
  * Revision 1.3  2000/08/15 21:44:27  mdw
  * (pfilt_smallfactor): New function for doing trial division the hard
  * way.
@@ -64,7 +74,6 @@
 #include "pfilt.h"
 #include "pgen.h"
 #include "primetab.h"
-#include "primorial.h"
 
 /*----- Main code ---------------------------------------------------------*/
 
@@ -111,7 +120,8 @@ int pfilt_smallfactor(mp *m)
   int rc = PGEN_TRY;
   int i;
   size_t sz = MP_LEN(m);
-  mpw *v = mpalloc(m->a, sz);
+  mparena *a = m->a ? m->a : MPARENA_GLOBAL;
+  mpw *v = mpalloc(a, sz);
 
   /* --- Fill in the residues --- */
 
@@ -131,7 +141,7 @@ int pfilt_smallfactor(mp *m)
 
   /* --- Done --- */
 
-  mpfree(m->a, v);
+  mpfree(a, v);
   return (rc);
 }
 
@@ -153,7 +163,8 @@ int pfilt_create(pfilt *p, mp *m)
   int rc = PGEN_TRY;
   int i;
   size_t sz = MP_LEN(m);
-  mpw *v = mpalloc(m->a, sz);
+  mparena *a = m->a ? m->a : MPARENA_GLOBAL;
+  mpw *v = mpalloc(a, sz);
 
   /* --- Take a copy of the number --- */
 
@@ -179,7 +190,7 @@ int pfilt_create(pfilt *p, mp *m)
 
   /* --- Done --- */
 
-  mpfree(m->a, v);
+  mpfree(a, v);
   return (rc);
 }