/[rdesktop]/sourceforge.net/trunk/seamlessrdp/ClientDLL/hash.cpp
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sourceforge.net/trunk/seamlessrdp/ClientDLL/hash.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 936 by astrand, Thu Jun 30 14:46:14 2005 UTC revision 937 by astrand, Fri Jul 1 06:50:52 2005 UTC
# Line 15  Line 15 
15  */  */
16    
17  /* HW: HenkJan Wolthuis, 1997, public domain  /* HW: HenkJan Wolthuis, 1997, public domain
18    
19        changed functionnames, all public functions now have a 'hash_' prefix        changed functionnames, all public functions now have a 'hash_' prefix
20        minor editing, marked 'm all(?) with a description        minor editing, marked 'm all(?) with a description
21        removed a bug in hash_del and one in hash_enumerate        removed a bug in hash_del and one in hash_enumerate
# Line 137  void *hash_insert(char *key, void *data, Line 137  void *hash_insert(char *key, void *data,
137              return NULL;              return NULL;
138    
139          if (NULL ==          if (NULL ==
140              ((table->table)[val]->key = (char *) malloc(strlen(key) + 1))) {                  ((table->table)[val]->key = (char *) malloc(strlen(key) + 1))) {
141              free((table->table)[val]);              free((table->table)[val]);
142              (table->table)[val] = NULL;              (table->table)[val] = NULL;
143              return NULL;              return NULL;
# Line 149  void *hash_insert(char *key, void *data, Line 149  void *hash_insert(char *key, void *data,
149          return (table->table)[val]->data;          return (table->table)[val]->data;
150      }      }
151    
152  /* HW: added a #define so the hashtable can accept duplicate keys */      /* HW: added a #define so the hashtable can accept duplicate keys */
153  #ifndef DUPLICATE_KEYS  #ifndef DUPLICATE_KEYS
154      /*      /*
155       ** This spot in the table is already in use.  See if the current string       ** This spot in the table is already in use.  See if the current string
# Line 237  void *hash_del(char *key, hash_table * t Line 237  void *hash_del(char *key, hash_table * t
237       ** contains.       ** contains.
238       */       */
239      for (last = NULL, ptr = (table->table)[val];      for (last = NULL, ptr = (table->table)[val];
240           NULL != ptr; last = ptr, ptr = ptr->next) {              NULL != ptr; last = ptr, ptr = ptr->next) {
241          if (0 == strcmp(key, ptr->key)) {          if (0 == strcmp(key, ptr->key)) {
242              if (last != NULL) {              if (last != NULL) {
243                  data = ptr->data;                  data = ptr->data;
# Line 290  static void free_node(char *key, void *d Line 290  static void free_node(char *key, void *d
290    
291      if (NULL != function) {      if (NULL != function) {
292          function(hash_del(key, the_table));          function(hash_del(key, the_table));
293      }      } else
     else  
294          hash_del(key, the_table);          hash_del(key, the_table);
295  }  }
296    
# Line 344  void hash_enumerate(hash_table * table, Line 343  void hash_enumerate(hash_table * table,
343  }  }
344    
345  /*      HW: added hash_sorted_enum()  /*      HW: added hash_sorted_enum()
346    
347        hash_sorted_enum is like hash_enumerate but gives        hash_sorted_enum is like hash_enumerate but gives
348        sorted output. This is much slower than hash_enumerate, but        sorted output. This is much slower than hash_enumerate, but
349        sometimes nice for printing to a file...        sometimes nice for printing to a file...
# Line 354  typedef struct sort_struct Line 353  typedef struct sort_struct
353  {  {
354      char *key;      char *key;
355      void *data;      void *data;
356  } sort_struct;  }
357    sort_struct;
358  static sort_struct *sortmap = NULL;  static sort_struct *sortmap = NULL;
359    
360  static int counter = 0;  static int counter = 0;
# Line 389  int hash_sorted_enum(hash_table * table, Line 389  int hash_sorted_enum(hash_table * table,
389    
390      /* malloc an pointerarray for all hashkey's and datapointers */      /* malloc an pointerarray for all hashkey's and datapointers */
391      if (NULL ==      if (NULL ==
392          (sortmap =              (sortmap =
393           (sort_struct *) malloc(sizeof(sort_struct) * table->count)))                   (sort_struct *) malloc(sizeof(sort_struct) * table->count)))
394          return 0;          return 0;
395    
396      /* copy the pointers to the hashkey's */      /* copy the pointers to the hashkey's */
# Line 445  int main(void) Line 445  int main(void)
445      hash_table table;      hash_table table;
446    
447      char *strings[] = {      char *strings[] = {
448          "The first string",                            "The first string",
449          "The second string",                            "The second string",
450          "The third string",                            "The third string",
451          "The fourth string",                            "The fourth string",
452          "A much longer string than the rest in this example.",                            "A much longer string than the rest in this example.",
453          "The last string",                            "The last string",
454          NULL                            NULL
455      };                        };
456    
457      char *junk[] = {      char *junk[] = {
458          "The first data",                         "The first data",
459          "The second data",                         "The second data",
460          "The third data",                         "The third data",
461          "The fourth data",                         "The fourth data",
462          "The fifth datum",                         "The fifth datum",
463          "The sixth piece of data"                         "The sixth piece of data"
464      };                     };
465    
466      int i;      int i;
467      void *j;      void *j;

Legend:
Removed from v.936  
changed lines
  Added in v.937

  ViewVC Help
Powered by ViewVC 1.1.26