-/* PSPP - computes sample statistics.
- Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
- Written by Ben Pfaff <blp@gnu.org>.
+/* PSPP - a program for statistical analysis.
+ Copyright (C) 1997-9, 2000, 2009, 2010, 2011, 2012 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 the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
+ 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
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA. */
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
-#include "value-labels.h"
+#include "data/value-labels.h"
#include <stdlib.h>
-#include <data/data-out.h>
-#include <data/variable.h>
-#include <libpspp/alloc.h>
-#include <libpspp/compiler.h>
-#include <libpspp/hash.h>
-#include <libpspp/message.h>
-#include <libpspp/str.h>
-
-static hsh_compare_func compare_int_val_lab;
-static hsh_hash_func hash_int_val_lab;
-static hsh_free_func free_int_val_lab;
-
-struct atom;
-static struct atom *atom_create (const char *string);
-static void atom_destroy (struct atom *);
-static char *atom_to_string (const struct atom *);
-
-/* A set of value labels. */
-struct val_labs
- {
- int width; /* 0=numeric, otherwise string width. */
- struct hsh_table *labels; /* Hash table of `struct int_val_lab's. */
- };
+#include "data/data-out.h"
+#include "data/value.h"
+#include "data/variable.h"
+#include "libpspp/array.h"
+#include "libpspp/cast.h"
+#include "libpspp/compiler.h"
+#include "libpspp/hash-functions.h"
+#include "libpspp/hmap.h"
+#include "libpspp/intern.h"
+#include "libpspp/message.h"
+#include "libpspp/str.h"
+
+#include "gl/xalloc.h"
/* Creates and returns a new, empty set of value labels with the
- given WIDTH. To actually add any value labels, WIDTH must be
- a numeric or short string width. */
+ given WIDTH. */
struct val_labs *
-val_labs_create (int width)
+val_labs_create (int width)
{
- struct val_labs *vls;
-
- assert (width >= 0);
-
- vls = xmalloc (sizeof *vls);
+ struct val_labs *vls = xmalloc (sizeof *vls);
vls->width = width;
- vls->labels = NULL;
+ hmap_init (&vls->labels);
return vls;
}
/* Creates and returns a new set of value labels identical to
- VLS. */
+ VLS. Returns a null pointer if VLS is null. */
struct val_labs *
-val_labs_copy (const struct val_labs *vls)
+val_labs_clone (const struct val_labs *vls)
{
struct val_labs *copy;
- struct val_labs_iterator *i;
- struct val_lab *vl;
+ struct val_lab *label;
- assert (vls != NULL);
+ if (vls == NULL)
+ return NULL;
copy = val_labs_create (vls->width);
- for (vl = val_labs_first (vls, &i); vl != NULL;
- vl = val_labs_next (vls, &i))
- val_labs_add (copy, vl->value, vl->label);
+ HMAP_FOR_EACH (label, struct val_lab, node, &vls->labels)
+ val_labs_add (copy, &label->value, label->escaped_label);
return copy;
}
-/* Determines whether VLS's width can be changed to NEW_WIDTH.
- Numeric widths cannot be changed at all.
- Strings can be widened. They can be shortened only if the
- characters that will be truncated are spaces. */
+/* Determines whether VLS's width can be changed to NEW_WIDTH,
+ using the rules checked by value_is_resizable. */
bool
-val_labs_can_set_width (const struct val_labs *vls, int new_width)
+val_labs_can_set_width (const struct val_labs *vls, int new_width)
{
- assert ((vls->width == 0) == (new_width == 0));
+ struct val_lab *label;
- if (vls->width == 0)
- return new_width == 0;
- else if (new_width < vls->width)
- {
- struct val_labs_iterator *i;
- struct val_lab *lab;
+ HMAP_FOR_EACH (label, struct val_lab, node, &vls->labels)
+ if (!value_is_resizable (&label->value, vls->width, new_width))
+ return false;
- for (lab = val_labs_first (vls, &i); lab != NULL;
- lab = val_labs_next (vls, &i))
- {
- int j;
-
- /* We can shorten the value labels only if all the
- truncated characters are blanks. */
- for (j = vls->width; j < new_width; j++)
- if (lab->value.s[j] != ' ')
- {
- val_labs_done (&i);
- return false;
- }
- }
- return true;
- }
- else
- return true;
+ return true;
}
-/* Changes the width of VLS to NEW_WIDTH. If VLS is numeric,
- NEW_WIDTH must be 0, otherwise it must be within the range
- 1...MAX_SHORT_STRING inclusive. */
+/* Changes the width of VLS to NEW_WIDTH. The original and new
+ width must be both numeric or both string. */
void
-val_labs_set_width (struct val_labs *vls, int new_width)
+val_labs_set_width (struct val_labs *vls, int new_width)
{
assert (val_labs_can_set_width (vls, new_width));
-
+ if (value_needs_resize (vls->width, new_width))
+ {
+ struct val_lab *label;
+ HMAP_FOR_EACH (label, struct val_lab, node, &vls->labels)
+ value_resize (&label->value, vls->width, new_width);
+ }
vls->width = new_width;
- if (new_width > MAX_SHORT_STRING)
- val_labs_clear (vls);
}
/* Destroys VLS. */
void
-val_labs_destroy (struct val_labs *vls)
+val_labs_destroy (struct val_labs *vls)
{
- if (vls != NULL)
+ if (vls != NULL)
{
- hsh_destroy (vls->labels);
+ val_labs_clear (vls);
+ hmap_destroy (&vls->labels);
free (vls);
}
}
/* Removes all the value labels from VLS. */
void
-val_labs_clear (struct val_labs *vls)
+val_labs_clear (struct val_labs *vls)
{
- assert (vls != NULL);
+ struct val_lab *label, *next;
- hsh_destroy (vls->labels);
- vls->labels = NULL;
+ HMAP_FOR_EACH_SAFE (label, next, struct val_lab, node, &vls->labels)
+ {
+ hmap_delete (&vls->labels, &label->node);
+ value_destroy (&label->value, vls->width);
+ intern_unref (label->label);
+ intern_unref (label->escaped_label);
+ free (label);
+ }
}
-/* Returns the number of value labels in VLS. */
-size_t
-val_labs_count (const struct val_labs *vls)
+/* Returns the width of VLS. */
+int
+val_labs_get_width (const struct val_labs *vls)
{
- assert (vls != NULL);
-
- if (vls->labels == NULL)
- return 0;
- else
- return hsh_count (vls->labels);
+ return vls->width;
}
-\f
-/* One value label in internal format. */
-struct int_val_lab
- {
- union value value; /* The value being labeled. */
- struct atom *label; /* A ref-counted string. */
- };
-
-/* Creates and returns an int_val_lab based on VALUE and
- LABEL. */
-static struct int_val_lab *
-create_int_val_lab (struct val_labs *vls, union value value, const char *label)
+
+/* Returns the number of value labels in VLS.
+ Returns 0 if VLS is null. */
+size_t
+val_labs_count (const struct val_labs *vls)
{
- struct int_val_lab *ivl;
-
- assert (label != NULL);
- assert (vls->width <= MAX_SHORT_STRING);
-
- ivl = xmalloc (sizeof *ivl);
- ivl->value = value;
- if (vls->width > 0)
- memset (ivl->value.s + vls->width, ' ', MAX_SHORT_STRING - vls->width);
- ivl->label = atom_create (label);
-
- return ivl;
+ return vls == NULL ? 0 : hmap_count (&vls->labels);
}
-
-/* If VLS does not already contain a value label for VALUE, adds
- LABEL for it and returns true. Otherwise, returns false.
- Behavior is undefined if VLS's width is greater than
- MAX_SHORT_STRING. */
-bool
-val_labs_add (struct val_labs *vls, union value value, const char *label)
+\f
+static void
+set_label (struct val_lab *lab, const char *escaped_label)
{
- struct int_val_lab *ivl;
- void **vlpp;
-
- assert (vls != NULL);
- assert (vls->width <= MAX_SHORT_STRING);
- assert (label != NULL);
-
- if (vls->labels == NULL)
- vls->labels = hsh_create (8, compare_int_val_lab, hash_int_val_lab,
- free_int_val_lab, vls);
-
- ivl = create_int_val_lab (vls, value, label);
- vlpp = hsh_probe (vls->labels, ivl);
- if (*vlpp == NULL)
+ lab->escaped_label = intern_new (escaped_label);
+ if (strstr (escaped_label, "\\n") == NULL)
+ lab->label = intern_ref (lab->escaped_label);
+ else
{
- *vlpp = ivl;
- return true;
+ struct string s;
+ const char *p;
+
+ ds_init_empty (&s);
+ ds_extend (&s, intern_strlen (lab->escaped_label));
+ for (p = escaped_label; *p != '\0'; p++)
+ {
+ char c = *p;
+ if (c == '\\' && p[1] == 'n')
+ {
+ c = '\n';
+ p++;
+ }
+ ds_put_byte (&s, c);
+ }
+ lab->label = intern_new (ds_cstr (&s));
+ ds_destroy (&s);
}
- free_int_val_lab (ivl, vls);
- return false;
}
-/* Sets LABEL as the value label for VALUE in VLS. Returns false
- if there wasn't already a value label for VALUE, or true if
- there was. Behavior is undefined if VLS's width is greater
- than MAX_SHORT_STRING. */
-bool
-val_labs_replace (struct val_labs *vls, union value value, const char *label)
+static void
+do_add_val_lab (struct val_labs *vls, const union value *value,
+ const char *escaped_label)
{
- struct int_val_lab *ivl;
-
- assert (vls != NULL);
- assert (vls->width <= MAX_SHORT_STRING);
- assert (label != NULL);
+ struct val_lab *lab = xmalloc (sizeof *lab);
+ value_clone (&lab->value, value, vls->width);
+ set_label (lab, escaped_label);
+ hmap_insert (&vls->labels, &lab->node, value_hash (value, vls->width, 0));
+}
- if (vls->labels == NULL)
- {
- val_labs_add (vls, value, label);
- return false;
- }
+/* If VLS does not already contain a value label for VALUE, adds the UTF-8
+ encoded LABEL for it and returns true. Otherwise, returns false.
- ivl = hsh_replace (vls->labels, create_int_val_lab (vls, value, label));
- if (ivl == NULL)
- return false;
- else
+ In LABEL, the two-byte sequence "\\n" is interpreted as a new-line. */
+bool
+val_labs_add (struct val_labs *vls, const union value *value,
+ const char *label)
+{
+ const struct val_lab *lab = val_labs_lookup (vls, value);
+ if (lab == NULL)
{
- free_int_val_lab (ivl, vls);
+ do_add_val_lab (vls, value, label);
return true;
}
+ else
+ return false;
}
-/* Removes any value label for VALUE within VLS. Returns true
- if a value label was removed. Behavior is undefined if VLS's
- width is greater than MAX_SHORT_STRING. */
-bool
-val_labs_remove (struct val_labs *vls, union value value)
-{
- assert (vls != NULL);
- assert (vls->width <= MAX_SHORT_STRING);
+/* Sets LABEL as the value label for VALUE in VLS, replacing any
+ existing label for VALUE.
- if (vls->labels != NULL)
+ In LABEL, the two-byte sequence "\\n" is interpreted as a new-line. */
+void
+val_labs_replace (struct val_labs *vls, const union value *value,
+ const char *label)
+{
+ struct val_lab *vl = val_labs_lookup (vls, value);
+ if (vl != NULL)
{
- struct int_val_lab *ivl = create_int_val_lab (vls, value, "");
- int deleted = hsh_delete (vls->labels, ivl);
- free (ivl);
- return deleted;
+ intern_unref (vl->label);
+ intern_unref (vl->escaped_label);
+ set_label (vl, label);
}
else
- return false;
+ do_add_val_lab (vls, value, label);
}
-/* Searches VLS for a value label for VALUE. If successful,
- returns the label; otherwise, returns a null pointer. If
- VLS's width is greater than MAX_SHORT_STRING, always returns a
- null pointer. */
-char *
-val_labs_find (const struct val_labs *vls, union value value)
+/* Removes LABEL from VLS. */
+void
+val_labs_remove (struct val_labs *vls, struct val_lab *label)
{
- assert (vls != NULL);
-
- if (vls->width > MAX_SHORT_STRING)
- return NULL;
-
- if (vls->labels != NULL)
- {
- struct int_val_lab ivl, *vlp;
-
- ivl.value = value;
- vlp = hsh_find (vls->labels, &ivl);
- if (vlp != NULL)
- return atom_to_string (vlp->label);
- }
- return NULL;
+ hmap_delete (&vls->labels, &label->node);
+ value_destroy (&label->value, vls->width);
+ intern_unref (label->label);
+ intern_unref (label->escaped_label);
+ free (label);
}
-\f
-/* A value labels iterator. */
-struct val_labs_iterator
- {
- void **labels; /* The labels, in order. */
- void **lp; /* Current label. */
- struct val_lab vl; /* Structure presented to caller. */
- };
-
-/* Sets up *IP for iterating through the value labels in VLS in
- no particular order. Returns the first value label or a null
- pointer if VLS is empty. If the return value is non-null,
- then val_labs_next() may be used to continue iterating or
- val_labs_done() to free up the iterator. Otherwise, neither
- function may be called for *IP. */
-struct val_lab *
-val_labs_first (const struct val_labs *vls, struct val_labs_iterator **ip)
+
+/* Searches VLS for a value label for VALUE. If successful, returns the string
+ used as the label, as a UTF-8 encoded string in a format suitable for
+ output. Otherwise, returns a null pointer. Returns a null pointer if VLS
+ is null. */
+const char *
+val_labs_find (const struct val_labs *vls, const union value *value)
{
- struct val_labs_iterator *i;
+ const struct val_lab *label = val_labs_lookup (vls, value);
+ return label ? label->label : NULL;
+}
- assert (vls != NULL);
- assert (ip != NULL);
+/* Searches VLS for a value label for VALUE. If successful,
+ returns the value label; otherwise, returns a null pointer.
+ Returns a null pointer if VLS is null. */
+static struct val_lab *
+val_labs_lookup__ (const struct val_labs *vls, const union value *value,
+ unsigned int hash)
+{
+ struct val_lab *label;
- if (vls->labels == NULL || vls->width > MAX_SHORT_STRING)
- return NULL;
+ HMAP_FOR_EACH_WITH_HASH (label, struct val_lab, node, hash, &vls->labels)
+ if (value_equal (&label->value, value, vls->width))
+ return label;
- i = *ip = xmalloc (sizeof *i);
- i->labels = hsh_data_copy (vls->labels);
- i->lp = i->labels;
- return val_labs_next (vls, ip);
+ return NULL;
}
-/* Sets up *IP for iterating through the value labels in VLS in
- sorted order of values. Returns the first value label or a
- null pointer if VLS is empty. If the return value is
- non-null, then val_labs_next() may be used to continue
- iterating or val_labs_done() to free up the iterator.
- Otherwise, neither function may be called for *IP. */
+/* Searches VLS for a value label for VALUE. If successful,
+ returns the value label; otherwise, returns a null pointer.
+ Returns a null pointer if VLS is null. */
struct val_lab *
-val_labs_first_sorted (const struct val_labs *vls,
- struct val_labs_iterator **ip)
+val_labs_lookup (const struct val_labs *vls, const union value *value)
{
- struct val_labs_iterator *i;
-
- assert (vls != NULL);
- assert (ip != NULL);
+ return (vls == NULL ? NULL
+ : val_labs_lookup__ (vls, value, value_hash (value, vls->width, 0)));
+}
- if (vls->labels == NULL || vls->width > MAX_SHORT_STRING)
- return NULL;
+/* Searches VLS for a value label whose label is exactly LABEL. If successful,
+ returns the corresponding value. Otherwise, returns a null pointer.
- i = *ip = xmalloc (sizeof *i);
- i->lp = i->labels = hsh_sort_copy (vls->labels);
- return val_labs_next (vls, ip);
-}
+ Returns a null pointer if VLS is null.
-/* Returns the next value label in an iteration begun by
- val_labs_first() or val_labs_first_sorted(). If the return
- value is non-null, then val_labs_next() may be used to
- continue iterating or val_labs_done() to free up the iterator.
- Otherwise, neither function may be called for *IP. */
-struct val_lab *
-val_labs_next (const struct val_labs *vls, struct val_labs_iterator **ip)
+ This function is O(n) in the number of labels in VLS. */
+const union value *
+val_labs_find_value (const struct val_labs *vls, const char *label_)
{
- struct val_labs_iterator *i;
- struct int_val_lab *ivl;
-
- assert (vls != NULL);
- assert (vls->width <= MAX_SHORT_STRING);
- assert (ip != NULL);
- assert (*ip != NULL);
-
- i = *ip;
- ivl = *i->lp++;
- if (ivl != NULL)
- {
- i->vl.value = ivl->value;
- i->vl.label = atom_to_string (ivl->label);
- return &i->vl;
- }
- else
+ const union value *value = NULL;
+
+ if (vls != NULL)
{
- free (i->labels);
- free (i);
- *ip = NULL;
- return NULL;
+ const struct val_lab *vl;
+ const char *label;
+
+ label = intern_new (label_);
+ HMAP_FOR_EACH (vl, struct val_lab, node, &vls->labels)
+ if (vl->label == label)
+ {
+ value = &vl->value;
+ break;
+ }
+ intern_unref (label);
}
-}
-/* Discards the state for an incomplete iteration begun by
- val_labs_first() or val_labs_first_sorted(). */
-void
-val_labs_done (struct val_labs_iterator **ip)
-{
- struct val_labs_iterator *i;
-
- assert (ip != NULL);
- assert (*ip != NULL);
-
- i = *ip;
- free (i->labels);
- free (i);
- *ip = NULL;
+ return value;
}
\f
-/* Compares two value labels and returns a strcmp()-type result. */
-int
-compare_int_val_lab (const void *a_, const void *b_, const void *vls_)
+/* Returns the first value label in VLS, in arbitrary order, or a
+ null pointer if VLS is empty or if VLS is a null pointer. If
+ the return value is non-null, then val_labs_next() may be used
+ to continue iterating. */
+const struct val_lab *
+val_labs_first (const struct val_labs *vls)
{
- const struct int_val_lab *a = a_;
- const struct int_val_lab *b = b_;
- const struct val_labs *vls = vls_;
-
- if (vls->width == 0)
- return a->value.f < b->value.f ? -1 : a->value.f > b->value.f;
- else
- return memcmp (a->value.s, b->value.s, vls->width);
+ return vls ? HMAP_FIRST (struct val_lab, node, &vls->labels) : NULL;
}
-/* Hash a value label. */
-unsigned
-hash_int_val_lab (const void *vl_, const void *vls_)
+/* Returns the next value label in an iteration begun by
+ val_labs_first(). If the return value is non-null, then
+ val_labs_next() may be used to continue iterating. */
+const struct val_lab *
+val_labs_next (const struct val_labs *vls, const struct val_lab *label)
{
- const struct int_val_lab *vl = vl_;
- const struct val_labs *vls = vls_;
-
- if (vls->width == 0)
- return hsh_hash_double (vl->value.f);
- else
- return hsh_hash_bytes (vl->value.s, sizeof vl->value.s);
+ return HMAP_NEXT (label, struct val_lab, node, &vls->labels);
}
-/* Free a value label. */
-void
-free_int_val_lab (void *vl_, const void *vls_ UNUSED)
+static int
+compare_labels_by_value_3way (const void *a_, const void *b_, const void *vls_)
{
- struct int_val_lab *vl = vl_;
-
- atom_destroy (vl->label);
- free (vl);
+ const struct val_lab *const *a = a_;
+ const struct val_lab *const *b = b_;
+ const struct val_labs *vls = vls_;
+ return value_compare_3way (&(*a)->value, &(*b)->value, vls->width);
}
-\f
-/* Atoms. */
-
-/* An atom. */
-struct atom
- {
- char *string; /* String value. */
- unsigned ref_count; /* Number of references. */
- };
-
-static hsh_compare_func compare_atoms;
-static hsh_hash_func hash_atom;
-static hsh_free_func free_atom;
-/* Hash table of atoms. */
-static struct hsh_table *atoms;
-
-/* Creates and returns an atom for STRING. */
-static struct atom *
-atom_create (const char *string)
+/* Allocates and returns an array of pointers to value labels
+ that is sorted in increasing order by value. The array has
+ val_labs_count(VLS) elements. The caller is responsible for
+ freeing the array. */
+const struct val_lab **
+val_labs_sorted (const struct val_labs *vls)
{
- struct atom a;
- void **app;
-
- assert (string != NULL);
-
- if (atoms == NULL)
- atoms = hsh_create (8, compare_atoms, hash_atom, free_atom, NULL);
-
- a.string = (char *) string;
- app = hsh_probe (atoms, &a);
- if (*app != NULL)
+ if (vls != NULL)
{
- struct atom *ap = *app;
- ap->ref_count++;
- return ap;
+ const struct val_lab *label;
+ const struct val_lab **labels;
+ size_t i;
+
+ labels = xmalloc (val_labs_count (vls) * sizeof *labels);
+ i = 0;
+ HMAP_FOR_EACH (label, struct val_lab, node, &vls->labels)
+ labels[i++] = label;
+ assert (i == val_labs_count (vls));
+ sort (labels, val_labs_count (vls), sizeof *labels,
+ compare_labels_by_value_3way, vls);
+ return labels;
}
else
- {
- struct atom *ap = xmalloc (sizeof *ap);
- ap->string = xstrdup (string);
- ap->ref_count = 1;
- *app = ap;
- return ap;
- }
-}
-
-/* Destroys ATOM. */
-static void
-atom_destroy (struct atom *atom)
-{
- if (atom != NULL)
- {
- assert (atom->ref_count > 0);
- atom->ref_count--;
- if (atom->ref_count == 0)
- hsh_force_delete (atoms, atom);
- }
-}
-
-/* Returns the string associated with ATOM. */
-static char *
-atom_to_string (const struct atom *atom)
-{
- assert (atom != NULL);
-
- return atom->string;
-}
-
-/* A hsh_compare_func that compares A and B. */
-static int
-compare_atoms (const void *a_, const void *b_, const void *aux UNUSED)
-{
- const struct atom *a = a_;
- const struct atom *b = b_;
-
- return strcmp (a->string, b->string);
+ return NULL;
}
-/* A hsh_hash_func that hashes ATOM. */
-static unsigned
-hash_atom (const void *atom_, const void *aux UNUSED)
+/* Returns a hash value that represents all of the labels in VLS, starting from
+ BASIS. */
+unsigned int
+val_labs_hash (const struct val_labs *vls, unsigned int basis)
{
- const struct atom *atom = atom_;
-
- return hsh_hash_string (atom->string);
+ const struct val_lab *label;
+ unsigned int hash;
+
+ hash = hash_int (val_labs_count (vls), basis);
+ HMAP_FOR_EACH (label, struct val_lab, node, &vls->labels)
+ hash ^= value_hash (&label->value, vls->width,
+ hash_string (label->label, basis));
+ return hash;
}
-/* A hsh_free_func that destroys ATOM. */
-static void
-free_atom (void *atom_, const void *aux UNUSED)
+/* Returns true if A and B contain the same values with the same labels,
+ false if they differ in some way. */
+bool
+val_labs_equal (const struct val_labs *a, const struct val_labs *b)
{
- struct atom *atom = atom_;
+ const struct val_lab *label;
- free (atom->string);
- free (atom);
-}
+ if (val_labs_count (a) != val_labs_count (b))
+ return false;
+ if (a == NULL || b == NULL)
+ return true;
-/* Get a string representing the value.
- That is, if it has a label, then return that label,
- otherwise, if the value is alpha, then return the string for it,
- else format it and return the formatted string
-*/
-const char *
-value_to_string (const union value *val, const struct variable *var)
-{
- char *s;
-
- assert (val != NULL);
- assert (var != NULL);
+ if (a->width != b->width)
+ return false;
- s = val_labs_find (var->val_labs, *val);
- if (s == NULL)
+ HMAP_FOR_EACH (label, struct val_lab, node, &a->labels)
{
- static char buf[MAX_STRING + 1];
- data_out (val, &var->print, buf);
- buf[var->print.w] = '\0';
- s = buf;
+ struct val_lab *label2 = val_labs_lookup__ (b, &label->value,
+ label->node.hash);
+ if (!label2 || label->label != label2->label)
+ return false;
}
-
- return s;
+
+ return true;
}