Move all hash functions to ghash.c
[platform/upstream/glib.git] / glib / gstring.c
index 8d6ef2c..9fac86c 100644 (file)
 #include "gprintf.h"
 
 
-/* Hash Functions.
- */
-
 /**
- * g_str_equal:
- * @v1: a key
- * @v2: a key to compare with @v1
- *
- * Compares two strings for byte-by-byte equality and returns %TRUE
- * if they are equal. It can be passed to g_hash_table_new() as the
- * @key_equal_func parameter, when using strings as keys in a #GHashTable.
- *
- * Note that this function is primarily meant as a hash table comparison
- * function. For a general-purpose, %NULL-safe string comparison function,
- * see g_strcmp0().
+ * SECTION:strings
+ * @title: Strings
+ * @short_description: text buffers which grow automatically
+ *     as text is added
  *
- * Returns: %TRUE if the two keys match
+ * A #GString is an object that handles the memory management
+ * of a C string for you. You can think of it as similar to a
+ * Java StringBuffer. In addition to the string itself, GString
+ * stores the length of the string, so can be used for binary
+ * data with embedded nul bytes. To access the C string managed
+ * by the GString @string, simply use @string->str.
  */
-gboolean
-g_str_equal (gconstpointer v1,
-             gconstpointer v2)
-{
-  const gchar *string1 = v1;
-  const gchar *string2 = v2;
-
-  return strcmp (string1, string2) == 0;
-}
 
 /**
- * g_str_hash:
- * @v: a string key
- *
- * Converts a string to a hash value.
- *
- * This function implements the widely used "djb" hash apparently posted
- * by Daniel Bernstein to comp.lang.c some time ago.  The 32 bit
- * unsigned hash value starts at 5381 and for each byte 'c' in the
- * string, is updated: <literal>hash = hash * 33 + c</literal>.  This
- * function uses the signed value of each byte.
- *
- * It can be passed to g_hash_table_new() as the @hash_func parameter,
- * when using strings as keys in a #GHashTable.
+ * GString:
+ * @str: points to the character data. It may move as text is added.
+ *   The @str field is null-terminated and so
+ *   can be used as an ordinary C string.
+ * @len: contains the length of the string, not including the
+ *   terminating nul byte.
+ * @allocated_len: the number of bytes that can be stored in the
+ *   string before it needs to be reallocated. May be larger than @len.
  *
- * Returns: a hash value corresponding to the key
+ * The GString struct contains the public fields of a GString.
  */
-guint
-g_str_hash (gconstpointer v)
-{
-  const signed char *p;
-  guint32 h = 5381;
 
-  for (p = v; *p != '\0'; p++)
-    h = (h << 5) + h + *p;
-
-  return h;
-}
 
 #define MY_MAXSIZE ((gsize)-1)
 
@@ -121,34 +92,6 @@ nearest_power (gsize base, gsize num)
     }
 }
 
-/**
- * SECTION:strings
- * @title: Strings
- * @short_description: text buffers which grow automatically
- *     as text is added
- *
- * A #GString is an object that handles the memory management
- * of a C string for you. You can think of it as similar to a
- * Java StringBuffer. In addition to the string itself, GString
- * stores the length of the string, so can be used for binary
- * data with embedded nul bytes. To access the C string managed
- * by the GString @string, simply use @string->str.
- */
-
-/**
- * GString:
- * @str: points to the character data. It may move as text is added.
- *   The @str field is null-terminated and so
- *   can be used as an ordinary C string.
- * @len: contains the length of the string, not including the
- *   terminating nul byte.
- * @allocated_len: the number of bytes that can be stored in the
- *   string before it needs to be reallocated. May be larger than @len.
- *
- * The GString struct contains the public fields of a GString.
- */
-
-
 static void
 g_string_maybe_expand (GString *string,
                        gsize    len)