[Opensrf-commits] r1204 - in trunk: include/opensrf src/libopensrf
svn at svn.open-ils.org
svn at svn.open-ils.org
Sun Jan 6 21:10:57 EST 2008
Author: miker
Date: 2008-01-06 20:46:42 -0500 (Sun, 06 Jan 2008)
New Revision: 1204
Modified:
trunk/include/opensrf/osrf_hash.h
trunk/src/libopensrf/osrf_hash.c
Log:
Patch from Scott McKellar:
1. Move several internal details from the header to the implementation
file:
The macros OSRF_HASH_LIST_SIZE and OSRF_HASH_NODE_FREE
The declaration of the osrfHashNode struct
The declarations of the osrfNewHashNode and osrfHashNodeFree
functions (which are now static)
2. Remove a leading underscore from each of the struct tags
__osrfHashStruct and __osrfHashIteratorStruct;
3. Explicitly initialize all struct members.
Modified: trunk/include/opensrf/osrf_hash.h
===================================================================
--- trunk/include/opensrf/osrf_hash.h 2008-01-07 00:37:13 UTC (rev 1203)
+++ trunk/include/opensrf/osrf_hash.h 2008-01-07 01:46:42 UTC (rev 1204)
@@ -5,45 +5,22 @@
#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;
+typedef struct _osrfHashIteratorStruct osrfHashIterator;
-osrfHashNode* osrfNewHashNode(char* key, void* item);
-void* osrfHashNodeFree(osrfHash*, osrfHashNode*);
-
/**
Allocates a new hash object
*/
Modified: trunk/src/libopensrf/osrf_hash.c
===================================================================
--- trunk/src/libopensrf/osrf_hash.c 2008-01-07 00:37:13 UTC (rev 1203)
+++ trunk/src/libopensrf/osrf_hash.c 2008-01-07 01:46:42 UTC (rev 1204)
@@ -1,15 +1,36 @@
#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) {
@@ -67,7 +88,7 @@
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));
@@ -76,7 +97,7 @@
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 )
@@ -204,6 +225,7 @@
osrfHashIterator* itr;
OSRF_MALLOC(itr, sizeof(osrfHashIterator));
itr->hash = hash;
+ itr->currentIdx = 0;
itr->current = NULL;
itr->keys = osrfHashKeysInc(hash);
return itr;
More information about the opensrf-commits
mailing list