4 #include <opensrf/utils.h>
5 #include <opensrf/string_array.h>
6 #include <opensrf/osrf_list.h>
8 struct _osrfHashStruct {
9 osrfList* hash; /* this hash */
10 void (*freeItem) (char* key, void* item); /* callback for freeing stored items */
12 osrfStringArray* keys;
14 typedef struct _osrfHashStruct osrfHash;
16 struct _osrfHashIteratorStruct {
18 size_t currsize; // length of "current" buffer
21 osrfStringArray* keys;
23 typedef struct _osrfHashIteratorStruct osrfHashIterator;
26 Allocates a new hash object
28 osrfHash* osrfNewHash();
31 Sets the given key with the given item
32 if "freeItem" is defined and an item already exists at the given location,
33 then old item is freed and the new item is put into place.
34 if "freeItem" is not defined and an item already exists, the old item
36 @return The old item if exists and there is no 'freeItem', returns NULL
39 void* osrfHashSet( osrfHash* hash, void* item, const char* key, ... );
42 Removes an item from the hash.
43 if 'freeItem' is defined it is used and NULL is returned,
44 else the freed item is returned
46 void* osrfHashRemove( osrfHash* hash, const char* key, ... );
48 void* osrfHashGet( osrfHash* hash, const char* key, ... );
52 @return A list of strings representing the keys of the hash.
53 caller is responsible for freeing the returned string array
54 with osrfStringArrayFree();
56 osrfStringArray* osrfHashKeys( osrfHash* hash );
58 osrfStringArray* osrfHashKeysInc( osrfHash* hash );
63 void osrfHashFree( osrfHash* hash );
66 @return The number of items in the hash
68 unsigned long osrfHashGetCount( osrfHash* hash );
74 Creates a new list iterator with the given list
76 osrfHashIterator* osrfNewHashIterator( osrfHash* hash );
78 int osrfHashIteratorHasNext( osrfHashIterator* itr );
81 Returns the next non-NULL item in the list, return NULL when
82 the end of the list has been reached
84 void* osrfHashIteratorNext( osrfHashIterator* itr );
87 Deallocates the given list
89 void osrfHashIteratorFree( osrfHashIterator* itr );
91 void osrfHashIteratorReset( osrfHashIterator* itr );