gfsmWeightMap.h
Go to the documentation of this file.
1 
2 /*=============================================================================*\
3  * File: gfsmWeightMap.h
4  * Author: Bryan Jurish <moocow.bovine@gmail.com>
5  * Description: finite state machine library
6  *
7  * Copyright (c) 2005-2007 Bryan Jurish.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 3 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  *=============================================================================*/
23 
28 #ifndef _GFSM_WEIGHTMAP_H
29 #define _GFSM_WEIGHTMAP_H
30 
31 #include <gfsmSet.h>
32 #include <gfsmSemiring.h>
33 
34 /*======================================================================
35  * Types
36  */
40 typedef GTree gfsmWeightMap;
41 
45 typedef struct {
46  GHashTable *table;
49 
53 typedef union {
55  gpointer p;
57 
59 typedef GArray gfsmStateWeightPairArray;
60 
61 /*======================================================================
62  * gfsmWeight <-> gpointer conversions
63  */
64 
66 
67 
70 gfsmWeight gfsm_ptr2weight(const gpointer p);
71 
74 gpointer gfsm_weight2ptr(const gfsmWeight w);
75 
77 
78 /*======================================================================
79  * gfsmWeightMap: Constructors etc.
80  */
81 
83 
84 
88 gfsmWeightMap *gfsm_weightmap_new_full(GCompareDataFunc key_cmp_func,
89  gpointer key_cmp_data,
90  GDestroyNotify key_free_func);
91 
94 gfsmWeightMap *gfsm_weightmap_new(GCompareFunc key_cmp_func);
95 
99 
103 
108 
109 
110 /*======================================================================
111  * Accessors
112  */
114 
115 
118 gboolean gfsm_weightmap_contains(gfsmWeightMap *weightmap, gconstpointer key);
119 
122 gboolean gfsm_weightmap_lookup(gfsmWeightMap *weightmap, gconstpointer key, gfsmWeight *wp);
123 
125 //#define _gfsm_weightmap_insert(weightmap,key,w) g_tree_insert((weightmap),((gpointer)(key)),gfsm_weight2ptr(w))
126 
129 void gfsm_weightmap_insert(gfsmWeightMap *weightmap, gconstpointer key, gfsmWeight w);
130 
135 gfsmWeight gfsm_weightmap_insert_sum(gfsmWeightMap *weightmap, gconstpointer key, gfsmWeight w, gfsmSemiring *sr);
136 
138 #define gfsm_weightmap_size(weightmap) g_tree_nnodes(weightmap)
139 
141 #define gfsm_weightmap_remove(weightmap,key) g_tree_remove((weightmap),((gpointer)(key)))
142 
144 #define gfsm_weightmap_foreach(weightmap,func,data) g_tree_foreach((weightmap),(func),(data))
145 
153 
155 
156 
157 
158 /*======================================================================
159  * gfsmWeightHash: Constructors etc.
160  */
162 
163 
166  GHashFunc key_hash_func,
167  GEqualFunc key_equal_func,
168  GDestroyNotify key_destroy_func);
169 
171 #define gfsm_weighthash_new(key_hash_f,key_equal_f) \
172  gfsm_weighthash_new_full(NULL,(key_hash_f),(key_equal_f),NULL)
173 
177 
182 
183 
184 /*======================================================================
185  * gfsmWeightHash: Accessors
186  */
188 
189 
192 gboolean gfsm_weighthash_lookup(gfsmWeightHash *wh, gconstpointer key, gfsmWeight *wp);
193 
196 void gfsm_weighthash_insert(gfsmWeightHash *wh, gconstpointer key, gfsmWeight w);
197 
205 gboolean gfsm_weighthash_insert_if_less(gfsmWeightHash *wh, gconstpointer key, gfsmWeight w, gfsmSemiring *sr);
206 
215 gboolean gfsm_weighthash_insert_sum_if_less(gfsmWeightHash *wh, gconstpointer key, gfsmWeight w, gfsmSemiring *sr);
216 
218 #define gfsm_weighthash_foreach(wh,func,data) \
219  g_hash_table_foreach((wh)->table,(func),(data))
220 
222 
223 //-- inline definitions
224 #ifdef GFSM_INLINE_ENABLED
225 # include <gfsmWeightMap.hi>
226 #endif
227 
228 #endif /* _GFSM_WEIGHTMAP_H */