X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fvalue-labels.c;h=1080cdff1d82d207aecd0577cc16ad685c25d1ed;hb=refs%2Fheads%2Fctables12;hp=746e20908f8f8bdafa7fa8a6529e7d8450be333c;hpb=e24089bbe924045c7b98e4bbcc0dc1c4b8703429;p=pspp diff --git a/src/data/value-labels.c b/src/data/value-labels.c index 746e20908f..1080cdff1d 100644 --- a/src/data/value-labels.c +++ b/src/data/value-labels.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2009, 2010, 2011 Free Software Foundation, Inc. + 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 @@ -256,6 +256,35 @@ val_labs_lookup (const struct val_labs *vls, const union value *value) return (vls == NULL ? NULL : val_labs_lookup__ (vls, value, value_hash (value, vls->width, 0))); } + +/* Searches VLS for a value label whose label is exactly LABEL. If successful, + returns the corresponding value. Otherwise, returns a null pointer. + + Returns a null pointer if VLS is null. + + 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_) +{ + const union value *value = NULL; + + if (vls != 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); + } + + return value; +} /* 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 @@ -333,7 +362,13 @@ val_labs_equal (const struct val_labs *a, const struct val_labs *b) { const struct val_lab *label; - if (val_labs_count (a) != val_labs_count (b) || a->width != b->width) + if (val_labs_count (a) != val_labs_count (b)) + return false; + + if (a == NULL || b == NULL) + return true; + + if (a->width != b->width) return false; HMAP_FOR_EACH (label, struct val_lab, node, &a->labels)