Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib/hash.h @ 9658:8ba4253adc9b HEAD tip
*-login: SSL connections didn't get closed when the client got destroyed.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 08 May 2014 16:41:29 +0300 |
parents | f05c50f43793 |
children |
rev | line source |
---|---|
6410
e4eb71ae8e96
Changed .h ifdef/defines to use <NAME>_H format.
Timo Sirainen <tss@iki.fi>
parents:
3906
diff
changeset
|
1 #ifndef HASH_H |
e4eb71ae8e96
Changed .h ifdef/defines to use <NAME>_H format.
Timo Sirainen <tss@iki.fi>
parents:
3906
diff
changeset
|
2 #define HASH_H |
0 | 3 |
4 /* Returns hash code. */ | |
1038
60646878858e
Function typedefs now define them as functions, not function pointers.
Timo Sirainen <tss@iki.fi>
parents:
953
diff
changeset
|
5 typedef unsigned int hash_callback_t(const void *p); |
0 | 6 /* Returns 0 if the pointers are equal. */ |
1038
60646878858e
Function typedefs now define them as functions, not function pointers.
Timo Sirainen <tss@iki.fi>
parents:
953
diff
changeset
|
7 typedef int hash_cmp_callback_t(const void *p1, const void *p2); |
0 | 8 |
9 /* Create a new hash table. If initial_size is 0, the default value is used. | |
953
411006be3c66
Naming change for function typedefs.
Timo Sirainen <tss@iki.fi>
parents:
949
diff
changeset
|
10 If hash_cb or key_compare_cb is NULL, direct hashing/comparing is used. |
945
501f076f2e74
Rewrote hash table code, works with less memory now. Also some memory
Timo Sirainen <tss@iki.fi>
parents:
942
diff
changeset
|
11 |
501f076f2e74
Rewrote hash table code, works with less memory now. Also some memory
Timo Sirainen <tss@iki.fi>
parents:
942
diff
changeset
|
12 table_pool is used to allocate/free large hash tables, node_pool is used |
501f076f2e74
Rewrote hash table code, works with less memory now. Also some memory
Timo Sirainen <tss@iki.fi>
parents:
942
diff
changeset
|
13 for smaller allocations and can also be alloconly pool. The pools must not |
8573
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
14 be free'd before hash_table_destroy() is called. */ |
953
411006be3c66
Naming change for function typedefs.
Timo Sirainen <tss@iki.fi>
parents:
949
diff
changeset
|
15 struct hash_table * |
8573
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
16 hash_table_create(pool_t table_pool, pool_t node_pool, unsigned int initial_size, |
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
17 hash_callback_t *hash_cb, hash_cmp_callback_t *key_compare_cb); |
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
18 void hash_table_destroy(struct hash_table **table); |
949
e601f13d95b1
hash_clear() can now be used to drop the memory allocated using node_pool.
Timo Sirainen <tss@iki.fi>
parents:
945
diff
changeset
|
19 /* Remove all nodes from hash table. If free_collisions is TRUE, the |
e601f13d95b1
hash_clear() can now be used to drop the memory allocated using node_pool.
Timo Sirainen <tss@iki.fi>
parents:
945
diff
changeset
|
20 memory allocated from node_pool is freed, or discarded with |
e601f13d95b1
hash_clear() can now be used to drop the memory allocated using node_pool.
Timo Sirainen <tss@iki.fi>
parents:
945
diff
changeset
|
21 alloconly pools. */ |
8573
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
22 void hash_table_clear(struct hash_table *table, bool free_collisions); |
0 | 23 |
8573
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
24 void *hash_table_lookup(const struct hash_table *table, const void *key) ATTR_PURE; |
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
25 bool hash_table_lookup_full(const struct hash_table *table, |
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
26 const void *lookup_key, |
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
27 void **orig_key, void **value); |
0 | 28 |
8573
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
29 /* Insert/update node in hash table. The difference is that hash_table_insert() |
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
30 replaces the key in table to given one, while hash_table_update() doesnt. */ |
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
31 void hash_table_insert(struct hash_table *table, void *key, void *value); |
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
32 void hash_table_update(struct hash_table *table, void *key, void *value); |
0 | 33 |
8573
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
34 void hash_table_remove(struct hash_table *table, const void *key); |
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
35 unsigned int hash_table_count(const struct hash_table *table) ATTR_PURE; |
0 | 36 |
8573
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
37 /* Iterates through all nodes in hash table. You may safely call hash_table_*() |
1897
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1038
diff
changeset
|
38 functions while iterating, but if you add any new nodes, they may or may |
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1038
diff
changeset
|
39 not be called for in this iteration. */ |
8573
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
40 struct hash_iterate_context *hash_table_iterate_init(struct hash_table *table); |
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
41 bool hash_table_iterate(struct hash_iterate_context *ctx, |
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
42 void **key_r, void **value_r); |
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
43 void hash_table_iterate_deinit(struct hash_iterate_context **ctx); |
0 | 44 |
45 /* Hash table isn't resized, and removed nodes aren't removed from | |
46 the list while hash table is freezed. Supports nesting. */ | |
8573
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
47 void hash_table_freeze(struct hash_table *table); |
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
48 void hash_table_thaw(struct hash_table *table); |
0 | 49 |
3616
906b87e236bf
Added hash_copy() and added some consts
Timo Sirainen <tss@iki.fi>
parents:
1897
diff
changeset
|
50 /* Copy all nodes from one hash table to another */ |
8573
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
51 void hash_table_copy(struct hash_table *dest, struct hash_table *src); |
3616
906b87e236bf
Added hash_copy() and added some consts
Timo Sirainen <tss@iki.fi>
parents:
1897
diff
changeset
|
52 |
0 | 53 /* hash function for strings */ |
7912
81806d402514
Added more consts, ATTR_CONSTs and ATTR_PUREs.
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
54 unsigned int str_hash(const void *p) ATTR_PURE; |
81806d402514
Added more consts, ATTR_CONSTs and ATTR_PUREs.
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
55 unsigned int strcase_hash(const void *p) ATTR_PURE; |
0 | 56 |
57 #endif |