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
* in The Art Of Computer Programming Volume 3 (more or less..)*/
+/*
static unsigned int osrfHashMakeKey(char* str) {
if(!str) return 0;
unsigned int len = strlen(str);
h = ((h << 5) ^ (h >> 27)) ^ (*str);
return (h & (OSRF_HASH_LIST_SIZE-1));
}
+*/
-/*
-#define OSRF_HASH_MAKE_KEY(str,num) \
- do {\
- unsigned int len = strlen(str); \
- unsigned int h = len;\
- unsigned int i = 0;\
- for(i = 0; i < len; str++, i++)\
- h = ((h << 5) ^ (h >> 27)) ^ (*str);\
- *num = (h & (OSRF_HASH_LIST_SIZE-1));\
- } while(0)
- */
-
-/*
-#define OSRF_HASH_MAKE_KEY(str,num) \
- unsigned int ___len = strlen(str);\
- unsigned int ___h = ___len;\
- unsigned int ___i = 0;\
- for(___i = 0; ___i < ___len; str++, ___i++)\
- ___h = ((___h << 5) ^ (___h >> 27)) ^ (*str);\
- num = (___h & (OSRF_HASH_LIST_SIZE-1));\
- */
-
-/*
-#define OSRF_HASH_MAKE_KEY(str,num,len) \
- unsigned int __i;\
- num = len;\
- for(__i = 0; __i < len; __i++, str++)\
- num = ((num << 5) ^ (num >> 27)) ^ (*str);\
- num = (num & (OSRF_HASH_LIST_SIZE-1));\
- */
+/* macro version of the above function */
+#define OSRF_HASH_MAKE_KEY(str,num) \
+ do {\
+ char* __k = str;\
+ unsigned int __len = strlen(__k); \
+ unsigned int __h = __len;\
+ unsigned int __i = 0;\
+ for(__i = 0; __i < __len; __k++, __i++)\
+ __h = ((__h << 5) ^ (__h >> 27)) ^ (*__k);\
+ num = (__h & (OSRF_HASH_LIST_SIZE-1));\
+ } while(0)
-/*
-#define OSRF_HASH_MAKE_KEY(str,num, len) \
- num = osrfHashMakeKey(str);\
- fprintf(stderr, "made num: %d\n", num);
- */
-
/* returns the index of the item and points l to the sublist the item
if(!(hash && key)) return -1;
- int i = osrfHashMakeKey(key);
-
- /*
- unsigned int i;
- OSRF_HASH_MAKE_KEY(key, &i);
- */
+ unsigned int i = 0;
+ OSRF_HASH_MAKE_KEY(key,i);
osrfList* list = OSRF_LIST_GET_INDEX( hash->hash, i );
if( !list ) { return -1; }
VA_LIST_TO_STRING(key);
void* olditem = osrfHashRemove( hash, VA_BUF );
- int bucketkey = osrfHashMakeKey(VA_BUF);
-
- /*
- unsigned int bucketkey;
- OSRF_HASH_MAKE_KEY(VA_BUF, &bucketkey);
- */
-
+ unsigned int bucketkey = 0;
+ OSRF_HASH_MAKE_KEY(VA_BUF,bucketkey);
+
osrfList* bucket;
if( !(bucket = OSRF_LIST_GET_INDEX(hash->hash, bucketkey)) ) {
bucket = osrfNewList();
}
-
+int osrfHashIteratorHasNext( osrfHashIterator* itr ) {
+ return ( itr->currentIdx < itr->keys->size ) ? 1 : 0;
+}
*/
osrfHashIterator* osrfNewHashIterator( osrfHash* hash );
+int osrfHashIteratorHasNext( osrfHashIterator* itr );
+
/**
Returns the next non-NULL item in the list, return NULL when
the end of the list has been reached
#include "osrf_list.h"
osrfList* osrfNewList() {
- //osrfList* list = safe_malloc(sizeof(osrfList));
osrfList* list;
OSRF_MALLOC(list, sizeof(osrfList));
- list->size = 0;
- list->freeItem = NULL;
list->arrsize = OSRF_LIST_DEFAULT_SIZE;
- //list->arrlist = safe_malloc( list->arrsize * sizeof(void*) );
OSRF_MALLOC(list->arrlist, list->arrsize * sizeof(void*));
return list;
}
osrfList* osrfNewListSize( unsigned int size ) {
- //osrfList* list = safe_malloc(sizeof(osrfList));
osrfList* list;
OSRF_MALLOC(list, sizeof(osrfList));
- list->size = 0;
- list->freeItem = NULL;
list->arrsize = size;
- //list->arrlist = safe_malloc( list->arrsize * sizeof(void*) );
OSRF_MALLOC( list->arrlist, list->arrsize * sizeof(void*) );
return list;
}
void* olditem = osrfListRemove( list, position );
list->arrlist[position] = item;
- if( list->size == 0 || list->size <= position )
- list->size = position + 1;
+ //if( list->size == 0 || list->size <= position )
+ if( list->size <= position ) list->size = position + 1;
return olditem;
}
if(full_escape) {
switch(c) {
case '"':
- buffer_add_char(buf, '\\');
- buffer_add_char(buf, '"');
+ OSRF_BUFFER_ADD_CHAR(buf, '\\');
+ OSRF_BUFFER_ADD_CHAR(buf, '"');
break;
case '\b':
- buffer_add_char(buf, '\\');
- buffer_add_char(buf, 'b');
+ OSRF_BUFFER_ADD_CHAR(buf, '\\');
+ OSRF_BUFFER_ADD_CHAR(buf, 'b');
break;
case '\f':
- buffer_add_char(buf, '\\');
- buffer_add_char(buf, 'f');
+ OSRF_BUFFER_ADD_CHAR(buf, '\\');
+ OSRF_BUFFER_ADD_CHAR(buf, 'f');
break;
case '\t':
- buffer_add_char(buf, '\\');
- buffer_add_char(buf, 't');
+ OSRF_BUFFER_ADD_CHAR(buf, '\\');
+ OSRF_BUFFER_ADD_CHAR(buf, 't');
break;
case '\n':
- buffer_add_char(buf, '\\');
- buffer_add_char(buf, 'n');
+ OSRF_BUFFER_ADD_CHAR(buf, '\\');
+ OSRF_BUFFER_ADD_CHAR(buf, 'n');
break;
case '\r':
- buffer_add_char(buf, '\\');
- buffer_add_char(buf, 'r');
+ OSRF_BUFFER_ADD_CHAR(buf, '\\');
+ OSRF_BUFFER_ADD_CHAR(buf, 'r');
break;
default:
- buffer_add_char(buf, c);
+ OSRF_BUFFER_ADD_CHAR(buf, c);
}
} else {
- buffer_add_char(buf, c);
+ OSRF_BUFFER_ADD_CHAR(buf, c);
}
}