Fixup paths and Makefiles for rpmdb/ elimination
[platform/upstream/rpm.git] / lib / rpmhash.h
1 #ifndef H_RPMHASH
2 #define H_RPMHASH
3
4 /**
5  * \file lib/rpmhash.h
6  * Hash table implemenation.
7  */
8
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12
13 /**
14  */
15 typedef struct hashTable_s * hashTable;
16
17 /**
18  */
19 typedef unsigned int (*hashFunctionType) (const void * string);
20
21 /**
22  */
23 typedef int (*hashEqualityType) (const void * key1, const void * key2);
24
25 /**
26  * Return hash value of a string
27  * @param string        string on which to calculate hash value
28  * @return              hash value
29  */
30 unsigned int hashFunctionString(const void * string);
31
32 /**
33  * Compare two hash table entries for equality.
34  * @param key1          entry 1
35  * @param key2          entry 2
36  * @return              0 if entries are equal
37  */
38 int hashEqualityString(const void * key1, const void * key2);
39
40 /**
41  * Create hash table.
42  * If keySize > 0, the key is duplicated within the table (which costs
43  * memory, but may be useful anyway.
44  * @param numBuckets    number of hash buckets
45  * @param keySize       size of key (0 if unknown)
46  * @param freeData      Should data be freed when table is destroyed?
47  * @param fn            function to generate hash value for key
48  * @param eq            function to compare hash keys for equality
49  * @return              pointer to initialized hash table
50  */
51 hashTable htCreate(int numBuckets, size_t keySize, int freeData,
52                 hashFunctionType fn, hashEqualityType eq); 
53
54 /**
55  * Destroy hash table.
56  * @param ht            pointer to hash table
57  * @return              NULL always
58  */
59 hashTable htFree( hashTable ht);
60
61 /**
62  * Add item to hash table.
63  * @param ht            pointer to hash table
64  * @param key           pointer to key
65  * @param data          pointer to data value
66  */
67 void htAddEntry(hashTable ht, const void * key,
68                 const void * data);
69
70 /**
71  * Retrieve item from hash table.
72  * @param ht            pointer to hash table
73  * @param key           pointer to key value
74  * @retval data         address to store data value from bucket
75  * @retval dataCount    address to store data value size from bucket
76  * @retval tableKey     address to store key value from bucket (may be NULL)
77  * @return              0 on success, 1 if the item is not found.
78  */
79 int htGetEntry(hashTable ht, const void * key,
80                 const void *** data,
81                 int * dataCount,
82                 const void ** tableKey);
83
84 /**
85  * Check for key in hash table.
86  * @param ht            pointer to hash table
87  * @param key           pointer to key value
88  * @return              1 if the key is present, 0 otherwise
89  */
90 int htHasEntry(hashTable ht, const void * key);
91
92 #ifdef __cplusplus
93 }
94 #endif
95
96 #endif