~ubuntu-branches/ubuntu/utopic/coreutils/utopic-proposed

« back to all changes in this revision

Viewing changes to lib/hash.h

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-11-28 03:03:42 UTC
  • mfrom: (8.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20121128030342-21zanj8354gas5gr
Tags: 8.20-3ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - Make 'uname -i -p' return the real processor/hardware, instead of
    unknown.
  - Build-depend on gettext:any instead of on gettext, so that apt-get can
    properly resolve build-dependencies on the tool when cross-building.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* hash - hashing table processing.
2
 
   Copyright (C) 1998-1999, 2001, 2003, 2009-2011 Free Software Foundation,
 
2
   Copyright (C) 1998-1999, 2001, 2003, 2009-2012 Free Software Foundation,
3
3
   Inc.
4
4
   Written by Jim Meyering <meyering@ascend.com>, 1998.
5
5
 
19
19
/* A generic hash table package.  */
20
20
 
21
21
/* Make sure USE_OBSTACK is defined to 1 if you want the allocator to use
22
 
   obstacks instead of malloc, and recompile `hash.c' with same setting.  */
 
22
   obstacks instead of malloc, and recompile 'hash.c' with same setting.  */
23
23
 
24
24
#ifndef HASH_H_
25
25
# define HASH_H_
35
35
#  define _GL_ATTRIBUTE_WUR /* empty */
36
36
# endif
37
37
 
 
38
# ifndef _GL_ATTRIBUTE_DEPRECATED
 
39
/* The __attribute__((__deprecated__)) feature
 
40
   is available in gcc versions 3.1 and newer.  */
 
41
#  if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 1)
 
42
#   define _GL_ATTRIBUTE_DEPRECATED /* empty */
 
43
#  else
 
44
#   define _GL_ATTRIBUTE_DEPRECATED __attribute__ ((__deprecated__))
 
45
#  endif
 
46
# endif
 
47
 
38
48
typedef size_t (*Hash_hasher) (const void *, size_t);
39
49
typedef bool (*Hash_comparator) (const void *, const void *);
40
50
typedef void (*Hash_data_freer) (void *);
42
52
 
43
53
struct hash_tuning
44
54
  {
45
 
    /* This structure is mainly used for `hash_initialize', see the block
46
 
       documentation of `hash_reset_tuning' for more complete comments.  */
 
55
    /* This structure is mainly used for 'hash_initialize', see the block
 
56
       documentation of 'hash_reset_tuning' for more complete comments.  */
47
57
 
48
58
    float shrink_threshold;     /* ratio of used buckets to trigger a shrink */
49
59
    float shrink_factor;        /* ratio of new smaller size to original size */
59
69
typedef struct hash_table Hash_table;
60
70
 
61
71
/* Information and lookup.  */
62
 
size_t hash_get_n_buckets (const Hash_table *);
63
 
size_t hash_get_n_buckets_used (const Hash_table *);
64
 
size_t hash_get_n_entries (const Hash_table *);
65
 
size_t hash_get_max_bucket_length (const Hash_table *);
66
 
bool hash_table_ok (const Hash_table *);
 
72
size_t hash_get_n_buckets (const Hash_table *) _GL_ATTRIBUTE_PURE;
 
73
size_t hash_get_n_buckets_used (const Hash_table *) _GL_ATTRIBUTE_PURE;
 
74
size_t hash_get_n_entries (const Hash_table *) _GL_ATTRIBUTE_PURE;
 
75
size_t hash_get_max_bucket_length (const Hash_table *) _GL_ATTRIBUTE_PURE;
 
76
bool hash_table_ok (const Hash_table *) _GL_ATTRIBUTE_PURE;
67
77
void hash_print_statistics (const Hash_table *, FILE *);
68
78
void *hash_lookup (const Hash_table *, const void *);
69
79
 
70
80
/* Walking.  */
71
 
void *hash_get_first (const Hash_table *);
 
81
void *hash_get_first (const Hash_table *) _GL_ATTRIBUTE_PURE;
72
82
void *hash_get_next (const Hash_table *, const void *);
73
83
size_t hash_get_entries (const Hash_table *, void **, size_t);
74
84
size_t hash_do_for_each (const Hash_table *, Hash_processor, void *);
75
85
 
76
86
/* Allocation and clean-up.  */
77
 
size_t hash_string (const char *, size_t);
 
87
size_t hash_string (const char *, size_t) _GL_ATTRIBUTE_PURE;
78
88
void hash_reset_tuning (Hash_tuning *);
79
89
Hash_table *hash_initialize (size_t, const Hash_tuning *,
80
90
                             Hash_hasher, Hash_comparator,
85
95
/* Insertion and deletion.  */
86
96
bool hash_rehash (Hash_table *, size_t) _GL_ATTRIBUTE_WUR;
87
97
void *hash_insert (Hash_table *, const void *) _GL_ATTRIBUTE_WUR;
88
 
int hash_insert0 (Hash_table *table, const void *entry,
89
 
                  const void **matched_ent);
 
98
 
 
99
/* Deprecate this interface.  It has been renamed to hash_insert_if_absent.  */
 
100
int hash_insert0 (Hash_table *table, /* FIXME: remove in 2013 */
 
101
                  const void *entry,
 
102
                  const void **matched_ent) _GL_ATTRIBUTE_DEPRECATED;
 
103
int hash_insert_if_absent (Hash_table *table, const void *entry,
 
104
                           const void **matched_ent);
90
105
void *hash_delete (Hash_table *, const void *);
91
106
 
92
107
#endif