2 #include "opensrf/utils.h"
3 #include "opensrf/string_array.h"
5 #define OSRF_HASH_MAXKEY 256
7 struct __osrfHashStruct {
8 Pvoid_t hash; /* the hash */
9 void (*freeItem) (char* key, void* item); /* callback for freeing stored items */
11 typedef struct __osrfHashStruct osrfHash;
14 struct __osrfHashIteratorStruct {
18 typedef struct __osrfHashIteratorStruct osrfHashIterator;
21 Allocates a new hash object
23 osrfHash* osrfNewHash();
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
31 @return The old item if exists and there is no 'freeItem', returns NULL
34 void* osrfHashSet( osrfHash* hash, void* item, const char* key, ... );
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
41 void* osrfHashRemove( osrfHash* hash, const char* key, ... );
43 void* osrfHashGet( osrfHash* hash, const char* key, ... );
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();
51 osrfStringArray* osrfHashKeys( osrfHash* hash );
56 void osrfHashFree( osrfHash* hash );
59 @return The number of items in the hash
61 unsigned long osrfHashGetCount( osrfHash* hash );
67 Creates a new list iterator with the given list
69 osrfHashIterator* osrfNewHashIterator( osrfHash* hash );
72 Returns the next non-NULL item in the list, return NULL when
73 the end of the list has been reached
75 void* osrfHashIteratorNext( osrfHashIterator* itr );
78 Deallocates the given list
80 void osrfHashIteratorFree( osrfHashIterator* itr );
82 void osrfHashIteratorReset( osrfHashIterator* itr );