{
candidate = obs_vals->vals + i;
assert (candidate != NULL);
- if (!compare_values (candidate, val, var_get_width (v)))
+ if (!compare_values (candidate, val, v))
{
return i;
}
#include <data/val-type.h>
#include <libpspp/hash.h>
#include <libpspp/str.h>
+#include "variable.h"
#include "xalloc.h"
Only the short string portion of longer strings are
compared. */
int
-compare_values (const union value *a, const union value *b, int width)
+compare_values (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)));
/* 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 union value *v, int width)
+hash_value (const void *v_, const void *var_)
{
+ const union value *v = v_;
+ const struct variable *var = var_;
+ int width = var_get_width (var);
return (width == 0
? hsh_hash_double (v->f)
- : hsh_hash_bytes (v->s, MIN (MAX_SHORT_STRING, width)));
-}
-
-
-int
-compare_ptr_values (const union value **v1, const union value **v2, int width)
-{
- return compare_values (*v1, *v2, width);
-}
-
-unsigned
-hash_ptr_value (const union value **v, int width)
-{
- return hash_value (*v, width);
+ : hsh_hash_bytes (v->s, width));
}
union value *value_dup (const union value *, int width);
union value *value_create (int width);
-int compare_values (const union value *, const union value *, int width);
-unsigned hash_value (const union value *, int width);
-
-int compare_ptr_values (const union value **, const union value **, int width);
-unsigned hash_ptr_value (const union value **, int width);
-
+int compare_values (const void *, const void *, const void *var);
+unsigned hash_value (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);
cat1[v].value = value_dup (value, width);
cat1[v].count = w;
}
- else if ( 0 == compare_values (cat1[v].value, value, width))
+ else if ( 0 == compare_values (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, width))
+ else if ( 0 == compare_values (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],
- var_get_width(fctr->indep_var[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_get_width (var) );
+ return compare_values (f1->value, f2->value, var );
}
unsigned int
-hash_freq (const void *_f, const void *_var)
+hash_freq (const void *_f, const void *var)
{
const struct freq *f = _f;
- const struct variable *var = _var;
- return hash_value (f->value, var_get_width (var));
+ return hash_value (f->value, var);
}
/* Free function to be used on FR whose value parameter has been copied */
The hash contains a group_statistics structure,
and is keyed by value of the independent variable */
- gp->group_hash =
- hsh_create(4,
- (hsh_compare_func *) compare_group,
- (hsh_hash_func *) hash_group,
- (hsh_free_func *) free_group,
- (void *) var_get_width (indep_var) );
-
+ gp->group_hash = hsh_create(4, compare_group, hash_group,
+ (hsh_free_func *) free_group,
+ indep_var);
totals->sum=0;
totals->n=0;
taint = taint_clone (casereader_get_taint (input));
global_group_hash = hsh_create(4,
- (hsh_compare_func *) compare_values,
- (hsh_hash_func *) hash_value,
+ compare_values,
+ hash_value,
free_value,
- (void *) var_get_width (indep_var) );
+ indep_var);
precalc(cmd);
struct group_statistics *gs;
- gs = hsh_find(group_hash, (void *) indep_val );
+ gs = hsh_find (group_hash, indep_val );
if ( ! gs )
{
gs->minimum = DBL_MAX;
gs->maximum = -DBL_MAX;
- hsh_insert ( group_hash, (void *) gs );
+ hsh_insert ( group_hash, gs );
}
if (!var_is_value_missing (v, val, exclude))
/* The comparison criterion */
enum comparison criterion;
- /* The width of the independent variable */
- int indep_width ;
+ /* The independent variable */
+ struct variable *indep_var;
union {
/* The value of the independent variable at which groups are determined to
/* There's always 2 groups for a T - TEST */
ttpr->n_groups = 2;
- gp.indep_width = var_get_width (indep_var);
+ gp.indep_var = indep_var;
ttpr->group_hash = hsh_create (2,
(hsh_compare_func *) compare_group_binary,
if ( p->criterion == CMP_LE )
{
- /* less-than comparision is not meaningfull for
- alpha variables, so we shouldn't ever arrive here */
- assert (p->indep_width == 0 ) ;
-
flag_a = ( a->id.f < p->v.critical_value ) ;
flag_b = ( b->id.f < p->v.critical_value ) ;
}
if ( p->criterion == CMP_LE )
{
- /* Not meaningfull to do a less than compare for alpha values ? */
- assert (p->indep_width == 0 ) ;
flag = ( g->id.f < p->v.critical_value ) ;
}
else if ( p->criterion == CMP_EQ)
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_width))
+ if ( 0 == compare_values (&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_width))
+ if ( 0 == compare_values (&g->id, &p->v.g_value[1], p->indep_var))
return 1;
return 2;
size_t i = 0;
size_t j = 0;
size_t v_idx;
- int found = 0;
+
struct pspp_coeff *result = NULL;
if (v != NULL)
{
j = i;
while (j < n_coef && compare_values (pspp_coeff_get_value (coefs[j], v),
- val, var_get_width (v)) != 0)
+ 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, var_get_width (v)))
+ if (compare_values (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, var_get_width (v1)))
+ if (compare_values (tmp_val, val1, v1))
{
x += 1.0;
}
/* Return -1 if the id of a is less than b; +1 if greater than and
0 if equal */
int
-compare_group (const struct group_statistics *a,
- const struct group_statistics *b,
- int width)
+compare_group (const void *a_,
+ const void *b_,
+ const void *var)
{
- return compare_values(&a->id, &b->id, width);
+ const struct group_statistics *a = a_;
+ const struct group_statistics *b = b_;
+ return compare_values(&a->id, &b->id, var);
}
-unsigned
-hash_group (const struct group_statistics *g, int width)
+unsigned int
+hash_group (const void *g_, const void *var)
{
unsigned id_hash;
+ const struct group_statistics *g = g_;;
- id_hash = hash_value(&g->id, width);
+ id_hash = hash_value(&g->id, var);
return id_hash;
}
#ifndef GROUP_H
#define GROUP_H
-
#include <data/value.h>
-
/* Statistics for grouped data */
struct group_statistics
{
};
-
+struct variable ;
/* These funcs are useful for hash tables */
/* Return -1 if the id of a is less than b; +1 if greater than and
0 if equal */
-int compare_group (const struct group_statistics *a,
- const struct group_statistics *b,
- int width);
+int compare_group (const void *a,
+ const void *b,
+ const void *var);
-unsigned hash_group (const struct group_statistics *g, int width);
+unsigned int hash_group (const void *g, const void *var);
void free_group (struct group_statistics *v, void *aux);
const union value *v)
{
const struct value_comparator *vc = (const struct value_comparator *) cmptr;
- return 0 == compare_values (v, vc->pattern, var_get_width (cmptr->var));
+ return 0 == compare_values (v, vc->pattern, cmptr->var);
}