1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 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, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 #include <libpspp/hash.h>
23 #include <libpspp/str.h>
28 The caller is responsible for freeing the returned value. */
30 value_dup (const union value *val, int width)
32 return xmemdup (val, MAX (width, sizeof *val));
35 /* Compares A and B, which both have the given WIDTH, and returns
36 a strcmp()-type result.
37 Only the short string portion of longer strings are
40 compare_values (const union value *a, const union value *b, int width)
43 ? (a->f < b->f ? -1 : a->f > b->f)
44 : memcmp (a->s, b->s, MIN (MAX_SHORT_STRING, width)));
47 /* Create a hash of V, which has the given WIDTH.
48 Only the short string portion of a longer string is hashed. */
50 hash_value (const union value *v, int width)
53 ? hsh_hash_double (v->f)
54 : hsh_hash_bytes (v->s, MIN (MAX_SHORT_STRING, width)));