From 6427af6fd081e477767d4bc3bc9b2a7d7ebb1bbf Mon Sep 17 00:00:00 2001 From: skimo Date: Wed, 17 Nov 2004 15:23:01 +0000 Subject: [PATCH] support multiple divisions and clean up memory --- barvinok.cc | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/barvinok.cc b/barvinok.cc index f2e0bae..5afb226 100644 --- a/barvinok.cc +++ b/barvinok.cc @@ -436,6 +436,39 @@ struct dpoly_r { } //dump(); } + dpoly_r(dpoly_r* num, dpoly& den, int pos, int sign, int dim) { + denom = num->denom; + len = num->len; + c = new vector< dpoly_r_term * > [len]; + this->dim = dim; + int powers[dim]; + ZZ coeff; + + for (int i = 0 ; i < len; ++i) { + for (int k = 0; k < num->c[i].size(); ++k) { + memcpy(powers, num->c[i][k]->powers, dim*sizeof(int)); + powers[pos] += sign; + add_term(i, powers, num->c[i][k]->coeff); + } + + for (int j = 1; j <= i; ++j) { + for (int k = 0; k < c[i-j].size(); ++k) { + memcpy(powers, c[i-j][k]->powers, dim*sizeof(int)); + powers[pos] += sign; + coeff = -den.coeff[j-1] * c[i-j][k]->coeff; + add_term(i, powers, coeff); + } + } + } + } + ~dpoly_r() { + for (int i = 0 ; i < len; ++i) + for (int k = 0; k < c[i].size(); ++k) { + delete [] c[i][k]->powers; + delete c[i][k]; + } + delete [] c; + } dpoly_r *div(dpoly& d) { dpoly_r *rc = new dpoly_r(len, dim); rc->denom = power(d.coeff[0], len); -- 2.11.4.GIT