mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-27 14:36:16 +01:00
Whitespace cleanup
This commit is contained in:
parent
70a1981532
commit
4832289bc0
@ -169,56 +169,60 @@ static guint CrcTable[128];
|
|||||||
*/
|
*/
|
||||||
static void crcinit(void)
|
static void crcinit(void)
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
guint sum;
|
guint sum;
|
||||||
|
|
||||||
for (i = 0; i < 128; ++i) {
|
for (i = 0; i < 128; ++i)
|
||||||
sum = 0L;
|
{
|
||||||
for (j = 7 - 1; j >= 0; --j)
|
sum = 0L;
|
||||||
if (i & (1 << j))
|
for (j = 7 - 1; j >= 0; --j)
|
||||||
sum ^= POLY >> j;
|
if (i & (1 << j))
|
||||||
CrcTable[i] = sum;
|
sum ^= POLY >> j;
|
||||||
}
|
CrcTable[i] = sum;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
- hash - Honeyman's nice hashing function
|
- hash - Honeyman's nice hashing function
|
||||||
*/
|
*/
|
||||||
static guint honeyman_hash(gconstpointer key)
|
static guint
|
||||||
|
honeyman_hash (gconstpointer key)
|
||||||
{
|
{
|
||||||
const gchar *name = (const gchar *) key;
|
const gchar *name = (const gchar *) key;
|
||||||
gint size;
|
gint size;
|
||||||
guint sum = 0;
|
guint sum = 0;
|
||||||
|
|
||||||
g_assert (name != NULL);
|
g_assert (name != NULL);
|
||||||
g_assert (*name != 0);
|
g_assert (*name != 0);
|
||||||
|
|
||||||
size = strlen(name);
|
size = strlen (name);
|
||||||
|
|
||||||
while (size--) {
|
while (size--)
|
||||||
sum = (sum >> 7) ^ CrcTable[(sum ^ (*name++)) & 0x7f];
|
sum = (sum >> 7) ^ CrcTable[(sum ^ (*name++)) & 0x7f];
|
||||||
}
|
|
||||||
|
|
||||||
return(sum);
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static gboolean second_hash_cmp (gconstpointer a, gconstpointer b)
|
static gboolean
|
||||||
|
second_hash_cmp (gconstpointer a, gconstpointer b)
|
||||||
{
|
{
|
||||||
return (strcmp (a, b) == 0);
|
return strcmp (a, b) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static guint one_hash(gconstpointer key)
|
static guint
|
||||||
|
one_hash (gconstpointer key)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void not_even_foreach (gpointer key,
|
static void
|
||||||
gpointer value,
|
not_even_foreach (gpointer key,
|
||||||
gpointer user_data)
|
gpointer value,
|
||||||
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
const char *_key = (const char *) key;
|
const char *_key = (const char *) key;
|
||||||
const char *_value = (const char *) value;
|
const char *_value = (const char *) value;
|
||||||
@ -240,9 +244,10 @@ static void not_even_foreach (gpointer key,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static gboolean remove_even_foreach (gpointer key,
|
static gboolean
|
||||||
gpointer value,
|
remove_even_foreach (gpointer key,
|
||||||
gpointer user_data)
|
gpointer value,
|
||||||
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
const char *_key = (const char *) key;
|
const char *_key = (const char *) key;
|
||||||
const char *_value = (const char *) value;
|
const char *_value = (const char *) value;
|
||||||
@ -265,174 +270,176 @@ static gboolean remove_even_foreach (gpointer key,
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void second_hash_test (gconstpointer d)
|
static void
|
||||||
|
second_hash_test (gconstpointer d)
|
||||||
{
|
{
|
||||||
gboolean simple_hash = GPOINTER_TO_INT (d);
|
gboolean simple_hash = GPOINTER_TO_INT (d);
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
char key[20] = "", val[20]="", *v, *orig_key, *orig_val;
|
char key[20] = "", val[20]="", *v, *orig_key, *orig_val;
|
||||||
GHashTable *h;
|
GHashTable *h;
|
||||||
gboolean found;
|
gboolean found;
|
||||||
|
|
||||||
crcinit ();
|
crcinit ();
|
||||||
|
|
||||||
h = g_hash_table_new_full (simple_hash ? one_hash : honeyman_hash,
|
h = g_hash_table_new_full (simple_hash ? one_hash : honeyman_hash,
|
||||||
second_hash_cmp,
|
second_hash_cmp,
|
||||||
g_free, g_free);
|
g_free, g_free);
|
||||||
g_assert (h != NULL);
|
g_assert (h != NULL);
|
||||||
for (i=0; i<20; i++)
|
for (i = 0; i < 20; i++)
|
||||||
{
|
{
|
||||||
sprintf (key, "%d", i);
|
sprintf (key, "%d", i);
|
||||||
g_assert (atoi (key) == i);
|
g_assert (atoi (key) == i);
|
||||||
|
|
||||||
sprintf (val, "%d value", i);
|
sprintf (val, "%d value", i);
|
||||||
g_assert (atoi (val) == i);
|
g_assert (atoi (val) == i);
|
||||||
|
|
||||||
g_hash_table_insert (h, g_strdup (key), g_strdup (val));
|
g_hash_table_insert (h, g_strdup (key), g_strdup (val));
|
||||||
}
|
}
|
||||||
|
|
||||||
g_assert (g_hash_table_size (h) == 20);
|
g_assert (g_hash_table_size (h) == 20);
|
||||||
|
|
||||||
for (i=0; i<20; i++)
|
for (i = 0; i < 20; i++)
|
||||||
{
|
{
|
||||||
sprintf (key, "%d", i);
|
sprintf (key, "%d", i);
|
||||||
g_assert (atoi(key) == i);
|
g_assert (atoi(key) == i);
|
||||||
|
|
||||||
v = (char *) g_hash_table_lookup (h, key);
|
v = (char *) g_hash_table_lookup (h, key);
|
||||||
|
|
||||||
g_assert (v != NULL);
|
g_assert (v != NULL);
|
||||||
g_assert (*v != 0);
|
g_assert (*v != 0);
|
||||||
g_assert (atoi (v) == i);
|
g_assert (atoi (v) == i);
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf (key, "%d", 3);
|
sprintf (key, "%d", 3);
|
||||||
g_hash_table_remove (h, key);
|
g_hash_table_remove (h, key);
|
||||||
g_assert (g_hash_table_size (h) == 19);
|
g_assert (g_hash_table_size (h) == 19);
|
||||||
g_hash_table_foreach_remove (h, remove_even_foreach, NULL);
|
g_hash_table_foreach_remove (h, remove_even_foreach, NULL);
|
||||||
g_assert (g_hash_table_size (h) == 9);
|
g_assert (g_hash_table_size (h) == 9);
|
||||||
g_hash_table_foreach (h, not_even_foreach, NULL);
|
g_hash_table_foreach (h, not_even_foreach, NULL);
|
||||||
|
|
||||||
for (i=0; i<20; i++)
|
for (i = 0; i < 20; i++)
|
||||||
{
|
{
|
||||||
sprintf (key, "%d", i);
|
sprintf (key, "%d", i);
|
||||||
g_assert (atoi(key) == i);
|
g_assert (atoi(key) == i);
|
||||||
|
|
||||||
sprintf (val, "%d value", i);
|
sprintf (val, "%d value", i);
|
||||||
g_assert (atoi (val) == i);
|
g_assert (atoi (val) == i);
|
||||||
|
|
||||||
orig_key = orig_val = NULL;
|
orig_key = orig_val = NULL;
|
||||||
found = g_hash_table_lookup_extended (h, key,
|
found = g_hash_table_lookup_extended (h, key,
|
||||||
(gpointer)&orig_key,
|
(gpointer)&orig_key,
|
||||||
(gpointer)&orig_val);
|
(gpointer)&orig_val);
|
||||||
if ((i % 2) == 0 || i == 3)
|
if ((i % 2) == 0 || i == 3)
|
||||||
{
|
{
|
||||||
g_assert (!found);
|
g_assert (!found);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_assert (found);
|
g_assert (found);
|
||||||
|
|
||||||
g_assert (orig_key != NULL);
|
g_assert (orig_key != NULL);
|
||||||
g_assert (strcmp (key, orig_key) == 0);
|
g_assert (strcmp (key, orig_key) == 0);
|
||||||
|
|
||||||
g_assert (orig_val != NULL);
|
g_assert (orig_val != NULL);
|
||||||
g_assert (strcmp (val, orig_val) == 0);
|
g_assert (strcmp (val, orig_val) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_hash_table_destroy (h);
|
g_hash_table_destroy (h);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean find_first (gpointer key,
|
static gboolean
|
||||||
gpointer value,
|
find_first (gpointer key,
|
||||||
gpointer user_data)
|
gpointer value,
|
||||||
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
gint *v = value;
|
gint *v = value;
|
||||||
gint *test = user_data;
|
gint *test = user_data;
|
||||||
return (*v == *test);
|
return (*v == *test);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void direct_hash_test (void)
|
static void
|
||||||
|
direct_hash_test (void)
|
||||||
{
|
{
|
||||||
gint i, rc;
|
gint i, rc;
|
||||||
GHashTable *h;
|
GHashTable *h;
|
||||||
|
|
||||||
h = g_hash_table_new (NULL, NULL);
|
h = g_hash_table_new (NULL, NULL);
|
||||||
g_assert (h != NULL);
|
g_assert (h != NULL);
|
||||||
for (i=1; i<=20; i++)
|
for (i = 1; i <= 20; i++)
|
||||||
{
|
g_hash_table_insert (h, GINT_TO_POINTER (i),
|
||||||
g_hash_table_insert (h, GINT_TO_POINTER (i),
|
GINT_TO_POINTER (i + 42));
|
||||||
GINT_TO_POINTER (i + 42));
|
|
||||||
}
|
|
||||||
|
|
||||||
g_assert (g_hash_table_size (h) == 20);
|
g_assert (g_hash_table_size (h) == 20);
|
||||||
|
|
||||||
for (i=1; i<=20; i++)
|
for (i = 1; i <= 20; i++)
|
||||||
{
|
{
|
||||||
rc = GPOINTER_TO_INT (
|
rc = GPOINTER_TO_INT (g_hash_table_lookup (h, GINT_TO_POINTER (i)));
|
||||||
g_hash_table_lookup (h, GINT_TO_POINTER (i)));
|
|
||||||
|
|
||||||
g_assert (rc != 0);
|
g_assert (rc != 0);
|
||||||
g_assert ((rc - 42) == i);
|
g_assert ((rc - 42) == i);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_hash_table_destroy (h);
|
g_hash_table_destroy (h);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void int64_hash_test (void)
|
static void
|
||||||
|
int64_hash_test (void)
|
||||||
{
|
{
|
||||||
gint i, rc;
|
gint i, rc;
|
||||||
GHashTable *h;
|
GHashTable *h;
|
||||||
gint64 values[20];
|
gint64 values[20];
|
||||||
gint64 key;
|
gint64 key;
|
||||||
|
|
||||||
h = g_hash_table_new (g_int64_hash, g_int64_equal);
|
h = g_hash_table_new (g_int64_hash, g_int64_equal);
|
||||||
g_assert (h != NULL);
|
g_assert (h != NULL);
|
||||||
for (i=0; i<20; i++)
|
for (i = 0; i < 20; i++)
|
||||||
{
|
{
|
||||||
values[i] = i + 42;
|
values[i] = i + 42;
|
||||||
g_hash_table_insert (h, &values[i], GINT_TO_POINTER (i + 42));
|
g_hash_table_insert (h, &values[i], GINT_TO_POINTER (i + 42));
|
||||||
}
|
}
|
||||||
|
|
||||||
g_assert (g_hash_table_size (h) == 20);
|
g_assert (g_hash_table_size (h) == 20);
|
||||||
|
|
||||||
for (i=0; i<20; i++)
|
for (i = 0; i < 20; i++)
|
||||||
{
|
{
|
||||||
key = i + 42;
|
key = i + 42;
|
||||||
rc = GPOINTER_TO_INT (g_hash_table_lookup (h, &key));
|
rc = GPOINTER_TO_INT (g_hash_table_lookup (h, &key));
|
||||||
|
|
||||||
g_assert_cmpint (rc, ==, i + 42);
|
g_assert_cmpint (rc, ==, i + 42);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_hash_table_destroy (h);
|
g_hash_table_destroy (h);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void double_hash_test (void)
|
static void
|
||||||
|
double_hash_test (void)
|
||||||
{
|
{
|
||||||
gint i, rc;
|
gint i, rc;
|
||||||
GHashTable *h;
|
GHashTable *h;
|
||||||
gdouble values[20];
|
gdouble values[20];
|
||||||
gdouble key;
|
gdouble key;
|
||||||
|
|
||||||
h = g_hash_table_new (g_double_hash, g_double_equal);
|
h = g_hash_table_new (g_double_hash, g_double_equal);
|
||||||
g_assert (h != NULL);
|
g_assert (h != NULL);
|
||||||
for (i=0; i<20; i++)
|
for (i = 0; i < 20; i++)
|
||||||
{
|
{
|
||||||
values[i] = i + 42.5;
|
values[i] = i + 42.5;
|
||||||
g_hash_table_insert (h, &values[i], GINT_TO_POINTER (i + 42));
|
g_hash_table_insert (h, &values[i], GINT_TO_POINTER (i + 42));
|
||||||
}
|
}
|
||||||
|
|
||||||
g_assert (g_hash_table_size (h) == 20);
|
g_assert (g_hash_table_size (h) == 20);
|
||||||
|
|
||||||
for (i=0; i<20; i++)
|
for (i = 0; i < 20; i++)
|
||||||
{
|
{
|
||||||
key = i + 42.5;
|
key = i + 42.5;
|
||||||
rc = GPOINTER_TO_INT (g_hash_table_lookup (h, &key));
|
rc = GPOINTER_TO_INT (g_hash_table_lookup (h, &key));
|
||||||
|
|
||||||
g_assert_cmpint (rc, ==, i + 42);
|
g_assert_cmpint (rc, ==, i + 42);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_hash_table_destroy (h);
|
g_hash_table_destroy (h);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -443,39 +450,40 @@ string_free (gpointer data)
|
|||||||
g_string_free (s, TRUE);
|
g_string_free (s, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void string_hash_test (void)
|
static void
|
||||||
|
string_hash_test (void)
|
||||||
{
|
{
|
||||||
gint i, rc;
|
gint i, rc;
|
||||||
GHashTable *h;
|
GHashTable *h;
|
||||||
GString *s;
|
GString *s;
|
||||||
|
|
||||||
h = g_hash_table_new_full ((GHashFunc)g_string_hash, (GEqualFunc)g_string_equal, string_free, NULL);
|
h = g_hash_table_new_full ((GHashFunc)g_string_hash, (GEqualFunc)g_string_equal, string_free, NULL);
|
||||||
g_assert (h != NULL);
|
g_assert (h != NULL);
|
||||||
for (i=0; i<20; i++)
|
for (i = 0; i < 20; i++)
|
||||||
{
|
{
|
||||||
s = g_string_new ("");
|
s = g_string_new ("");
|
||||||
g_string_append_printf (s, "%d", i + 42);
|
g_string_append_printf (s, "%d", i + 42);
|
||||||
g_string_append_c (s, '.');
|
g_string_append_c (s, '.');
|
||||||
g_string_prepend_unichar (s, 0x2301);
|
g_string_prepend_unichar (s, 0x2301);
|
||||||
g_hash_table_insert (h, s, GINT_TO_POINTER (i + 42));
|
g_hash_table_insert (h, s, GINT_TO_POINTER (i + 42));
|
||||||
}
|
}
|
||||||
|
|
||||||
g_assert (g_hash_table_size (h) == 20);
|
g_assert (g_hash_table_size (h) == 20);
|
||||||
|
|
||||||
s = g_string_new ("");
|
s = g_string_new ("");
|
||||||
for (i=0; i<20; i++)
|
for (i = 0; i < 20; i++)
|
||||||
{
|
{
|
||||||
g_string_assign (s, "");
|
g_string_assign (s, "");
|
||||||
g_string_append_printf (s, "%d", i + 42);
|
g_string_append_printf (s, "%d", i + 42);
|
||||||
g_string_append_c (s, '.');
|
g_string_append_c (s, '.');
|
||||||
g_string_prepend_unichar (s, 0x2301);
|
g_string_prepend_unichar (s, 0x2301);
|
||||||
rc = GPOINTER_TO_INT (g_hash_table_lookup (h, s));
|
rc = GPOINTER_TO_INT (g_hash_table_lookup (h, s));
|
||||||
|
|
||||||
g_assert_cmpint (rc, ==, i + 42);
|
g_assert_cmpint (rc, ==, i + 42);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_string_free (s, TRUE);
|
g_string_free (s, TRUE);
|
||||||
g_hash_table_destroy (h);
|
g_hash_table_destroy (h);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user