From: Ben Pfaff Date: Sun, 30 Nov 2008 23:26:43 +0000 (-0800) Subject: Rename compare_values, hash_values with "_short" suffix. X-Git-Tag: v0.7.1~50^2~7 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp-builds.git;a=commitdiff_plain;h=16af7ed2b7da4aa1c38a15c5663298d6e251e458 Rename compare_values, hash_values with "_short" suffix. The compare_values and hash_values functions do not compare an entire value. Rather, they compare only the short string prefix of long string values. I have a feeling that this misnaming was confusing people (it certainly confused me) so this commit renames them. It also adds a new function value_compare_3way() that does what one what expect such a function to do. --- diff --git a/src/data/category.c b/src/data/category.c index 7190418c..6771b583 100644 --- a/src/data/category.c +++ b/src/data/category.c @@ -108,7 +108,7 @@ cat_value_find (const struct variable *v, const union value *val) { candidate = obs_vals->vals + i; assert (candidate != NULL); - if (!compare_values (candidate, val, v)) + if (!compare_values_short (candidate, val, v)) { return i; } diff --git a/src/data/value.c b/src/data/value.c index 9fcf1cbb..baaaed48 100644 --- a/src/data/value.c +++ b/src/data/value.c @@ -47,21 +47,20 @@ value_create (int width) Only the short string portion of longer strings are compared. */ int -compare_values (const void *a_, const void *b_, const void *var_) +compare_values_short (const void *a_, const void *b_, const void *var_) { const union value *a = a_; const union value *b = b_; const struct variable *var = var_; int width = var_get_width (var); - return (width == 0 - ? (a->f < b->f ? -1 : a->f > b->f) - : memcmp (a->s, b->s, MIN (MAX_SHORT_STRING, width))); + return value_compare_3way (a, b, MIN (width, MAX_SHORT_STRING)); } + /* Create a hash of V, which has the given WIDTH. Only the short string portion of a longer string is hashed. */ unsigned -hash_value (const void *v_, const void *var_) +hash_value_short (const void *v_, const void *var_) { const union value *v = v_; const struct variable *var = var_; @@ -122,3 +121,13 @@ value_resize (union value *value, int old_width, int new_width) if (new_width > old_width) memset (&value->s[old_width], ' ', new_width - old_width); } + +/* Compares A and B, which both have the given WIDTH, and returns + a strcmp()-type result. */ +int +value_compare_3way (const union value *a, const union value *b, int width) +{ + return (width == 0 + ? (a->f < b->f ? -1 : a->f > b->f) + : memcmp (a->s, b->s, width)); +} diff --git a/src/data/value.h b/src/data/value.h index 9103c6b3..97c24050 100644 --- a/src/data/value.h +++ b/src/data/value.h @@ -42,11 +42,15 @@ union value *value_create (int width); int compare_values (const void *, const void *, const void *var); unsigned hash_value (const void *, const void *var); +int compare_values_short (const void *, const void *, const void *var); +unsigned hash_value_short (const void *, const void *var); + static inline size_t value_cnt_from_width (int width); void value_copy (union value *, const union value *, int width); void value_set_missing (union value *, int width); bool value_is_resizable (const union value *, int old_width, int new_width); void value_resize (union value *, int old_width, int new_width); +int value_compare_3way (const union value *, const union value *, int width); /* Number of "union value"s required for a variable of the given WIDTH. */ diff --git a/src/language/stats/binomial.c b/src/language/stats/binomial.c index 5022cebd..35e619bd 100644 --- a/src/language/stats/binomial.c +++ b/src/language/stats/binomial.c @@ -119,14 +119,14 @@ do_binomial (const struct dictionary *dict, cat1[v].value = value_dup (value, width); cat1[v].count = w; } - else if ( 0 == compare_values (cat1[v].value, value, var)) + else if ( 0 == compare_values_short (cat1[v].value, value, var)) cat1[v].count += w; else if ( NULL == cat2[v].value ) { cat2[v].value = value_dup (value, width); cat2[v].count = w; } - else if ( 0 == compare_values (cat2[v].value, value, var)) + else if ( 0 == compare_values_short (cat2[v].value, value, var)) cat2[v].count += w; else if ( bst->category1 == SYSMIS) msg (ME, _("Variable %s is not dichotomous"), var_get_name (var)); diff --git a/src/language/stats/examine.q b/src/language/stats/examine.q index e341b18a..361a85bd 100644 --- a/src/language/stats/examine.q +++ b/src/language/stats/examine.q @@ -1337,8 +1337,8 @@ show_summary (const struct variable **dependent_var, int n_dep_var, { if ( last_value == NULL || - compare_values (last_value, result->value[0], - fctr->indep_var[0])) + compare_values_short (last_value, result->value[0], + fctr->indep_var[0])) { struct string str; diff --git a/src/language/stats/freq.c b/src/language/stats/freq.c index afad84ee..95285747 100644 --- a/src/language/stats/freq.c +++ b/src/language/stats/freq.c @@ -30,7 +30,7 @@ compare_freq ( const void *_f1, const void *_f2, const void *_var) const struct freq *f2 = _f2; const struct variable *var = _var; - return compare_values (f1->value, f2->value, var ); + return compare_values_short (f1->value, f2->value, var ); } unsigned int @@ -38,7 +38,7 @@ hash_freq (const void *_f, const void *var) { const struct freq *f = _f; - return hash_value (f->value, var); + return hash_value_short (f->value, var); } /* Free function to be used on FR whose value parameter has been copied */ diff --git a/src/language/stats/oneway.q b/src/language/stats/oneway.q index 87a75004..b2e77f45 100644 --- a/src/language/stats/oneway.q +++ b/src/language/stats/oneway.q @@ -907,8 +907,8 @@ run_oneway (struct cmd_oneway *cmd, taint = taint_clone (casereader_get_taint (input)); global_group_hash = hsh_create (4, - compare_values, - hash_value, + compare_values_short, + hash_value_short, free_value, indep_var); diff --git a/src/language/stats/t-test.q b/src/language/stats/t-test.q index 3d278743..6d6dfd56 100644 --- a/src/language/stats/t-test.q +++ b/src/language/stats/t-test.q @@ -1933,10 +1933,10 @@ short which_group (const struct group_statistics *g, const struct group_properties *p) { - if ( 0 == compare_values (&g->id, &p->v.g_value[0], p->indep_var)) + if ( 0 == compare_values_short (&g->id, &p->v.g_value[0], p->indep_var)) return 0; - if ( 0 == compare_values (&g->id, &p->v.g_value[1], p->indep_var)) + if ( 0 == compare_values_short (&g->id, &p->v.g_value[1], p->indep_var)) return 1; return 2; diff --git a/src/math/coefficient.c b/src/math/coefficient.c index f738c783..1f157433 100644 --- a/src/math/coefficient.c +++ b/src/math/coefficient.c @@ -186,8 +186,8 @@ pspp_coeff_var_to_coeff (const struct variable *v, struct pspp_coeff **coefs, if (val != NULL) { j = i; - while (j < n_coef && compare_values (pspp_coeff_get_value (coefs[j], v), - val, v) != 0) + while (j < n_coef && compare_values_short (pspp_coeff_get_value (coefs[j], v), + val, v) != 0) { j++; } diff --git a/src/math/covariance-matrix.c b/src/math/covariance-matrix.c index fb67a64c..32ca9bca 100644 --- a/src/math/covariance-matrix.c +++ b/src/math/covariance-matrix.c @@ -227,7 +227,7 @@ column_iterate (struct design_matrix *cov, const struct variable *v, col += i; y = -1.0 * cat_get_category_count (i, v) / ssize; tmp_val = cat_subscript_to_value (i, v); - if (compare_values (tmp_val, val1, v)) + if (compare_values_short (tmp_val, val1, v)) { y += -1.0; } @@ -262,7 +262,7 @@ covariance_pass_two (struct design_matrix *cov, double mean1, double mean2, row += i; x = -1.0 * cat_get_category_count (i, v1) / ssize; tmp_val = cat_subscript_to_value (i, v1); - if (compare_values (tmp_val, val1, v1)) + if (compare_values_short (tmp_val, val1, v1)) { x += 1.0; } @@ -399,23 +399,23 @@ match_nodes (const struct covariance_accumulator *c, } if (var_is_numeric (v1) && var_is_alpha (v2)) { - if (compare_values (val2, c->val2, v2)) + if (compare_values_short (val2, c->val2, v2)) { return 0; } } if (var_is_alpha (v1) && var_is_numeric (v2)) { - if (compare_values (val1, c->val1, v1)) + if (compare_values_short (val1, c->val1, v1)) { return 0; } } if (var_is_alpha (v1) && var_is_alpha (v2)) { - if (compare_values (val1, c->val1, v1)) + if (compare_values_short (val1, c->val1, v1)) { - if (compare_values (val2, c->val2, v2)) + if (compare_values_short (val2, c->val2, v2)) { return 0; } @@ -689,7 +689,7 @@ covariance_matrix_insert (struct design_matrix *cov, { i = 0; tmp_val = cat_subscript_to_value (i, v1); - while (!compare_values (tmp_val, val1, v1)) + while (!compare_values_short (tmp_val, val1, v1)) { i++; tmp_val = cat_subscript_to_value (i, v1); @@ -704,7 +704,7 @@ covariance_matrix_insert (struct design_matrix *cov, col = design_matrix_var_to_column (cov, v2); i = 0; tmp_val = cat_subscript_to_value (i, v1); - while (!compare_values (tmp_val, val1, v1)) + while (!compare_values_short (tmp_val, val1, v1)) { i++; tmp_val = cat_subscript_to_value (i, v1); diff --git a/src/math/group.c b/src/math/group.c index 6101c350..b5c9e56c 100644 --- a/src/math/group.c +++ b/src/math/group.c @@ -35,7 +35,7 @@ compare_group (const void *a_, { const struct group_statistics *a = a_; const struct group_statistics *b = b_; - return compare_values(&a->id, &b->id, var); + return compare_values_short (&a->id, &b->id, var); } @@ -46,7 +46,7 @@ hash_group (const void *g_, const void *var) unsigned id_hash; const struct group_statistics *g = g_;; - id_hash = hash_value(&g->id, var); + id_hash = hash_value_short (&g->id, var); return id_hash; } diff --git a/src/ui/gui/find-dialog.c b/src/ui/gui/find-dialog.c index 7764d04a..3c54cac4 100644 --- a/src/ui/gui/find-dialog.c +++ b/src/ui/gui/find-dialog.c @@ -464,7 +464,7 @@ value_compare (const struct comparator *cmptr, const union value *v) { const struct value_comparator *vc = (const struct value_comparator *) cmptr; - return 0 == compare_values (v, vc->pattern, cmptr->var); + return 0 == compare_values_short (v, vc->pattern, cmptr->var); }