Mercurial > hg > octave-shane > gnulib-hg
annotate lib/hash-triple.c @ 14610:b427a1938336
use _GL_ATTRIBUTE_CONST and _GL_ATTRIBUTE_PURE
author | Jim Meyering <meyering@redhat.com> |
---|---|
date | Sun, 24 Apr 2011 19:02:10 +0200 |
parents | 97fc9a21a8fb |
children | 6ef4f1f39105 |
rev | line source |
---|---|
9225 | 1 /* Hash functions for file-related triples: name, device, inode. |
14079
97fc9a21a8fb
maint: update almost all copyright ranges to include 2011
Jim Meyering <meyering@redhat.com>
parents:
12772
diff
changeset
|
2 Copyright (C) 2007, 2009-2011 Free Software Foundation, Inc. |
9225 | 3 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9233
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
9225 | 5 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9233
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9233
diff
changeset
|
7 (at your option) any later version. |
9225 | 8 |
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. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9233
diff
changeset
|
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
9225 | 16 |
17 /* written by Jim Meyering */ | |
18 | |
19 #include <config.h> | |
20 | |
21 #include "hash-triple.h" | |
22 | |
23 #include <stdlib.h> | |
9233
f5b68edd82c4
Fix canonicalize loop-detection corner case.
Jim Meyering <jim@meyering.net>
parents:
9225
diff
changeset
|
24 #include <string.h> |
9225 | 25 |
26 #include "hash-pjw.h" | |
27 #include "same.h" | |
28 #include "same-inode.h" | |
29 | |
12772
2ea3e3fab7ee
define STREQ(a,b) consistently, removing useless parentheses
Jim Meyering <meyering@redhat.com>
parents:
12559
diff
changeset
|
30 #define STREQ(a, b) (strcmp (a, b) == 0) |
9233
f5b68edd82c4
Fix canonicalize loop-detection corner case.
Jim Meyering <jim@meyering.net>
parents:
9225
diff
changeset
|
31 |
14610
b427a1938336
use _GL_ATTRIBUTE_CONST and _GL_ATTRIBUTE_PURE
Jim Meyering <meyering@redhat.com>
parents:
14079
diff
changeset
|
32 /* The attribute __pure__ was added in gcc 2.96. */ |
b427a1938336
use _GL_ATTRIBUTE_CONST and _GL_ATTRIBUTE_PURE
Jim Meyering <meyering@redhat.com>
parents:
14079
diff
changeset
|
33 #undef _GL_ATTRIBUTE_PURE |
b427a1938336
use _GL_ATTRIBUTE_CONST and _GL_ATTRIBUTE_PURE
Jim Meyering <meyering@redhat.com>
parents:
14079
diff
changeset
|
34 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) |
b427a1938336
use _GL_ATTRIBUTE_CONST and _GL_ATTRIBUTE_PURE
Jim Meyering <meyering@redhat.com>
parents:
14079
diff
changeset
|
35 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__)) |
b427a1938336
use _GL_ATTRIBUTE_CONST and _GL_ATTRIBUTE_PURE
Jim Meyering <meyering@redhat.com>
parents:
14079
diff
changeset
|
36 #else |
b427a1938336
use _GL_ATTRIBUTE_CONST and _GL_ATTRIBUTE_PURE
Jim Meyering <meyering@redhat.com>
parents:
14079
diff
changeset
|
37 # define _GL_ATTRIBUTE_PURE /* empty */ |
b427a1938336
use _GL_ATTRIBUTE_CONST and _GL_ATTRIBUTE_PURE
Jim Meyering <meyering@redhat.com>
parents:
14079
diff
changeset
|
38 #endif |
b427a1938336
use _GL_ATTRIBUTE_CONST and _GL_ATTRIBUTE_PURE
Jim Meyering <meyering@redhat.com>
parents:
14079
diff
changeset
|
39 |
9225 | 40 /* Hash an F_triple, and *do* consider the file name. */ |
41 size_t | |
42 triple_hash (void const *x, size_t table_size) | |
43 { | |
44 struct F_triple const *p = x; | |
45 size_t tmp = hash_pjw (p->name, table_size); | |
46 | |
47 /* Ignoring the device number here should be fine. */ | |
48 return (tmp ^ p->st_ino) % table_size; | |
49 } | |
50 | |
51 /* Hash an F_triple, without considering the file name. */ | |
14610
b427a1938336
use _GL_ATTRIBUTE_CONST and _GL_ATTRIBUTE_PURE
Jim Meyering <meyering@redhat.com>
parents:
14079
diff
changeset
|
52 size_t _GL_ATTRIBUTE_PURE |
9225 | 53 triple_hash_no_name (void const *x, size_t table_size) |
54 { | |
55 struct F_triple const *p = x; | |
56 | |
57 /* Ignoring the device number here should be fine. */ | |
58 return p->st_ino % table_size; | |
59 } | |
60 | |
61 /* Compare two F_triple structs. */ | |
62 bool | |
63 triple_compare (void const *x, void const *y) | |
64 { | |
65 struct F_triple const *a = x; | |
66 struct F_triple const *b = y; | |
67 return (SAME_INODE (*a, *b) && same_name (a->name, b->name)) ? true : false; | |
68 } | |
69 | |
9233
f5b68edd82c4
Fix canonicalize loop-detection corner case.
Jim Meyering <jim@meyering.net>
parents:
9225
diff
changeset
|
70 bool |
f5b68edd82c4
Fix canonicalize loop-detection corner case.
Jim Meyering <jim@meyering.net>
parents:
9225
diff
changeset
|
71 triple_compare_ino_str (void const *x, void const *y) |
f5b68edd82c4
Fix canonicalize loop-detection corner case.
Jim Meyering <jim@meyering.net>
parents:
9225
diff
changeset
|
72 { |
f5b68edd82c4
Fix canonicalize loop-detection corner case.
Jim Meyering <jim@meyering.net>
parents:
9225
diff
changeset
|
73 struct F_triple const *a = x; |
f5b68edd82c4
Fix canonicalize loop-detection corner case.
Jim Meyering <jim@meyering.net>
parents:
9225
diff
changeset
|
74 struct F_triple const *b = y; |
f5b68edd82c4
Fix canonicalize loop-detection corner case.
Jim Meyering <jim@meyering.net>
parents:
9225
diff
changeset
|
75 return (SAME_INODE (*a, *b) && STREQ (a->name, b->name)) ? true : false; |
f5b68edd82c4
Fix canonicalize loop-detection corner case.
Jim Meyering <jim@meyering.net>
parents:
9225
diff
changeset
|
76 } |
f5b68edd82c4
Fix canonicalize loop-detection corner case.
Jim Meyering <jim@meyering.net>
parents:
9225
diff
changeset
|
77 |
9225 | 78 /* Free an F_triple. */ |
79 void | |
80 triple_free (void *x) | |
81 { | |
82 struct F_triple *a = x; | |
83 free (a->name); | |
84 free (a); | |
85 } |