rnd-20030428-1-src
[rocksndiamonds.git] / src / libgame / setup.c
index 1e9a56e2e1917f2f2779fc8c2256a065d42be6bc..102d5fd13d92d0bd7fa1fa0ca494d7ecbe34994b 100644 (file)
@@ -1040,6 +1040,18 @@ char *getFormattedSetupEntry(char *token, char *value)
   return entry;
 }
 
   return entry;
 }
 
+SetupFileList *newSetupFileList(char *token, char *value)
+{
+  SetupFileList *new = checked_malloc(sizeof(SetupFileList));
+
+  new->token = getStringCopy(token);
+  new->value = getStringCopy(value);
+
+  new->next = NULL;
+
+  return new;
+}
+
 void freeSetupFileList(SetupFileList *list)
 {
   if (list == NULL)
 void freeSetupFileList(SetupFileList *list)
 {
   if (list == NULL)
@@ -1054,18 +1066,6 @@ void freeSetupFileList(SetupFileList *list)
   free(list);
 }
 
   free(list);
 }
 
-SetupFileList *newSetupFileList(char *token, char *value)
-{
-  SetupFileList *new = checked_malloc(sizeof(SetupFileList));
-
-  new->token = getStringCopy(token);
-  new->value = getStringCopy(value);
-
-  new->next = NULL;
-
-  return new;
-}
-
 char *getListEntry(SetupFileList *list, char *token)
 {
   if (list == NULL)
 char *getListEntry(SetupFileList *list, char *token)
 {
   if (list == NULL)
@@ -1125,11 +1125,19 @@ static unsigned int get_hash_from_key(void *key)
   /*
     djb2
 
   /*
     djb2
 
-    this algorithm (k=33) was first reported by dan bernstein many years ago in
-    comp.lang.c. another version of this algorithm (now favored by bernstein)
-    uses xor: hash(i) = hash(i - 1) * 33 ^ str[i]; the magic of number 33 (why
+    This algorithm (k=33) was first reported by Dan Bernstein many years ago in
+    'comp.lang.c'. Another version of this algorithm (now favored by Bernstein)
+    uses XOR: hash(i) = hash(i - 1) * 33 ^ str[i]; the magic of number 33 (why
     it works better than many other constants, prime or not) has never been
     adequately explained.
     it works better than many other constants, prime or not) has never been
     adequately explained.
+
+    If you just want to have a good hash function, and cannot wait, djb2
+    is one of the best string hash functions i know. It has excellent
+    distribution and speed on many different sets of keys and table sizes.
+    You are not likely to do better with one of the "well known" functions
+    such as PJW, K&R, etc.
+
+    Ozan (oz) Yigit [http://www.cs.yorku.ca/~oz/hash.html]
   */
 
   char *str = (char *)key;
   */
 
   char *str = (char *)key;
@@ -1147,15 +1155,6 @@ static int keys_are_equal(void *key1, void *key2)
   return (strcmp((char *)key1, (char *)key2) == 0);
 }
 
   return (strcmp((char *)key1, (char *)key2) == 0);
 }
 
-void freeSetupFileHash(SetupFileHash *hash)
-{
-  if (hash == NULL)
-    return;
-
-  hashtable_destroy(hash, 1);  /* 1 == also free values */
-  free(hash);
-}
-
 SetupFileHash *newSetupFileHash()
 {
   SetupFileHash *new_hash =
 SetupFileHash *newSetupFileHash()
 {
   SetupFileHash *new_hash =
@@ -1164,6 +1163,14 @@ SetupFileHash *newSetupFileHash()
   return new_hash;
 }
 
   return new_hash;
 }
 
+void freeSetupFileHash(SetupFileHash *hash)
+{
+  if (hash == NULL)
+    return;
+
+  hashtable_destroy(hash, 1);  /* 1 == also free values stored in hash */
+}
+
 char *getHashEntry(SetupFileHash *hash, char *token)
 {
   if (hash == NULL)
 char *getHashEntry(SetupFileHash *hash, char *token)
 {
   if (hash == NULL)
@@ -1191,26 +1198,6 @@ void setHashEntry(SetupFileHash *hash, char *token, char *value)
 #ifdef DEBUG
 static void printSetupFileHash(SetupFileHash *hash)
 {
 #ifdef DEBUG
 static void printSetupFileHash(SetupFileHash *hash)
 {
-#if 0
-  if (hash == NULL)
-    return;
-
-  /* iterator constructor only returns valid iterator for non-empty hash */
-  if (hash != NULL && hashtable_count(hash) > 0)
-  {
-    struct hashtable_itr *itr = hashtable_iterator(hash);
-
-    do
-    {
-      printf("token: '%s'\n", (char *)hashtable_iterator_key(itr));
-      printf("value: '%s'\n", (char *)hashtable_iterator_value(itr));
-    }
-    while (hashtable_iterator_advance(itr));
-
-    free(itr);
-  }
-#endif
-
   BEGIN_HASH_ITERATION(hash, itr)
   {
     printf("token: '%s'\n", HASH_ITERATION_TOKEN(itr));
   BEGIN_HASH_ITERATION(hash, itr)
   {
     printf("token: '%s'\n", HASH_ITERATION_TOKEN(itr));
@@ -2381,6 +2368,7 @@ static void checkSeriesInfo()
 
       levelnum_value = atoi(levelnum_str);
 
 
       levelnum_value = atoi(levelnum_str);
 
+#if 0
       if (levelnum_value < leveldir_current->first_level)
       {
        Error(ERR_WARN, "additional level %d found", levelnum_value);
       if (levelnum_value < leveldir_current->first_level)
       {
        Error(ERR_WARN, "additional level %d found", levelnum_value);
@@ -2391,6 +2379,7 @@ static void checkSeriesInfo()
        Error(ERR_WARN, "additional level %d found", levelnum_value);
        leveldir_current->last_level = levelnum_value;
       }
        Error(ERR_WARN, "additional level %d found", levelnum_value);
        leveldir_current->last_level = levelnum_value;
       }
+#endif
     }
   }
 
     }
   }