{
candidate = obs_vals->vals + i;
assert (candidate != NULL);
- if (!compare_values (candidate, val, v))
+ if (!compare_values_short (candidate, val, v))
{
return i;
}
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_;
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));
+}
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. */
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));
{
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;
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
{
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 */
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);
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;
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++;
}
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;
}
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;
}
}
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;
}
{
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);
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);
{
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);
}
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;
}
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);
}