2010年1月17日

GLib GHashTable

GLib Hash Tables
// test_GHashTable.c
#include <stdio.h>
#include <stdlib.h>
#include <glib.h>

int main(void) {
GHashTable* hash = g_hash_table_new(g_str_hash, g_str_equal);

g_hash_table_insert(hash, "Yes", "No");
g_hash_table_insert(hash, "Left", "Right");
g_hash_table_insert(hash, "Up", "Down");

printf("Size: %d\n", g_hash_table_size(hash));
printf("Left Opposite is %s\n", (char*) g_hash_table_lookup(hash, "Left"));

g_hash_table_destroy(hash);

return EXIT_SUCCESS;
}
/*
$ gcc `pkg-config --cflags --libs glib-2.0` -o test_GHashTable test_GHashTable.c
$ ./test_GHashTable
Size: 3
Left Opposite is Right
*/

沒有留言:

網誌存檔