1 /* Hash functions for file-related triples: name, device, inode.
2 Copyright (C) 2007 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 2, or (at your option)
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, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 /* written by Jim Meyering */
22 #include "hash-triple.h"
29 #include "same-inode.h"
31 #define STREQ(a, b) (strcmp ((a), (b)) == 0)
33 /* Hash an F_triple, and *do* consider the file name. */
35 triple_hash (void const *x, size_t table_size)
37 struct F_triple const *p = x;
38 size_t tmp = hash_pjw (p->name, table_size);
40 /* Ignoring the device number here should be fine. */
41 return (tmp ^ p->st_ino) % table_size;
44 /* Hash an F_triple, without considering the file name. */
46 triple_hash_no_name (void const *x, size_t table_size)
48 struct F_triple const *p = x;
50 /* Ignoring the device number here should be fine. */
51 return p->st_ino % table_size;
54 /* Compare two F_triple structs. */
56 triple_compare (void const *x, void const *y)
58 struct F_triple const *a = x;
59 struct F_triple const *b = y;
60 return (SAME_INODE (*a, *b) && same_name (a->name, b->name)) ? true : false;
64 triple_compare_ino_str (void const *x, void const *y)
66 struct F_triple const *a = x;
67 struct F_triple const *b = y;
68 return (SAME_INODE (*a, *b) && STREQ (a->name, b->name)) ? true : false;
71 /* Free an F_triple. */
75 struct F_triple *a = x;