]> git.evergreen-ils.org Git - Evergreen.git/blob - OpenSRF/src/libstack/osrf_hash.h
abaacc5da4dcfdb9fb16b8d9a10e5d73a4a73afe
[Evergreen.git] / OpenSRF / src / libstack / osrf_hash.h
1 #include <Judy.h>
2 #include "opensrf/utils.h"
3 #include "opensrf/string_array.h"
4
5 #define OSRF_HASH_MAXKEY 256
6
7 struct __osrfHashStruct {
8         Pvoid_t hash;                                                   /* the hash */
9         void (*freeItem) (char* key, void* item);       /* callback for freeing stored items */
10 };
11 typedef struct __osrfHashStruct osrfHash;
12
13
14 struct __osrfHashIteratorStruct {
15         char* current;
16         osrfHash* hash;
17 };
18 typedef struct __osrfHashIteratorStruct osrfHashIterator;
19
20 /**
21   Allocates a new hash object
22   */
23 osrfHash* osrfNewHash();
24
25 /**
26   Sets the given key with the given item
27   if "freeItem" is defined and an item already exists at the given location, 
28   then old item is freed and the new item is put into place.
29   if "freeItem" is not defined and an item already exists, the old item
30   is returned.
31   @return The old item if exists and there is no 'freeItem', returns NULL
32   otherwise
33   */
34 void* osrfHashSet( osrfHash* hash, void* item, const char* key, ... );
35
36 /**
37   Removes an item from the hash.
38   if 'freeItem' is defined it is used and NULL is returned,
39   else the freed item is returned
40   */
41 void* osrfHashRemove( osrfHash* hash, const char* key, ... );
42
43 void* osrfHashGet( osrfHash* hash, const char* key, ... );
44
45
46 /**
47   @return A list of strings representing the keys of the hash. 
48   caller is responsible for freeing the returned string array 
49   with osrfStringArrayFree();
50   */
51 osrfStringArray* osrfHashKeys( osrfHash* hash );
52
53 /**
54   Frees a hash
55   */
56 void osrfHashFree( osrfHash* hash );
57
58 /**
59   @return The number of items in the hash
60   */
61 unsigned long osrfHashGetCount( osrfHash* hash );
62
63
64
65
66 /**
67   Creates a new list iterator with the given list
68   */
69 osrfHashIterator* osrfNewHashIterator( osrfHash* hash );
70
71 /**
72   Returns the next non-NULL item in the list, return NULL when
73   the end of the list has been reached
74   */
75 void* osrfHashIteratorNext( osrfHashIterator* itr );
76
77 /**
78   Deallocates the given list
79   */
80 void osrfHashIteratorFree( osrfHashIterator* itr );
81
82 void osrfHashIteratorReset( osrfHashIterator* itr );
83