commit: r275 - in trunk: libspread stdutil/src

[email protected]
Newsgroups gmane.network.spread.cvs
Message-ID <[email protected]>
Author: jschultz
Date: 2005-09-01 15:27:47 -0400 (Thu, 01 Sep 2005)
New Revision: 275

Modified:
   trunk/libspread/fl.c
   trunk/libspread/fl_p.h
   trunk/stdutil/src/stdhash.c
Log:
Fix to stdhash and minor changes in hash/cmp fcns in flush. Still needs more work and testing.



Modified: trunk/libspread/fl.c
===================================================================
--- trunk/libspread/fl.c	2005-08-30 13:53:19 UTC (rev 274)
+++ trunk/libspread/fl.c	2005-09-01 19:27:47 UTC (rev 275)
@@ -984,6 +984,7 @@
 
     /* get groups info out of the msg: either in um->groups or um->new_grps */
     get_groups_info(um, &bm->num_groups, (char(**)[MAX_GROUP_NAME]) &groups);
+
     if ((groups_size = bm->num_groups * MAX_GROUP_NAME) != 0) {
       if ((bm->groups = (char(*)[MAX_GROUP_NAME]) malloc(groups_size)) == 0)
 	stderr_abort("(%s, %d): malloc(%u)\n", __FILE__, __LINE__, groups_size);    
@@ -2139,35 +2140,27 @@
 }
 
 /* hashing fcns for group names */
-static stdbool group_name_cmp(const void *str1, const void *str2) {
+static int group_name_cmp(const void *str1, const void *str2) {
   return strncmp((const char*) str1, (const char*) str2, MAX_GROUP_NAME);
 }
 
-static size_t group_name_hashcode(const void *str) {
-  const stduint8 *key = (const stduint8*) str, *end = key + MAX_GROUP_NAME;
-  size_t ret = 0;
-  
-  while (key != end && *key != 0) 
-    ret = ret * 33 + *key++;
-  
-  return ret;
+static stdhcode group_name_hashcode(const void *str) {
+  return stdhcode_sfh(str, strlen((const char*) str));
 }
 
-static stdbool group_name_ptr_cmp(const void *strptr1, const void *strptr2) {
+static int group_name_ptr_cmp(const void *strptr1, const void *strptr2) {
   return strncmp(*(const char**) strptr1, *(const char**) strptr2, MAX_GROUP_NAME);
 }
 
-static size_t group_name_ptr_hashcode(const void *strptr) {
+static stdhcode group_name_ptr_hashcode(const void *strptr) {
   return group_name_hashcode(*(const void**) strptr);
 }
 
-static stdbool group_id_cmp(const void *gid1, const void *gid2) {
+static int group_id_cmp(const void *gid1, const void *gid2) {
   return memcmp(gid1, gid2, sizeof(group_id));
 }
 
-static size_t group_id_hashcode(const void *gid) {
-  group_id *gid2 = (group_id*) gid;
-
-  return (gid2->id[0] ^ gid2->id[1] ^ gid2->id[2]);
+static stdhcode group_id_hashcode(const void *gid) {
+  return stdhcode_sfh(gid, sizeof(group_id));
 }
 

Modified: trunk/libspread/fl_p.h
===================================================================
--- trunk/libspread/fl_p.h	2005-08-30 13:53:19 UTC (rev 274)
+++ trunk/libspread/fl_p.h	2005-09-01 19:27:47 UTC (rev 275)
@@ -334,12 +334,12 @@
 static float FL_SP_version(void);
 
 /* group name hash fcns: used by stdhashs where the keys are group_names */
-static stdbool group_name_cmp(const void *str1, const void *str2);
-static size_t  group_name_hashcode(const void *str);
-static stdbool group_name_ptr_cmp(const void *str_ptr1, const void *str_ptr2);
-static size_t  group_name_ptr_hashcode(const void *str_ptr);
-static stdbool group_id_cmp(const void *gid1, const void *gid2);
-static size_t  group_id_hashcode(const void *gid);
+static int      group_name_cmp(const void *str1, const void *str2);
+static stdhcode group_name_hashcode(const void *str);
+static int      group_name_ptr_cmp(const void *str_ptr1, const void *str_ptr2);
+static stdhcode group_name_ptr_hashcode(const void *str_ptr);
+static int      group_id_cmp(const void *gid1, const void *gid2);
+static stdhcode group_id_hashcode(const void *gid);
 
 #ifdef __cplusplus
 }

Modified: trunk/stdutil/src/stdhash.c
===================================================================
--- trunk/stdutil/src/stdhash.c	2005-08-30 13:53:19 UTC (rev 274)
+++ trunk/stdutil/src/stdhash.c	2005-09-01 19:27:47 UTC (rev 275)
@@ -461,7 +461,7 @@
 					    stdsize num_ins, stdbool overwrite, stdbool advance) 
 {
   stdcode         ret       = STDESUCCESS;
-  stdsize         hthresh      = stdhash_high_thresh(h);
+  stdsize         hthresh   = stdhash_high_thresh(h);
   stdhash_node ** search    = NULL;  
   stdhash_node ** first_ins = NULL;
   stdit           src_it    = *b;
@@ -474,7 +474,7 @@
 
     /* check the loading factor on the table: grow/rehash if necessary */
 
-    if (h->num_nodes > hthresh) {                                       /* load factor too high */
+    if (h->num_nodes >= hthresh) {                                      /* load factor too high */
 
       if ((h->opts & STDHASH_OPTS_NO_AUTO_GROW) != 0) {                 /* growth disallowed */
 	ret = STDEACCES;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.