aboutsummaryrefslogtreecommitdiffstats
path: root/hashlib.h
diff options
context:
space:
mode:
authorJari Aalto <jari.aalto@cante.net>2002-07-17 14:10:11 +0000
committerJari Aalto <jari.aalto@cante.net>2009-09-12 16:46:55 +0000
commit7117c2d221b2aed4ede8600f6a36b7c1454b4f55 (patch)
treeb792f26ecca68813c51ed5ba2e381790758ef31b /hashlib.h
parentf73dda092b33638d2d5e9c35375f687a607b5403 (diff)
downloadandroid_external_bash-7117c2d221b2aed4ede8600f6a36b7c1454b4f55.tar.gz
android_external_bash-7117c2d221b2aed4ede8600f6a36b7c1454b4f55.tar.bz2
android_external_bash-7117c2d221b2aed4ede8600f6a36b7c1454b4f55.zip
Imported from ../bash-2.05b.tar.gz.
Diffstat (limited to 'hashlib.h')
-rw-r--r--hashlib.h48
1 files changed, 36 insertions, 12 deletions
diff --git a/hashlib.h b/hashlib.h
index 9c3dee0..bb7120b 100644
--- a/hashlib.h
+++ b/hashlib.h
@@ -23,10 +23,19 @@
#include "stdc.h"
+#ifndef PTR_T
+# ifdef __STDC__
+# define PTR_T void *
+# else
+# define PTR_T char *
+# endif
+#endif
+
typedef struct bucket_contents {
struct bucket_contents *next; /* Link to next hashed key in this bucket. */
char *key; /* What we look up. */
- char *data; /* What we really want. */
+ PTR_T data; /* What we really want. */
+ unsigned int khash; /* What key hashes to */
int times_found; /* Number of times this item has been found. */
} BUCKET_CONTENTS;
@@ -36,27 +45,42 @@ typedef struct hash_table {
int nentries; /* How many entries does this table have. */
} HASH_TABLE;
-extern int hash_string __P((const char *, HASH_TABLE *));
-extern int hash_table_nentries __P((HASH_TABLE *));
-extern HASH_TABLE *make_hash_table __P((int));
-extern HASH_TABLE *copy_hash_table __P((HASH_TABLE *, sh_string_func_t *));
-extern BUCKET_CONTENTS *find_hash_item __P((const char *, HASH_TABLE *));
-extern BUCKET_CONTENTS *remove_hash_item __P((const char *, HASH_TABLE *));
-extern BUCKET_CONTENTS *add_hash_item __P((char *, HASH_TABLE *));
-extern void flush_hash_table __P((HASH_TABLE *, sh_free_func_t *));
-extern void dispose_hash_table __P((HASH_TABLE *));
+typedef int hash_wfunc __P((BUCKET_CONTENTS *));
+
+/* Operations on tables as a whole */
+extern HASH_TABLE *hash_create __P((int));
+extern HASH_TABLE *hash_copy __P((HASH_TABLE *, sh_string_func_t *));
+extern void hash_flush __P((HASH_TABLE *, sh_free_func_t *));
+extern void hash_dispose __P((HASH_TABLE *));
+extern void hash_walk __P((HASH_TABLE *, hash_wfunc *));
+
+/* Operations to extract information from or pieces of tables */
+extern int hash_bucket __P((const char *, HASH_TABLE *));
+extern int hash_size __P((HASH_TABLE *));
+
+/* Operations on hash table entries */
+extern BUCKET_CONTENTS *hash_search __P((const char *, HASH_TABLE *, int));
+extern BUCKET_CONTENTS *hash_insert __P((char *, HASH_TABLE *, int));
+extern BUCKET_CONTENTS *hash_remove __P((const char *, HASH_TABLE *, int));
+
+/* Miscellaneous */
+extern unsigned int hash_string __P((const char *));
/* Redefine the function as a macro for speed. */
-#define get_hash_bucket(bucket, table) \
+#define hash_items(bucket, table) \
((table && (bucket < table->nbuckets)) ? \
table->bucket_array[bucket] : \
(BUCKET_CONTENTS *)NULL)
/* Default number of buckets in the hash table. */
-#define DEFAULT_HASH_BUCKETS 53 /* was 107 */
+#define DEFAULT_HASH_BUCKETS 64 /* was 107, then 53, must be power of two now */
#define HASH_ENTRIES(ht) ((ht) ? (ht)->nentries : 0)
+/* flags for hash_search and hash_insert */
+#define HASH_NOSRCH 0x01
+#define HASH_CREATE 0x02
+
#if !defined (NULL)
# if defined (__STDC__)
# define NULL ((void *) 0)