forked from metajack/libstrophe
-
Notifications
You must be signed in to change notification settings - Fork 6
/
hash.h
64 lines (48 loc) · 1.82 KB
/
hash.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* hash.h
** strophe XMPP client library -- hash table interface
**
** Copyright (C) 2005-2009 Collecta, Inc.
**
** This software is provided AS-IS with no warranty, either express
** or implied.
**
** This software is distributed under license and may not be copied,
** modified or distributed except as expressly authorized under the
** terms of the license contained in the file LICENSE.txt in this
** distribution.
*/
/** @file
* Hash table API.
*/
#ifndef __LIBSTROPHE_HASH_H__
#define __LIBSTROPHE_HASH_H__
typedef struct _hash_t hash_t;
typedef void (*hash_free_func)(const xmpp_ctx_t * const ctx, void *p);
/** allocate and initialize a new hash table */
hash_t *hash_new(xmpp_ctx_t * const ctx, const int size,
hash_free_func free);
/** allocate a new reference to an existing hash table */
hash_t *hash_clone(hash_t * const table);
/** release a hash table when no longer needed */
void hash_release(hash_t * const table);
/** add a key, value pair to a hash table.
* each key can appear only once; the value of any
* identical key will be replaced
*/
int hash_add(hash_t *table, const char * const key, void *data);
/** look up a key in a hash table */
void *hash_get(hash_t *table, const char *key);
/** delete a key from a hash table */
int hash_drop(hash_t *table, const char *key);
/** return the number of keys in a hash */
int hash_num_keys(hash_t *table);
/** hash key iterator functions */
typedef struct _hash_iterator_t hash_iterator_t;
/** allocate and initialize a new iterator */
hash_iterator_t *hash_iter_new(hash_t *table);
/** release an iterator that is no longer needed */
void hash_iter_release(hash_iterator_t *iter);
/** return the next hash table key from the iterator.
the returned key should not be freed */
const char * hash_iter_next(hash_iterator_t *iter);
#endif /* __LIBXMPPP_HASH_H__ */