libUnihan  0.5.3
collection.h
Go to the documentation of this file.
1 
8 /*
9  * Copyright © 2008 Red Hat, Inc. All rights reserved.
10  * Copyright © 2008 Ding-Yi Chen <dchen at redhat dot com>
11  *
12  * This file is part of the libUnihan Project.
13  *
14  * This library is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU Lesser General Public
16  * License as published by the Free Software Foundation; either
17  * version 2 of the License, or (at your option) any later version.
18  *
19  * This library is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with this program; if not, write to the
26  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
27  * Boston, MA 02111-1307 USA
28  */
29 
30 #ifndef COLLECTION_H_
31 #define COLLECTION_H_
32 #include <glib.h>
33 
43 typedef enum{
48 } ElementType;
49 
67 typedef struct {
68  GHashTable *hTable;
70 }HashSet;
71 
72 
82 typedef gboolean (* ForeachCallbackFunc) (gpointer data, gpointer userdata);
83 
111 
125 HashSet *hashSet_new(ElementType type,GHashFunc hash_func, GEqualFunc element_equal_func) ;
126 
141 HashSet *hashSet_new_full(ElementType type,GHashFunc hash_func, GEqualFunc element_equal_func,
142  GDestroyNotify element_destroy_func) ;
143 
144 
154 void hashSet_copy(HashSet *dest, HashSet *src);
155 
164 guint hashSet_get_size(HashSet *hashSet);
165 
175 gboolean hashSet_has_element(HashSet *hashSet,gconstpointer element);
176 
177 
189 gboolean hashSet_add_element(HashSet *hashSet,gpointer element);
190 
203 void hashSet_remove_all(HashSet *hashSet);
204 
205 
220 gboolean hashSet_remove_element(HashSet *hashSet,gconstpointer element);
221 
222 
236 void hashSet_steal_all(HashSet *hashSet);
237 
252 gboolean hashSet_steal_element(HashSet *hashSet,gconstpointer element);
253 
273 void hashSet_union(HashSet *result, HashSet *hashSet1, HashSet *hashSet2);
274 
288 void hashSet_intersect(HashSet *result, HashSet *hashSet1, HashSet *hashSet2);
289 
311 char* hashSet_to_string(HashSet *hashSet);
312 
318 void hashSet_destroy(HashSet *hashSet);
319 
327 int integer_compareFunc(gconstpointer a,gconstpointer b);
328 
335 #define G_PTR_ARRAY_REMOVE_ALL(array) if (array->len>0) g_ptr_array_remove_range(array,0,array->len)
336 
346 #define G_ARRAY_CONCAT(dest,src) g_array_append_vals(dest,src->data,src->len)
347 
354 #define G_ARRAY_REMOVE_ALL(array) if (array->len>0) g_array_remove_range(array,0,array->len)
355 
373 int g_array_find(GArray *array, gpointer element, gint elementSize,GCompareFunc func);
374 
386 GArray *g_array_copy(GArray *dest,GArray *src);
387 
388 #endif /*COLLECTION_H_*/
389 
ElementType setType
Element type of key.
Definition: collection.h:69
Specify that collection elements are user-defined type.
Definition: collection.h:47
void hashSet_destroy(HashSet *hashSet)
Free the hashSet instance.
GArray * g_array_copy(GArray *dest, GArray *src)
Copy from another GArray.
int g_array_find(GArray *array, gpointer element, gint elementSize, GCompareFunc func)
Find an element in a GArray.
HashSet * hashSet_new_full(ElementType type, GHashFunc hash_func, GEqualFunc element_equal_func, GDestroyNotify element_destroy_func)
New a HashSet instance, while specifying element destroy function.
GHashTable * hTable
The backing GHashTable.
Definition: collection.h:68
void hashSet_union(HashSet *result, HashSet *hashSet1, HashSet *hashSet2)
Union two sets.
Specify that collection elements are pointers.
Definition: collection.h:46
HashSet * hashSet_new_default(ElementType type)
New a HashSet instance with default handling functions.
int integer_compareFunc(gconstpointer a, gconstpointer b)
GCompareFunc that compares two intergers.
void hashSet_steal_all(HashSet *hashSet)
Steal all elements in the set.
HashSet: A set which backed by Hash Table.
Definition: collection.h:67
gboolean hashSet_steal_element(HashSet *hashSet, gconstpointer element)
Steal an element to the HashSet.
gboolean hashSet_add_element(HashSet *hashSet, gpointer element)
Add an element to the HashSet.
HashSet * hashSet_new(ElementType type, GHashFunc hash_func, GEqualFunc element_equal_func)
New a HashSet instance.
Specify that collection elements are integers.
Definition: collection.h:44
guint hashSet_get_size(HashSet *hashSet)
Get the number of elements in the HashSet.
void hashSet_copy(HashSet *dest, HashSet *src)
Copy from another HashSet.
void hashSet_remove_all(HashSet *hashSet)
Remove all elements in the set.
void hashSet_intersect(HashSet *result, HashSet *hashSet1, HashSet *hashSet2)
Intersect two sets.
Specify that collection elements are strings.
Definition: collection.h:45
gboolean(* ForeachCallbackFunc)(gpointer data, gpointer userdata)
Foreach callback function prototype.
Definition: collection.h:82
char * hashSet_to_string(HashSet *hashSet)
New a string representation for the content of the HashSet.
ElementType
Enumeration of element types which the collection stores.
Definition: collection.h:43
gboolean hashSet_remove_element(HashSet *hashSet, gconstpointer element)
Remove an element to the HashSet.
gboolean hashSet_has_element(HashSet *hashSet, gconstpointer element)
Whether a element is in the HashSet.