summaryrefslogtreecommitdiffstats
path: root/src/libopkg/hash_table.h
diff options
context:
space:
mode:
authorP. J. McDermott <pjm@nac.net>2012-02-09 10:56:43 (EST)
committer P. J. McDermott <pjm@nac.net>2012-02-09 10:56:43 (EST)
commitf431cd1a48a6a5186633bf5f16a2d21cb4399e8c (patch)
tree337e36fd9d7884fcf76ba769ab7b0039f52d9d31 /src/libopkg/hash_table.h
Initial commit.
TODO: Copyright information. Including source code and a patch to add files generated by GNU Autoconf is not very pretty... Running 'make dist' in the SVN trunk to generate a source archive might be better.
Diffstat (limited to 'src/libopkg/hash_table.h')
-rw-r--r--src/libopkg/hash_table.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/libopkg/hash_table.h b/src/libopkg/hash_table.h
new file mode 100644
index 0000000..472b3e2
--- /dev/null
+++ b/src/libopkg/hash_table.h
@@ -0,0 +1,51 @@
+/* hash.h - hash tables for opkg
+
+ Steven M. Ayer, Jamey Hicks
+
+ Copyright (C) 2002 Compaq Computer Corporation
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+*/
+
+#ifndef _HASH_TABLE_H_
+#define _HASH_TABLE_H_
+
+typedef struct hash_entry hash_entry_t;
+typedef struct hash_table hash_table_t;
+
+struct hash_entry {
+ char * key;
+ void * data;
+ struct hash_entry * next;
+};
+
+struct hash_table {
+ const char *name;
+ hash_entry_t * entries;
+ unsigned int n_buckets;
+ unsigned int n_elements;
+
+ /* useful stats */
+ unsigned int n_used_buckets;
+ unsigned int n_collisions;
+ unsigned int max_bucket_len;
+ unsigned int n_hits, n_misses;
+};
+
+void hash_table_init(const char *name, hash_table_t *hash, int len);
+void hash_table_deinit(hash_table_t *hash);
+void hash_print_stats(hash_table_t *hash);
+void *hash_table_get(hash_table_t *hash, const char *key);
+int hash_table_insert(hash_table_t *hash, const char *key, void *value);
+int hash_table_remove(hash_table_t *has, const char *key);
+void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
+
+#endif /* _HASH_TABLE_H_ */