exp2l: Work around a NetBSD 10.0/i386 bug.
[gnulib.git] / lib / hash-triple-simple.c
blobef1b4dcb3cd0a47b399b5bd2f34080fe55e82bae
1 /* Hash functions for file-related triples: name, device, inode.
2 Copyright (C) 2007, 2009-2024 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 <https://www.gnu.org/licenses/>. */
17 /* written by Jim Meyering */
19 #include <config.h>
21 /* Specification. */
22 #include "hash-triple.h"
24 #include <stdlib.h>
25 #include <string.h>
27 #include "hash-pjw.h"
28 #include "same-inode.h"
30 #define STREQ(a, b) (strcmp (a, b) == 0)
32 /* Hash an F_triple, and *do* consider the file name. */
33 size_t
34 triple_hash (void const *x, size_t table_size)
36 struct F_triple const *p = x;
37 size_t tmp = hash_pjw (p->name, table_size);
39 /* Ignoring the device number here should be fine. */
40 return (tmp ^ p->st_ino) % table_size;
43 /* Compare two F_triple structs. */
44 bool
45 triple_compare_ino_str (void const *x, void const *y)
47 struct F_triple const *a = x;
48 struct F_triple const *b = y;
49 return PSAME_INODE (a, b) && STREQ (a->name, b->name);
52 /* Free an F_triple. */
53 void
54 triple_free (void *x)
56 struct F_triple *a = x;
57 free (a->name);
58 free (a);