]> git.cworth.org Git - tar/blob - gnu/hash-triple.c
Imported Upstream version 1.23
[tar] / gnu / hash-triple.c
1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* Hash functions for file-related triples: name, device, inode.
4    Copyright (C) 2007, 2009-2010 Free Software Foundation, Inc.
5
6    This program is free software: you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
18
19 /* written by Jim Meyering */
20
21 #include <config.h>
22
23 #include "hash-triple.h"
24
25 #include <stdlib.h>
26 #include <string.h>
27
28 #include "hash-pjw.h"
29 #include "same.h"
30 #include "same-inode.h"
31
32 #define STREQ(a, b) (strcmp (a, b) == 0)
33
34 /* Hash an F_triple, and *do* consider the file name.  */
35 size_t
36 triple_hash (void const *x, size_t table_size)
37 {
38   struct F_triple const *p = x;
39   size_t tmp = hash_pjw (p->name, table_size);
40
41   /* Ignoring the device number here should be fine.  */
42   return (tmp ^ p->st_ino) % table_size;
43 }
44
45 /* Hash an F_triple, without considering the file name.  */
46 size_t
47 triple_hash_no_name (void const *x, size_t table_size)
48 {
49   struct F_triple const *p = x;
50
51   /* Ignoring the device number here should be fine.  */
52   return p->st_ino % table_size;
53 }
54
55 /* Compare two F_triple structs.  */
56 bool
57 triple_compare (void const *x, void const *y)
58 {
59   struct F_triple const *a = x;
60   struct F_triple const *b = y;
61   return (SAME_INODE (*a, *b) && same_name (a->name, b->name)) ? true : false;
62 }
63
64 bool
65 triple_compare_ino_str (void const *x, void const *y)
66 {
67   struct F_triple const *a = x;
68   struct F_triple const *b = y;
69   return (SAME_INODE (*a, *b) && STREQ (a->name, b->name)) ? true : false;
70 }
71
72 /* Free an F_triple.  */
73 void
74 triple_free (void *x)
75 {
76   struct F_triple *a = x;
77   free (a->name);
78   free (a);
79 }