4 #include "opensrf/utils.h"
5 #include "opensrf/string_array.h"
8 #define OSRF_HASH_MAXKEY 256
10 #define OSRF_HASH_KEY_MASK 0x7FF /* hash keys are a maximun of 2047 in size */
11 #define OSRF_HASH_KEY_SIZE 2048 /* size of the container list for the keys */
14 struct __osrfHashStruct {
15 osrfList* hash; /* this hash */
16 void (*freeItem) (char* key, void* item); /* callback for freeing stored items */
19 typedef struct __osrfHashStruct osrfHash;
21 struct _osrfHashNodeStruct {
25 typedef struct _osrfHashNodeStruct osrfHashNode;
28 struct __osrfHashIteratorStruct {
32 osrfStringArray* keys;
34 typedef struct __osrfHashIteratorStruct osrfHashIterator;
36 osrfHashNode* osrfNewHashNode(char* key, void* item);
37 void osrfHashNodeFree(osrfHashNode*);
40 Allocates a new hash object
42 osrfHash* osrfNewHash();
45 Sets the given key with the given item
46 if "freeItem" is defined and an item already exists at the given location,
47 then old item is freed and the new item is put into place.
48 if "freeItem" is not defined and an item already exists, the old item
50 @return The old item if exists and there is no 'freeItem', returns NULL
53 void* osrfHashSet( osrfHash* hash, void* item, const char* key, ... );
56 Removes an item from the hash.
57 if 'freeItem' is defined it is used and NULL is returned,
58 else the freed item is returned
60 void* osrfHashRemove( osrfHash* hash, const char* key, ... );
62 void* osrfHashGet( osrfHash* hash, const char* key, ... );
66 @return A list of strings representing the keys of the hash.
67 caller is responsible for freeing the returned string array
68 with osrfStringArrayFree();
70 osrfStringArray* osrfHashKeys( osrfHash* hash );
75 void osrfHashFree( osrfHash* hash );
78 @return The number of items in the hash
80 unsigned long osrfHashGetCount( osrfHash* hash );
86 Creates a new list iterator with the given list
88 osrfHashIterator* osrfNewHashIterator( osrfHash* hash );
91 Returns the next non-NULL item in the list, return NULL when
92 the end of the list has been reached
94 void* osrfHashIteratorNext( osrfHashIterator* itr );
97 Deallocates the given list
99 void osrfHashIteratorFree( osrfHashIterator* itr );
101 void osrfHashIteratorReset( osrfHashIterator* itr );