#include <opensrf/string_array.h>
#include <opensrf/osrf_list.h>
-/* 0x100 is a good size for small hashes */
-//#define OSRF_HASH_LIST_SIZE 0x100 /* size of the main hash list */
-#define OSRF_HASH_LIST_SIZE 0x10 /* size of the main hash list */
-
-
-/* used internally */
-#define OSRF_HASH_NODE_FREE(h, n) \
- if(h && n) { \
- if(h->freeItem) h->freeItem(n->key, n->item);\
- free(n->key); free(n); \
- }
-
-
-struct __osrfHashStruct {
+struct _osrfHashStruct {
osrfList* hash; /* this hash */
void (*freeItem) (char* key, void* item); /* callback for freeing stored items */
unsigned int size;
osrfStringArray* keys;
};
-typedef struct __osrfHashStruct osrfHash;
+typedef struct _osrfHashStruct osrfHash;
-struct _osrfHashNodeStruct {
- char* key;
- void* item;
-};
-typedef struct _osrfHashNodeStruct osrfHashNode;
-
-
-struct __osrfHashIteratorStruct {
+struct _osrfHashIteratorStruct {
char* current;
int currentIdx;
osrfHash* hash;
osrfStringArray* keys;
};
-typedef struct __osrfHashIteratorStruct osrfHashIterator;
-
-osrfHashNode* osrfNewHashNode(char* key, void* item);
-void* osrfHashNodeFree(osrfHash*, osrfHashNode*);
+typedef struct _osrfHashIteratorStruct osrfHashIterator;
/**
Allocates a new hash object
#include <opensrf/osrf_hash.h>
+struct _osrfHashNodeStruct {
+ char* key;
+ void* item;
+};
+typedef struct _osrfHashNodeStruct osrfHashNode;
+
+/* 0x100 is a good size for small hashes */
+//#define OSRF_HASH_LIST_SIZE 0x100 /* size of the main hash list */
+#define OSRF_HASH_LIST_SIZE 0x10 /* size of the main hash list */
+
+/* used internally */
+#define OSRF_HASH_NODE_FREE(h, n) \
+ if(h && n) { \
+ if(h->freeItem) h->freeItem(n->key, n->item);\
+ free(n->key); free(n); \
+}
+
+static osrfHashNode* osrfNewHashNode(char* key, void* item);
+static void* osrfHashNodeFree(osrfHash*, osrfHashNode*);
+
osrfHash* osrfNewHash() {
osrfHash* hash;
OSRF_MALLOC(hash, sizeof(osrfHash));
hash->hash = osrfNewList();
+ hash->freeItem = NULL;
+ hash->size = 0;
hash->keys = osrfNewStringArray(64);
return hash;
}
-
-/* algorithm proposed by Donald E. Knuth
+/* algorithm proposed by Donald E. Knuth
* in The Art Of Computer Programming Volume 3 (more or less..)*/
/*
static unsigned int osrfHashMakeKey(char* str) {
return k;
}
-osrfHashNode* osrfNewHashNode(char* key, void* item) {
+static osrfHashNode* osrfNewHashNode(char* key, void* item) {
if(!(key && item)) return NULL;
osrfHashNode* n;
OSRF_MALLOC(n, sizeof(osrfHashNode));
return n;
}
-void* osrfHashNodeFree(osrfHash* hash, osrfHashNode* node) {
+static void* osrfHashNodeFree(osrfHash* hash, osrfHashNode* node) {
if(!(node && hash)) return NULL;
void* item = NULL;
if( hash->freeItem )
osrfHashIterator* itr;
OSRF_MALLOC(itr, sizeof(osrfHashIterator));
itr->hash = hash;
+ itr->currentIdx = 0;
itr->current = NULL;
itr->keys = osrfHashKeysInc(hash);
return itr;