gfsmxlCascade.h
Go to the documentation of this file.
1 
2 /*=============================================================================*\
3  * File: gfsmxlCascade.h
4  * Author: Bryan Jurish <moocow.bovine@gmail.com>
5  * Description: finite state machine library: lookup cascade
6  *
7  * Copyright (c) 2007-2012 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 2.1 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 _GFSMXL_CASCADE_H
29 #define _GFSMXL_CASCADE_H
30 
31 #include <gfsm.h>
32 #include <gfsmxlLabelIndex.h>
33 #include <gfsmxlSuffixIndex.h>
34 
35 /*======================================================================
36  * Types
37  */
38 
41 
42 //#define CASCADE_USE_RAW_BSEARCH 1
43 #define CASCADE_USE_BLOCK_INDEX 1
44 /*-- uhura, r616M, Wed, 03 Feb 2010 14:29:57 +0100: CASCADE_EXPAND_BLOCK_BSEARCH was defined --*/
45 //#define CASCADE_EXPAND_BLOCK_BSEARCH 1
46 //#define CASCADE_USE_BLOCK_HASH 1
47 //#define CASCADE_USE_SUFFIX_INDEX 1
48 
49 //-- sort temporary arc-lists on creation?
50 // : this is pointless unless we're storing arc-lists with configs!
51 //#define CASCADE_SORT_ARCITER 1
52 
53 #if !defined(CASCADE_USE_BLOCK_INDEX)
54 # define CASCADE_USE_BLOCK_INDEX 1
55 #endif
56 
57 #if defined(CASCADE_USE_BLOCK_INDEX) || defined(CASCADE_USE_BLOCK_HASH)
58 # define CASCADE_USE_BLOCKS 1
59 #else
60 # undef CASCADE_USE_BLOCKS
61 #endif
62 
64 typedef struct {
65  guint depth;
67  GPtrArray *xfsms;
68 #if defined(CASCADE_USE_BLOCK_INDEX)
69  GPtrArray *xblks;
70 #elif defined(CASCADE_USE_BLOCK_HASH)
71  GPtrArray *xblks;
72 #endif
73 #if defined(CASCADE_USE_SUFFIX_INDEX)
74  GPtrArray *xslxs;
75 #endif
76  GArray *roots;
78 
79 /*======================================================================
80  * Constructors, etc.
81  */
83 
84 
88 
92 
95 void gfsmxl_cascade_free(gfsmxlCascade *csc, gboolean free_automata);
96 
98 void gfsmxl_cascade_clear(gfsmxlCascade *csc, gboolean free_automata);
99 
101 void gfsmxl_cascade_clear_nth(gfsmxlCascade *csc, guint n, gboolean free_automaton);
102 
106 
109 void gfsmxl_cascade_set_nth_indexed(gfsmxlCascade *csc, guint n, gfsmIndexedAutomaton *xfsm, gboolean free_old_automaton);
110 
114 
118 
120 
121 /*======================================================================
122  * High-level Access
123  */
125 
126 
130 #define gfsmxl_cascade_index(csc_,index_) \
131  ((gfsmIndexedAutomaton*)g_ptr_array_index((csc_)->xfsms,(index_)))
132 
136 
140 
143 
145 
146 /*======================================================================
147  * State Utilities
148  */
150 
151 
155 
159 
163 
167 
171 
174 void gfsmxl_cascade_stateid_free(gfsmxlCascadeStateId qids, guint depth);
175 
177 
178 /*======================================================================
179  * Arc Utilities
180  */
182 
183 
188 
192 
196 
200 
203 void gfsmxl_arcpp_free(gfsmxlArcPP arcpp, guint depth);
204 
208 
211 gfsmLabelId gfsmxl_arcpp_upper(gfsmxlArcPP arcpp, guint depth);
212 
215 gfsmWeight gfsmxl_arcpp_weight(gfsmxlArcPP arcpp, guint depth, gfsmSemiring *sr);
216 
220 
222 
223 /*======================================================================
224  * Arc Utilities
225  */
227 
228 
230 typedef struct {
236 
240 
244 
248 
251 void gfsmxl_cascade_arc_free(gfsmxlCascadeArc *arc, guint depth);
252 
254 
255 
256 /*======================================================================
257  * Arc Iteration & Low-level Access
258  */
260 
261 
264 
269 
271 typedef struct {
274  GSList *arclist;
275  GSList *cur;
278 
284 
287 
291 
298 
302 
306 
307 #ifdef CASCADE_SORT_ARCITER
308 
311 #else
312 
315 #endif
316 
317 
319 
320 /*======================================================================
321  * I/O
322  */
324 
325 
327 typedef struct {
328  gchar magic[16];
335  guint32 srtype;
336  guint32 _unused1;
337  guint32 depth;
338  guint32 _unused3;
340 
342 extern const gchar gfsm_cascade_header_magic[16];
343 
346 
349 
350 /*--------------------------------------------------------------*/
351 
355 
358 
360 gboolean gfsmxl_cascade_load_bin_file(gfsmxlCascade *csc, FILE *f, gfsmError **errp);
361 
363 gboolean gfsmxl_cascade_load_bin_filename(gfsmxlCascade *csc, const gchar *filename, gfsmError **errp);
364 
366 gboolean gfsmxl_cascade_load_bin_gstring(gfsmxlCascade *csc, GString *gs, gfsmError **errp);
367 
368 /*--------------------------------------------------------------*/
369 
372 
374 gboolean gfsmxl_cascade_save_bin_file(gfsmxlCascade *csc, FILE *f, gfsmError **errp);
375 
377 gboolean gfsmxl_cascade_save_bin_filename_nc(gfsmxlCascade *csc, const gchar *filename, gfsmError **errp);
378 
383 gboolean gfsmxl_cascade_save_bin_filename(gfsmxlCascade *csc, const gchar *filename, int zlevel, gfsmError **errp);
384 
386 gboolean gfsmxl_cascade_save_bin_gstring(gfsmxlCascade *csc, GString *gs, gfsmError **errp);
387 
389 
390 /*======================================================================
391  * END
392  */
393 
394 //-- inline definitions
395 #ifdef GFSM_INLINE_ENABLED
396 # include <gfsmxlCascade.hi>
397 #endif
398 
399 #endif /* _GFSMXL_CASCADE_H */