X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fvalue.c;h=baaaed48d4c396a94312917a1becc7b7bee9f7c2;hb=16af7ed2b7da4aa1c38a15c5663298d6e251e458;hp=9fcf1cbb9b8fa0a97cb4e75544a9a6892879ab68;hpb=45a1201de864c76f5a8c78166dc4ff2ea4151e5d;p=pspp-builds.git diff --git a/src/data/value.c b/src/data/value.c index 9fcf1cbb..baaaed48 100644 --- a/src/data/value.c +++ b/src/data/value.c @@ -47,21 +47,20 @@ value_create (int width) 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_; @@ -122,3 +121,13 @@ value_resize (union value *value, int old_width, int new_width) 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)); +}