Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib/hash2.h @ 9451:9fff30644260 HEAD
istream-concat: Fixed a lot of bugs.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 26 Oct 2009 17:06:57 -0400 |
parents | 29ed66459a74 |
children |
rev | line source |
---|---|
8143
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1 #ifndef HASH2_H |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 #define HASH2_H |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
4 struct hash2_iter { |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 struct hash2_value *value, *next_value; |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 unsigned int key_hash; |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 }; |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 /* Returns hash code for the key. */ |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 typedef unsigned int hash2_key_callback_t(const void *key); |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 /* Returns TRUE if the key matches the value. */ |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 typedef bool hash2_cmp_callback_t(const void *key, const void *value, |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 void *context); |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 /* Create a new hash table. If initial_size is 0, the default value is used. */ |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 struct hash2_table * |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 hash2_create(unsigned int initial_size, unsigned int value_size, |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 hash2_key_callback_t *key_hash_cb, |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 hash2_cmp_callback_t *key_compare_cb, void *context); |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 void hash2_destroy(struct hash2_table **hash); |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 /* Remove all nodes from hash table. */ |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 void hash2_clear(struct hash2_table *hash); |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 void *hash2_lookup(const struct hash2_table *hash, const void *key) ATTR_PURE; |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 /* Iterate through all nodes with the given hash. iter must initially be |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 zero-filled. */ |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 void *hash2_iterate(const struct hash2_table *hash, |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 unsigned int key_hash, struct hash2_iter *iter); |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 /* Insert node to the hash table and returns pointer to the value that can be |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
30 written to. Assumes it doesn't already exist (or that a duplicate entry |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
31 is wanted). */ |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
32 void *hash2_insert(struct hash2_table *hash, const void *key); |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
33 /* Like hash2_insert(), but insert directly using a hash. */ |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
34 void *hash2_insert_hash(struct hash2_table *hash, unsigned int key_hash); |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
35 /* Remove a node. */ |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
36 void hash2_remove(struct hash2_table *hash, const void *key); |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
37 /* Remove the last node iterator returned. Iterating continues from the next |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
38 node. */ |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
39 void hash2_remove_iter(struct hash2_table *hash, struct hash2_iter *iter); |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
40 /* Return the number of nodes in hash table. */ |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
41 unsigned int hash2_count(const struct hash2_table *hash) ATTR_PURE; |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
42 |
29ed66459a74
Added an alternative hash table implementation.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
43 #endif |