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