1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include <libpspp/hash.h>
21 #include <libpspp/str.h>
26 The caller is responsible for freeing the returned value. */
28 value_dup (const union value *val, int width)
30 return xmemdup (val, MAX (width, sizeof *val));
33 /* Compares A and B, which both have the given WIDTH, and returns
34 a strcmp()-type result.
35 Only the short string portion of longer strings are
38 compare_values (const union value *a, const union value *b, int width)
41 ? (a->f < b->f ? -1 : a->f > b->f)
42 : memcmp (a->s, b->s, MIN (MAX_SHORT_STRING, width)));
45 /* Create a hash of V, which has the given WIDTH.
46 Only the short string portion of a longer string is hashed. */
48 hash_value (const union value *v, int width)
51 ? hsh_hash_double (v->f)
52 : hsh_hash_bytes (v->s, MIN (MAX_SHORT_STRING, width)));
55 /* Copies SRC to DST, given that they both contain data of the
58 value_copy (union value *dst, const union value *src, int width)
63 memcpy (dst->s, src->s, width);
66 /* Sets V to the system-missing value for data of the given
69 value_set_missing (union value *v, int width)
74 memset (v->s, ' ', width);