5 #include "opensrf/utils.h"
6 #include "opensrf/string_array.h"
8 #define OSRF_HASH_MAXKEY 256
10 struct __osrfHashStruct {
11 Pvoid_t hash; /* the hash */
12 void (*freeItem) (char* key, void* item); /* callback for freeing stored items */
14 typedef struct __osrfHashStruct osrfHash;
17 struct __osrfHashIteratorStruct {
21 typedef struct __osrfHashIteratorStruct osrfHashIterator;
24 Allocates a new hash object
26 osrfHash* osrfNewHash();
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
34 @return The old item if exists and there is no 'freeItem', returns NULL
37 void* osrfHashSet( osrfHash* hash, void* item, const char* key, ... );
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
44 void* osrfHashRemove( osrfHash* hash, const char* key, ... );
46 void* osrfHashGet( osrfHash* hash, const char* key, ... );
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();
54 osrfStringArray* osrfHashKeys( osrfHash* hash );
59 void osrfHashFree( osrfHash* hash );
62 @return The number of items in the hash
64 unsigned long osrfHashGetCount( osrfHash* hash );
70 Creates a new list iterator with the given list
72 osrfHashIterator* osrfNewHashIterator( osrfHash* hash );
75 Returns the next non-NULL item in the list, return NULL when
76 the end of the list has been reached
78 void* osrfHashIteratorNext( osrfHashIterator* itr );
81 Deallocates the given list
83 void osrfHashIteratorFree( osrfHashIterator* itr );
85 void osrfHashIteratorReset( osrfHashIterator* itr );