4 #include <opensrf/utils.h>
5 #include <opensrf/string_array.h>
6 #include <opensrf/osrf_list.h>
12 struct _osrfHashStruct;
13 typedef struct _osrfHashStruct osrfHash;
15 struct _osrfHashIteratorStruct;
16 typedef struct _osrfHashIteratorStruct osrfHashIterator;
19 Allocates a new hash object
21 osrfHash* osrfNewHash();
23 /** Installs a callback function for freeing stored items
25 void osrfHashSetCallback( osrfHash* hash, void (*callback) (char* key, void* item) );
28 Sets the given key with the given item
29 if "freeItem" is defined and an item already exists at the given location,
30 then old item is freed and the new item is put into place.
31 if "freeItem" is not defined and an item already exists, the old item
33 @return The old item if exists and there is no 'freeItem', returns NULL
36 void* osrfHashSet( osrfHash* hash, void* item, const char* key, ... );
39 Removes an item from the hash.
40 if 'freeItem' is defined it is used and NULL is returned,
41 else the freed item is returned
43 void* osrfHashRemove( osrfHash* hash, const char* key, ... );
45 void* osrfHashGet( osrfHash* hash, const char* key );
47 void* osrfHashGetFmt( 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 );
67 Creates a new list iterator with the given list
69 osrfHashIterator* osrfNewHashIterator( osrfHash* hash );
71 int osrfHashIteratorHasNext( osrfHashIterator* itr );
74 Returns the next non-NULL item in the list, return NULL when
75 the end of the list has been reached
77 void* osrfHashIteratorNext( osrfHashIterator* itr );
80 Returns a pointer to the key of the current hash item
82 const char* osrfHashIteratorKey( const osrfHashIterator* itr );
85 Deallocates the given list
87 void osrfHashIteratorFree( osrfHashIterator* itr );
89 void osrfHashIteratorReset( osrfHashIterator* itr );