]> git.evergreen-ils.org Git - OpenSRF.git/blob - include/opensrf/osrf_big_hash.h
Commit autotools patch from Kevin Beswick
[OpenSRF.git] / include / opensrf / osrf_big_hash.h
1 #ifndef OSRF_HASH_H
2 #define OSRF_HASH_H
3
4 #include <Judy.h>
5 #include <opensrf/utils.h>
6 #include <opensrf/string_array.h>
7
8 #define OSRF_HASH_MAXKEY 256
9
10 struct __osrfBigHashStruct {
11         Pvoid_t hash;                                                   /* the hash */
12         void (*freeItem) (char* key, void* item);       /* callback for freeing stored items */
13 };
14 typedef struct __osrfBigHashStruct osrfBigHash;
15
16
17 struct __osrfBigHashIteratorStruct {
18         char* current;
19         osrfBigHash* hash;
20 };
21 typedef struct __osrfBigHashIteratorStruct osrfBigHashIterator;
22
23 /**
24   Allocates a new hash object
25   */
26 osrfBigHash* osrfNewBigHash();
27
28 /**
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
33   is returned.
34   @return The old item if exists and there is no 'freeItem', returns NULL
35   otherwise
36   */
37 void* osrfBigHashSet( osrfBigHash* hash, void* item, const char* key, ... );
38
39 /**
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
43   */
44 void* osrfBigHashRemove( osrfBigHash* hash, const char* key, ... );
45
46 void* osrfBigHashGet( osrfBigHash* hash, const char* key, ... );
47
48
49 /**
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();
53   */
54 osrfStringArray* osrfBigHashKeys( osrfBigHash* hash );
55
56 /**
57   Frees a hash
58   */
59 void osrfBigHashFree( osrfBigHash* hash );
60
61 /**
62   @return The number of items in the hash
63   */
64 unsigned long osrfBigHashGetCount( osrfBigHash* hash );
65
66
67
68
69 /**
70   Creates a new list iterator with the given list
71   */
72 osrfBigHashIterator* osrfNewBigHashIterator( osrfBigHash* hash );
73
74 /**
75   Returns the next non-NULL item in the list, return NULL when
76   the end of the list has been reached
77   */
78 void* osrfBigHashIteratorNext( osrfBigHashIterator* itr );
79
80 /**
81   Deallocates the given list
82   */
83 void osrfBigHashIteratorFree( osrfBigHashIterator* itr );
84
85 void osrfBigHashIteratorReset( osrfBigHashIterator* itr );
86
87 #endif