libUnihan
0.5.3
|
00001 00008 /* 00009 * Copyright © 2008 Red Hat, Inc. All rights reserved. 00010 * Copyright © 2008 Ding-Yi Chen <dchen at redhat dot com> 00011 * 00012 * This file is part of the libUnihan Project. 00013 * 00014 * This library is free software; you can redistribute it and/or 00015 * modify it under the terms of the GNU Lesser General Public 00016 * License as published by the Free Software Foundation; either 00017 * version 2 of the License, or (at your option) any later version. 00018 * 00019 * This library is distributed in the hope that it will be useful, 00020 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 * GNU Lesser General Public License for more details. 00023 * 00024 * You should have received a copy of the GNU Lesser General Public 00025 * License along with this program; if not, write to the 00026 * Free Software Foundation, Inc., 59 Temple Place, Suite 330, 00027 * Boston, MA 02111-1307 USA 00028 */ 00029 00030 #ifndef COLLECTION_H_ 00031 #define COLLECTION_H_ 00032 #include <glib.h> 00033 00043 typedef enum{ 00044 ELEMENTS_TYPE_INTEGER, 00045 ELEMENTS_TYPE_STRING, 00046 ELEMENTS_TYPE_POINTER, 00047 ELEMENTS_TYPE_CUSTOM 00048 } ElementType; 00049 00067 typedef struct { 00068 GHashTable *hTable; 00069 ElementType setType; 00070 }HashSet; 00071 00072 00082 typedef gboolean (* ForeachCallbackFunc) (gpointer data, gpointer userdata); 00083 00110 HashSet *hashSet_new_default(ElementType type); 00111 00125 HashSet *hashSet_new(ElementType type,GHashFunc hash_func, GEqualFunc element_equal_func) ; 00126 00141 HashSet *hashSet_new_full(ElementType type,GHashFunc hash_func, GEqualFunc element_equal_func, 00142 GDestroyNotify element_destroy_func) ; 00143 00144 00154 void hashSet_copy(HashSet *dest, HashSet *src); 00155 00164 guint hashSet_get_size(HashSet *hashSet); 00165 00175 gboolean hashSet_has_element(HashSet *hashSet,gconstpointer element); 00176 00177 00189 gboolean hashSet_add_element(HashSet *hashSet,gpointer element); 00190 00203 void hashSet_remove_all(HashSet *hashSet); 00204 00205 00220 gboolean hashSet_remove_element(HashSet *hashSet,gconstpointer element); 00221 00222 00236 void hashSet_steal_all(HashSet *hashSet); 00237 00252 gboolean hashSet_steal_element(HashSet *hashSet,gconstpointer element); 00253 00273 void hashSet_union(HashSet *result, HashSet *hashSet1, HashSet *hashSet2); 00274 00288 void hashSet_intersect(HashSet *result, HashSet *hashSet1, HashSet *hashSet2); 00289 00311 char* hashSet_to_string(HashSet *hashSet); 00312 00318 void hashSet_destroy(HashSet *hashSet); 00319 00327 int integer_compareFunc(gconstpointer a,gconstpointer b); 00328 00335 #define G_PTR_ARRAY_REMOVE_ALL(array) if (array->len>0) g_ptr_array_remove_range(array,0,array->len) 00336 00346 #define G_ARRAY_CONCAT(dest,src) g_array_append_vals(dest,src->data,src->len) 00347 00354 #define G_ARRAY_REMOVE_ALL(array) if (array->len>0) g_array_remove_range(array,0,array->len) 00355 00373 int g_array_find(GArray *array, gpointer element, gint elementSize,GCompareFunc func); 00374 00386 GArray *g_array_copy(GArray *dest,GArray *src); 00387 00388 #endif /*COLLECTION_H_*/ 00389