From 867281924841dc1b8b4050d5a4ed5408da5812cf Mon Sep 17 00:00:00 2001 From: vub Date: Sun, 23 Apr 2017 20:15:16 -0400 Subject: [PATCH] A bit more minor optimization --- erasure_code/ec65536/poly_utils.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/erasure_code/ec65536/poly_utils.cpp b/erasure_code/ec65536/poly_utils.cpp index 06a5110..f086aa0 100644 --- a/erasure_code/ec65536/poly_utils.cpp +++ b/erasure_code/ec65536/poly_utils.cpp @@ -159,10 +159,10 @@ vector subroot_linear_combination(vector xs, vector factors) { } -vector derivative(vector p) { - vector o(p.size() - 1); - for (int i = 0; i < o.size(); i+= 2) { - o[i] = p[i + 1]; +vector derivative_and_square_base(vector p) { + vector o((p.size() - 1) / 2); + for (int i = 0; i < o.size(); i+= 1) { + o[i] = p[i * 2 + 1]; } return o; } @@ -181,10 +181,11 @@ vector poly_to_logs(vector p) { vector lagrange_interp(vector ys, vector xs) { int xs_size = xs.size(); vector root = mk_root(xs); - vector log_rootprime = poly_to_logs(derivative(root)); + vector log_rootprime = poly_to_logs(derivative_and_square_base(root)); vector factors(xs_size); for (int i = 0; i < xs_size; i++) { - int denom = eval_log_poly_at(log_rootprime, xs[i]); + int x_square = xs[i] ? gexptable[glogtable[xs[i]] * 2] : 0; + int denom = eval_log_poly_at(log_rootprime, x_square); if (ys[i]) factors[i] = gexptable[glogtable[ys[i]] + 65535 - glogtable[denom]]; }