summaryrefslogtreecommitdiff
path: root/lib/hash.c
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2011-04-24 19:02:10 +0200
committerJim Meyering <meyering@redhat.com>2011-04-25 10:24:30 +0200
commit349d7fe0e307d59d508b3579317ee8d4eacfeb9c (patch)
tree97d92955127a8bf559e227fbe801987246c3a0d2 /lib/hash.c
parentd35ef05dc0564cf696408eae985444879a399e29 (diff)
downloadgnulib-349d7fe0e307d59d508b3579317ee8d4eacfeb9c.tar.gz
use _GL_ATTRIBUTE_CONST and _GL_ATTRIBUTE_PURE
Diffstat (limited to 'lib/hash.c')
-rw-r--r--lib/hash.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/lib/hash.c b/lib/hash.c
index f3de2aaaac..9a969ac318 100644
--- a/lib/hash.c
+++ b/lib/hash.c
@@ -43,6 +43,14 @@
# endif
#endif
+/* The attribute __const__ was added in gcc 2.95. */
+#undef _GL_ATTRIBUTE_CONST
+#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
+# define _GL_ATTRIBUTE_CONST __attribute__ ((__const__))
+#else
+# define _GL_ATTRIBUTE_CONST /* empty */
+#endif
+
struct hash_entry
{
void *data;
@@ -146,7 +154,7 @@ static const Hash_tuning default_tuning =
number of buckets (used plus unused), or the maximum number of slots, are
the same quantity. */
-size_t
+size_t _GL_ATTRIBUTE_PURE
hash_get_n_buckets (const Hash_table *table)
{
return table->n_buckets;
@@ -154,7 +162,7 @@ hash_get_n_buckets (const Hash_table *table)
/* Return the number of slots in use (non-empty buckets). */
-size_t
+size_t _GL_ATTRIBUTE_PURE
hash_get_n_buckets_used (const Hash_table *table)
{
return table->n_buckets_used;
@@ -162,7 +170,7 @@ hash_get_n_buckets_used (const Hash_table *table)
/* Return the number of active entries. */
-size_t
+size_t _GL_ATTRIBUTE_PURE
hash_get_n_entries (const Hash_table *table)
{
return table->n_entries;
@@ -170,7 +178,7 @@ hash_get_n_entries (const Hash_table *table)
/* Return the length of the longest chain (bucket). */
-size_t
+size_t _GL_ATTRIBUTE_PURE
hash_get_max_bucket_length (const Hash_table *table)
{
struct hash_entry const *bucket;
@@ -197,7 +205,7 @@ hash_get_max_bucket_length (const Hash_table *table)
/* Do a mild validation of a hash table, by traversing it and checking two
statistics. */
-bool
+bool _GL_ATTRIBUTE_PURE
hash_table_ok (const Hash_table *table)
{
struct hash_entry const *bucket;
@@ -284,7 +292,7 @@ hash_lookup (const Hash_table *table, const void *entry)
/* Return the first data in the table, or NULL if the table is empty. */
-void *
+void * _GL_ATTRIBUTE_PURE
hash_get_first (const Hash_table *table)
{
struct hash_entry const *bucket;
@@ -401,7 +409,7 @@ hash_do_for_each (const Hash_table *table, Hash_processor processor,
algorithms tend to be domain-specific, so what's good for [diffutils'] io.c
may not be good for your application." */
-size_t
+size_t _GL_ATTRIBUTE_PURE
hash_string (const char *string, size_t n_buckets)
{
# define HASH_ONE_CHAR(Value, Byte) \
@@ -440,7 +448,7 @@ hash_string (const char *string, size_t n_buckets)
/* Return true if CANDIDATE is a prime number. CANDIDATE should be an odd
number at least equal to 11. */
-static bool
+static bool _GL_ATTRIBUTE_CONST
is_prime (size_t candidate)
{
size_t divisor = 3;
@@ -459,7 +467,7 @@ is_prime (size_t candidate)
/* Round a given CANDIDATE number up to the nearest prime, and return that
prime. Primes lower than 10 are merely skipped. */
-static size_t
+static size_t _GL_ATTRIBUTE_CONST
next_prime (size_t candidate)
{
/* Skip small primes. */
@@ -540,7 +548,7 @@ check_tuning (Hash_table *table)
TUNING, or return 0 if there is no possible way to allocate that
many entries. */
-static size_t
+static size_t _GL_ATTRIBUTE_PURE
compute_bucket_size (size_t candidate, const Hash_tuning *tuning)
{
if (!tuning->is_n_buckets)