/* By "Alexis S. L. Carvalho" */ /* To compile: gcc -O2 -Wall -g -o blowout-glib blowout-glib.c `pkg-config --cflags --libs glib-2.0` */ #include #include #include #include #define MAXLINE (1024) int main (int argc, char *argv[]) { char line[MAXLINE]; GHashTable *hashtest; GTimer *timer; int i = 0; hashtest = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); timer = g_timer_new (); while (fgets (line, MAXLINE, stdin)) { /* stripping '\n' */ line[strlen (line) - 1] = '\0'; g_hash_table_insert (hashtest, g_strdup (line), GINT_TO_POINTER (1)); /* uncomment the next line to print the hash value of every key */ /* printf ("%s %d\n", line, g_str_hash (line)); */ i++; if ((i % 100) == 0) printf ("%d %.2f\n", i, g_timer_elapsed (timer, NULL)); } g_timer_destroy (timer); g_hash_table_destroy (hashtest); exit (0); }