Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Inline functions without their definitions don't make much sense.
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Tue, 12 Jun 2012 13:39:50 +0000 (15:39 +0200)
committerArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Tue, 12 Jun 2012 13:44:34 +0000 (15:44 +0200)
Declare xbt_dict_hash() and xbt_dict_hash_ext() as static inline,
and move their definitions in header file.

include/xbt/str.h
src/xbt/xbt_str.c

index ea8dcc3..63a3826 100644 (file)
@@ -49,9 +49,88 @@ XBT_PUBLIC(char *) xbt_str_diff(const char *a, const char *b);
 
 XBT_PUBLIC(char *) xbt_str_from_file(FILE * file);
 
 
 XBT_PUBLIC(char *) xbt_str_from_file(FILE * file);
 
-XBT_INLINE XBT_PUBLIC(unsigned int) xbt_dict_hash_ext(const char *str,
-                                                      int str_len);
-XBT_INLINE XBT_PUBLIC(unsigned int) xbt_dict_hash(const char *str);
+#define DJB2_HASH_FUNCTION
+//#define FNV_HASH_FUNCTION
+
+/**
+ * @brief Returns the hash code of a string.
+ */
+static XBT_INLINE unsigned int xbt_dict_hash_ext(const char *str, int str_len)
+{
+
+#ifdef DJB2_HASH_FUNCTION
+  /* fast implementation of djb2 algorithm */
+  int c;
+  register unsigned int hash = 5381;
+
+  while (str_len--) {
+    c = *str++;
+    hash = ((hash << 5) + hash) + c;    /* hash * 33 + c */
+  }
+# elif defined(FNV_HASH_FUNCTION)
+  register unsigned int hash = 0x811c9dc5;
+  unsigned char *bp = (unsigned char *) str;    /* start of buffer */
+  unsigned char *be = bp + str_len;     /* beyond end of buffer */
+
+  while (bp < be) {
+    /* multiply by the 32 bit FNV magic prime mod 2^32 */
+    hash +=
+        (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) +
+        (hash << 24);
+
+    /* xor the bottom with the current octet */
+    hash ^= (unsigned int) *bp++;
+  }
+
+# else
+  register unsigned int hash = 0;
+
+  while (str_len--) {
+    hash += (*str) * (*str);
+    str++;
+  }
+#endif
+
+  return hash;
+}
+
+/**
+ * @brief Returns the hash code of a string.
+ */
+static XBT_INLINE unsigned int xbt_dict_hash(const char *str)
+{
+#ifdef DJB2_HASH_FUNCTION
+  /* fast implementation of djb2 algorithm */
+  int c;
+  register unsigned int hash = 5381;
+
+  while ((c = *str++)) {
+    hash = ((hash << 5) + hash) + c;    /* hash * 33 + c */
+  }
+
+# elif defined(FNV_HASH_FUNCTION)
+  register unsigned int hash = 0x811c9dc5;
+
+  while (*str) {
+    /* multiply by the 32 bit FNV magic prime mod 2^32 */
+    hash +=
+        (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) +
+        (hash << 24);
+
+    /* xor the bottom with the current byte */
+    hash ^= (unsigned int) *str++;
+  }
+
+# else
+  register unsigned int hash = 0;
+
+  while (*str) {
+    hash += (*str) * (*str);
+    str++;
+  }
+#endif
+  return hash;
+}
                                                       
 /** @brief Classical alias to (char*)
  *
                                                       
 /** @brief Classical alias to (char*)
  *
index 920df6c..de49953 100644 (file)
@@ -6,9 +6,6 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-#define DJB2_HASH_FUNCTION
-//#define FNV_HASH_FUNCTION
-
 #include "portable.h"
 #include "xbt/misc.h"
 #include "xbt/sysdep.h"
 #include "portable.h"
 #include "xbt/misc.h"
 #include "xbt/sysdep.h"
@@ -906,87 +903,6 @@ char *xbt_str_from_file(FILE * file)
   return res;
 }
 
   return res;
 }
 
-/**
- * @brief Returns the hash code of a string.
- */
-XBT_INLINE unsigned int xbt_dict_hash_ext(const char *str,
-                                                 int str_len)
-{
-
-#ifdef DJB2_HASH_FUNCTION
-  /* fast implementation of djb2 algorithm */
-  int c;
-  register unsigned int hash = 5381;
-
-  while (str_len--) {
-    c = *str++;
-    hash = ((hash << 5) + hash) + c;    /* hash * 33 + c */
-  }
-# elif defined(FNV_HASH_FUNCTION)
-  register unsigned int hash = 0x811c9dc5;
-  unsigned char *bp = (unsigned char *) str;    /* start of buffer */
-  unsigned char *be = bp + str_len;     /* beyond end of buffer */
-
-  while (bp < be) {
-    /* multiply by the 32 bit FNV magic prime mod 2^32 */
-    hash +=
-        (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) +
-        (hash << 24);
-
-    /* xor the bottom with the current octet */
-    hash ^= (unsigned int) *bp++;
-  }
-
-# else
-  register unsigned int hash = 0;
-
-  while (str_len--) {
-    hash += (*str) * (*str);
-    str++;
-  }
-#endif
-
-  return hash;
-}
-
-/**
- * @brief Returns the hash code of a string.
- */
-XBT_INLINE unsigned int xbt_dict_hash(const char *str)
-{
-#ifdef DJB2_HASH_FUNCTION
-  /* fast implementation of djb2 algorithm */
-  int c;
-  register unsigned int hash = 5381;
-
-  while ((c = *str++)) {
-    hash = ((hash << 5) + hash) + c;    /* hash * 33 + c */
-  }
-
-# elif defined(FNV_HASH_FUNCTION)
-  register unsigned int hash = 0x811c9dc5;
-
-  while (*str) {
-    /* multiply by the 32 bit FNV magic prime mod 2^32 */
-    hash +=
-        (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) +
-        (hash << 24);
-
-    /* xor the bottom with the current byte */
-    hash ^= (unsigned int) *str++;
-  }
-
-# else
-  register unsigned int hash = 0;
-
-  while (*str) {
-    hash += (*str) * (*str);
-    str++;
-  }
-#endif
-  return hash;
-}
-
 #ifdef SIMGRID_TEST
 #include "xbt/str.h"
 
 #ifdef SIMGRID_TEST
 #include "xbt/str.h"