POLY: rework poly_new()
Don't allocate anything here, just operate on the parameters.
This commit is contained in:
parent
aa01859192
commit
fd0ba50c85
24
src/poly.c
24
src/poly.c
@ -90,22 +90,21 @@ static void poly_mod2_to_modq(fmpz_poly_t a,
|
|||||||
* context ctx and returns a newly allocated polynomial.
|
* context ctx and returns a newly allocated polynomial.
|
||||||
* For an empty polynom, both parameters can be NULL/0.
|
* For an empty polynom, both parameters can be NULL/0.
|
||||||
*
|
*
|
||||||
|
* @param new_poly the polynomial to initialize and
|
||||||
|
* fill with coefficients
|
||||||
* @param c array of polynomial coefficients, can be NULL
|
* @param c array of polynomial coefficients, can be NULL
|
||||||
* @param len size of the coefficient array, can be 0
|
* @param len size of the coefficient array, can be 0
|
||||||
* @return newly allocated polynomial pointer, must be freed
|
* @return newly allocated polynomial pointer, must be freed
|
||||||
* with fmpz_poly_clear()
|
* with fmpz_poly_clear()
|
||||||
*/
|
*/
|
||||||
fmpz_poly_t *poly_new(int const * const c,
|
void poly_new(fmpz_poly_t new_poly,
|
||||||
|
int const * const c,
|
||||||
const size_t len)
|
const size_t len)
|
||||||
{
|
{
|
||||||
fmpz_poly_t *new_poly = ntru_malloc(sizeof(*new_poly));
|
fmpz_poly_init(new_poly);
|
||||||
|
|
||||||
fmpz_poly_init(*new_poly);
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < len; i++)
|
for (unsigned int i = 0; i < len; i++)
|
||||||
fmpz_poly_set_coeff_si(*new_poly, i, c[i]);
|
fmpz_poly_set_coeff_si(new_poly, i, c[i]);
|
||||||
|
|
||||||
return new_poly;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -116,10 +115,9 @@ fmpz_poly_t *poly_new(int const * const c,
|
|||||||
*
|
*
|
||||||
* @param poly the polynomial to delete
|
* @param poly the polynomial to delete
|
||||||
*/
|
*/
|
||||||
void poly_delete(fmpz_poly_t *poly)
|
void poly_delete(fmpz_poly_t poly)
|
||||||
{
|
{
|
||||||
fmpz_poly_clear(*poly);
|
fmpz_poly_clear(poly);
|
||||||
free(poly);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -132,16 +130,16 @@ void poly_delete(fmpz_poly_t *poly)
|
|||||||
* @param poly the polynomial to delete
|
* @param poly the polynomial to delete
|
||||||
* @param ... follow up polynomials
|
* @param ... follow up polynomials
|
||||||
*/
|
*/
|
||||||
void poly_delete_all(fmpz_poly_t *poly, ...)
|
void poly_delete_all(fmpz_poly_t poly, ...)
|
||||||
{
|
{
|
||||||
fmpz_poly_t *next_poly;
|
fmpz_poly_struct *next_poly;
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
next_poly = poly;
|
next_poly = poly;
|
||||||
va_start(args, poly);
|
va_start(args, poly);
|
||||||
while (next_poly != NULL) {
|
while (next_poly != NULL) {
|
||||||
poly_delete(next_poly);
|
poly_delete(next_poly);
|
||||||
next_poly = va_arg(args, fmpz_poly_t*);
|
next_poly = va_arg(args, fmpz_poly_struct*);
|
||||||
}
|
}
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
@ -38,12 +38,13 @@
|
|||||||
#include <fmpz_poly.h>
|
#include <fmpz_poly.h>
|
||||||
|
|
||||||
|
|
||||||
fmpz_poly_t *poly_new(int const * const c,
|
void poly_new(fmpz_poly_t new_poly,
|
||||||
|
int const * const c,
|
||||||
const size_t len);
|
const size_t len);
|
||||||
|
|
||||||
void poly_delete(fmpz_poly_t *poly);
|
void poly_delete(fmpz_poly_t poly);
|
||||||
|
|
||||||
void poly_delete_all(fmpz_poly_t *poly, ...);
|
void poly_delete_all(fmpz_poly_t poly, ...);
|
||||||
|
|
||||||
void fmpz_poly_mod_unsigned(fmpz_poly_t a,
|
void fmpz_poly_mod_unsigned(fmpz_poly_t a,
|
||||||
unsigned int mod);
|
unsigned int mod);
|
||||||
|
Loading…
Reference in New Issue
Block a user