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 {
20 osrfStringArray* keys;
22 typedef struct _osrfHashIteratorStruct osrfHashIterator;
25 Allocates a new hash object
27 osrfHash* osrfNewHash();
30 Sets the given key with the given item
31 if "freeItem" is defined and an item already exists at the given location,
32 then old item is freed and the new item is put into place.
33 if "freeItem" is not defined and an item already exists, the old item
35 @return The old item if exists and there is no 'freeItem', returns NULL
38 void* osrfHashSet( osrfHash* hash, void* item, const char* key, ... );
41 Removes an item from the hash.
42 if 'freeItem' is defined it is used and NULL is returned,
43 else the freed item is returned
45 void* osrfHashRemove( osrfHash* hash, const char* key, ... );
47 void* osrfHashGet( osrfHash* hash, const char* key, ... );
51 @return A list of strings representing the keys of the hash.
52 caller is responsible for freeing the returned string array
53 with osrfStringArrayFree();
55 osrfStringArray* osrfHashKeys( osrfHash* hash );
57 osrfStringArray* osrfHashKeysInc( osrfHash* hash );
62 void osrfHashFree( osrfHash* hash );
65 @return The number of items in the hash
67 unsigned long osrfHashGetCount( osrfHash* hash );
73 Creates a new list iterator with the given list
75 osrfHashIterator* osrfNewHashIterator( osrfHash* hash );
77 int osrfHashIteratorHasNext( osrfHashIterator* itr );
80 Returns the next non-NULL item in the list, return NULL when
81 the end of the list has been reached
83 void* osrfHashIteratorNext( osrfHashIterator* itr );
86 Deallocates the given list
88 void osrfHashIteratorFree( osrfHashIterator* itr );
90 void osrfHashIteratorReset( osrfHashIterator* itr );