From: Jason H Stover Date: Mon, 23 Feb 2009 22:27:07 +0000 (-0500) Subject: covariance-matrix.c: (covariance_accumulator_hash) For categorical X-Git-Tag: v0.7.3~285^2 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=543ef3347c4d15a1609b1f52c312243d465405dc;p=pspp-builds.git covariance-matrix.c: (covariance_accumulator_hash) For categorical variables, eliminate temporary string by using hsh_hash_bytes and XOR. --- diff --git a/src/math/covariance-matrix.c b/src/math/covariance-matrix.c index 88b85051..c419ce02 100644 --- a/src/math/covariance-matrix.c +++ b/src/math/covariance-matrix.c @@ -350,15 +350,10 @@ covariance_accumulator_hash (const void *h, const void *aux) } if (var_is_alpha (v_max) && var_is_alpha (v_min)) { - unsigned int tmp; - char *x = - xnmalloc (1 + var_get_width (v_max) + var_get_width (v_min), - sizeof (*x)); - strncpy (x, val_max->s, var_get_width (v_max)); - strncat (x, val_min->s, var_get_width (v_min)); - tmp = *n_vars * (*n_vars + 1 + idx_max) + idx_min + hsh_hash_string (x); - free (x); - return tmp; + unsigned tmp = hsh_hash_bytes (val_max, var_get_width (v_max)); + tmp ^= hsh_hash_bytes (val_min, var_get_width (v_min)); + tmp += *n_vars * (*n_vars + 1 + idx_max) + idx_min; + return (size_t) tmp; } return -1u; }