hash.h
1.19 KB
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
/* Copyright 2006 David Crawshaw, released under the new BSD license.
* Version 2, from http://www.zentus.com/c/hash.html
* Modified by C. Steenberg <conrad.steenberg@caltech.edu>
02/12/2008 Make it possible to use keys with \0 chars
*/
#ifndef NUPACK_SHARED_HASH_H
#define NUPACK_SHARED_HASH_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Opaque structure used to represent hashtable. */
typedef struct hash hash;
/* Create new hashtable. */
hash * hash_new(unsigned int size);
/* Free hashtable. */
void hash_destroy(hash *h);
/* Add key/value pair. Returns non-zero value on error (eg out-of-memory). */
int hash_add(hash *h, const char *key, const unsigned int len, void *value);
/* Return value matching given key. */
void * hash_get(hash *h, const char *key, const unsigned int len);
/* Remove key from table, returning value. */
void * hash_remove(hash *h, const char *key, const unsigned int len);
/* Returns total number of keys in the hashtable. */
unsigned int hash_size(hash *h);
/* Calculate a hash from a given array of characters that need not be
zero-terminated
*/
unsigned int vechash(const char *vec, const unsigned int len);
#ifdef __cplusplus
}
#endif
#endif