Some code used the result of var_get_dict_index() on a pair of variables to
tell whether the variables are the same. This is unnecessary: v1 == v2
works just as well.
Other code used the result of var_get_dict_index() as part of a hash value
computation. This is reasonable, but it is even better just to hash the
pointer to the variable.
/* PSPP - a program for statistical analysis.
/* PSPP - a program for statistical analysis.
- Copyright (C) 2005, 2009 Free Software Foundation, Inc.
+ Copyright (C) 2005, 2009, 2010 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
{
size_t i = 0;
size_t j = 0;
{
size_t i = 0;
size_t j = 0;
struct pspp_coeff *result = NULL;
if (v != NULL)
{
struct pspp_coeff *result = NULL;
if (v != NULL)
{
- v_idx = var_get_dict_index (v);
while (i < n_coef)
{
if (coefs[i]->v_info != NULL)
{
while (i < n_coef)
{
if (coefs[i]->v_info != NULL)
{
- if (var_get_dict_index (coefs[i]->v_info->v) == v_idx)
+ if (coefs[i]->v_info->v == v)
/* PSPP - a program for statistical analysis.
/* PSPP - a program for statistical analysis.
- Copyright (C) 2008, 2009 Free Software Foundation, Inc.
+ Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
{
struct covariance_accumulator *ca = (struct covariance_accumulator *) h;
size_t *n_vars = (size_t *) aux;
{
struct covariance_accumulator *ca = (struct covariance_accumulator *) h;
size_t *n_vars = (size_t *) aux;
- size_t idx_max;
- size_t idx_min;
const struct variable *v_min;
const struct variable *v_max;
const union value *val_min;
const union value *val_max;
/*
const struct variable *v_min;
const struct variable *v_max;
const union value *val_min;
const union value *val_max;
/*
- Order everything by the variables' indices. This ensures we get the
+ Order everything by the variables' addresses. This ensures we get the
same key regardless of the order in which the variables are stored
and passed around.
*/
same key regardless of the order in which the variables are stored
and passed around.
*/
- v_min =
- (var_get_dict_index (ca->v1) <
- var_get_dict_index (ca->v2)) ? ca->v1 : ca->v2;
- v_max = (ca->v1 == v_min) ? ca->v2 : ca->v1;
-
- val_min = (v_min == ca->v1) ? ca->val1 : ca->val2;
- val_max = (ca->val1 == val_min) ? ca->val2 : ca->val1;
-
- idx_min = var_get_dict_index (v_min);
- idx_max = var_get_dict_index (v_max);
+ if (ca->v1 < ca->v2)
+ {
+ v_min = ca->v1;
+ v_max = ca->v2;
+ val_min = ca->val1;
+ val_max = ca->val2;
+ }
+ else
+ {
+ v_min = ca->v2;
+ v_max = ca->v2;
+ val_min = ca->val2;
+ val_max = ca->val1;
+ }
if (var_is_numeric (v_max) && var_is_numeric (v_min))
{
if (var_is_numeric (v_max) && var_is_numeric (v_min))
{
- return (*n_vars * idx_max + idx_min);
+ return hash_pointer (v_min, hash_pointer (v_max, 0));
}
if (var_is_numeric (v_max) && var_is_alpha (v_min))
{
}
if (var_is_numeric (v_max) && var_is_alpha (v_min))
{
{
unsigned hash = value_hash (val_max, var_get_width (v_max), 0);
hash = value_hash (val_min, var_get_width (v_min), hash);
{
unsigned hash = value_hash (val_max, var_get_width (v_max), 0);
hash = value_hash (val_min, var_get_width (v_min), hash);
- return hash_int (*n_vars * (*n_vars + 1 + idx_max) + idx_min, hash);
+ hash = hash_pointer (v_min, hash);
+ return hash_pointer (v_max, hash);
ordered_match_nodes (const struct covariance_accumulator *c, const struct variable *v1,
const struct variable *v2, const union value *val1, const union value *val2)
{
ordered_match_nodes (const struct covariance_accumulator *c, const struct variable *v1,
const struct variable *v2, const union value *val1, const union value *val2)
{
- size_t result;
- size_t m;
-
- result = var_get_dict_index (v1) ^ var_get_dict_index (c->v1);
- m = var_get_dict_index (v2) ^ var_get_dict_index (c->v2);
- result = result|m;
- if (var_is_alpha (v1))
- {
- result |= value_compare_3way (val1, c->val1, var_get_width (v1));
- if (var_is_alpha (v2))
- {
- result |= value_compare_3way (val2, c->val2, var_get_width (v2));
- }
- }
- else if (var_is_alpha (v2))
- {
- result |= value_compare_3way (val2, c->val2, var_get_width (v2));
- }
- return result;
+ return (v1 != c->v1
+ || v2 != c->v2
+ || (var_is_alpha (v1)
+ && !value_equal (val1, c->val1, var_get_width (v1)))
+ || (var_is_alpha (v2)
+ && !value_equal (val2, c->val2, var_get_width (v2))));
const struct variable *v1, const struct variable *v2,
const union value *val1, const union value *val2)
{
const struct variable *v1, const struct variable *v2,
const union value *val1, const union value *val2)
{
- size_t n;
- size_t m;
-
- n = ordered_match_nodes (c, v1, v2, val1, val2);
- m = ordered_match_nodes (c, v2, v1, val2, val1);
- return (n & m);
+ return (ordered_match_nodes (c, v1, v2, val1, val2)
+ && ordered_match_nodes (c, v2, v1, val2, val1));
unsigned int result = -1u;
if (var_is_numeric (v1) && var_is_alpha (v2))
{
unsigned int result = -1u;
if (var_is_numeric (v1) && var_is_alpha (v2))
{
- result = n_vars * ((n_vars + 1) + var_get_dict_index (v1))
- + var_get_dict_index (v2) + value_hash (val, var_get_width (v2), 0);
+ result = hash_pointer (v1, 0);
+ result = hash_pointer (v2, result);
+ result = value_hash (val, var_get_width (v2), result);
}
else if (var_is_alpha (v1) && var_is_numeric (v2))
{
}
else if (var_is_alpha (v1) && var_is_numeric (v2))
{
assert (dm != NULL);
v1 = design_matrix_col_to_var (dm, i);
v2 = design_matrix_col_to_var (dm, j);
assert (dm != NULL);
v1 = design_matrix_col_to_var (dm, i);
v2 = design_matrix_col_to_var (dm, j);
- if (var_get_dict_index (v1) == var_get_dict_index(ca->v1))
- if (var_get_dict_index (v2) == var_get_dict_index (ca->v2))
{
k = dm_get_exact_subscript (dm, v1, ca->val1);
if (k == i)
{
k = dm_get_exact_subscript (dm, v1, ca->val1);
if (k == i)
- else if (var_get_dict_index (v1) == var_get_dict_index (ca->v2))
- if (var_get_dict_index (v2) == var_get_dict_index (ca->v1))
{
k = dm_get_exact_subscript (dm, v1, ca->val2);
if (k == i)
{
k = dm_get_exact_subscript (dm, v1, ca->val2);
if (k == i)
const struct variable *var;
double tmp;
var = design_matrix_col_to_var (dm, i);
const struct variable *var;
double tmp;
var = design_matrix_col_to_var (dm, i);
- if (var_get_dict_index (ca->v1) == var_get_dict_index (var))
{
var = design_matrix_col_to_var (dm, j);
{
var = design_matrix_col_to_var (dm, j);
- if (var_get_dict_index (ca->v2) == var_get_dict_index (var))
{
tmp = design_matrix_get_element (dm, i, j);
tmp += ca->ssize;
{
tmp = design_matrix_get_element (dm, i, j);
tmp += ca->ssize;
for (i = 0; i < n_intr; i++)
{
intr = interaction_get_variable (iv[i]);
for (i = 0; i < n_intr; i++)
{
intr = interaction_get_variable (iv[i]);
- if (var_get_dict_index (intr) == var_get_dict_index (var))