]> git.evergreen-ils.org Git - OpenSRF.git/blob - include/opensrf/osrf_big_hash.h
LP#1286198: Teach osrf_router to (optionally) write its own PID files
[OpenSRF.git] / include / opensrf / osrf_big_hash.h
1 #ifndef OSRF_BIG_HASH_H
2 #define OSRF_BIG_HASH_H
3
4 #include <Judy.h>
5 #include <opensrf/utils.h>
6 #include <opensrf/string_array.h>
7
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11
12 #define OSRF_HASH_MAXKEY 256
13
14 struct __osrfBigHashStruct {
15         Pvoid_t hash;                                                   /* the hash */
16         void (*freeItem) (char* key, void* item);       /* callback for freeing stored items */
17 };
18 typedef struct __osrfBigHashStruct osrfBigHash;
19
20
21 struct __osrfBigHashIteratorStruct {
22         char* current;
23         osrfBigHash* hash;
24 };
25 typedef struct __osrfBigHashIteratorStruct osrfBigHashIterator;
26
27 /**
28   Allocates a new hash object
29   */
30 osrfBigHash* osrfNewBigHash();
31
32 /**
33   Sets the given key with the given item
34   if "freeItem" is defined and an item already exists at the given location, 
35   then old item is freed and the new item is put into place.
36   if "freeItem" is not defined and an item already exists, the old item
37   is returned.
38   @return The old item if exists and there is no 'freeItem', returns NULL
39   otherwise
40   */
41 void* osrfBigHashSet( osrfBigHash* hash, void* item, const char* key, ... );
42
43 /**
44   Removes an item from the hash.
45   if 'freeItem' is defined it is used and NULL is returned,
46   else the freed item is returned
47   */
48 void* osrfBigHashRemove( osrfBigHash* hash, const char* key, ... );
49
50 void* osrfBigHashGet( osrfBigHash* hash, const char* key, ... );
51
52
53 /**
54   @return A list of strings representing the keys of the hash. 
55   caller is responsible for freeing the returned string array 
56   with osrfStringArrayFree();
57   */
58 osrfStringArray* osrfBigHashKeys( osrfBigHash* hash );
59
60 /**
61   Frees a hash
62   */
63 void osrfBigHashFree( osrfBigHash* hash );
64
65 /**
66   @return The number of items in the hash
67   */
68 unsigned long osrfBigHashGetCount( osrfBigHash* hash );
69
70
71
72
73 /**
74   Creates a new list iterator with the given list
75   */
76 osrfBigHashIterator* osrfNewBigHashIterator( osrfBigHash* hash );
77
78 /**
79   Returns the next non-NULL item in the list, return NULL when
80   the end of the list has been reached
81   */
82 void* osrfBigHashIteratorNext( osrfBigHashIterator* itr );
83
84 /**
85   Deallocates the given list
86   */
87 void osrfBigHashIteratorFree( osrfBigHashIterator* itr );
88
89 void osrfBigHashIteratorReset( osrfBigHashIterator* itr );
90
91 #ifdef __cplusplus
92 }
93 #endif
94
95 #endif