gfsmAutomaton.h
Go to the documentation of this file.
1 
2 /*=============================================================================*\
3  * File: gfsmAutomaton.h
4  * Author: Bryan Jurish <moocow.bovine@gmail.com>
5  * Description: finite state machine library: automata
6  *
7  * Copyright (c) 2004-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_AUTOMATON_H
29 #define _GFSM_AUTOMATON_H
30 
31 #include <gfsmAlphabet.h>
32 #include <gfsmState.h>
33 #include <gfsmWeightMap.h>
34 #include <gfsmBitVector.h>
35 
36 /*======================================================================
37  * Types
38  */
39 
45 typedef struct {
46  guint32 is_transducer : 1;
47  guint32 is_weighted : 1;
48  guint32 is_deterministic : 1;
49  guint32 sort_mode : 24;
50  guint32 unused : 5;
52 
57 typedef struct {
58  //-- basic data
61  GArray *states;
65 
66 /*======================================================================
67  * Constants
68  */
71 
74 
77 
78 /*======================================================================*/
80 
81 
85 
89 
96 
107 
110 
117 
121 
124 
129 
130 
131 /*======================================================================*/
133 
134 
138 
150 
161 
163 
164 /*======================================================================*/
166 
167 
174 
178 #define gfsm_automaton_reserve(fsm,n_states) gfsm_automaton_reserve_states((fsm),(n_states))
179 
180 
188 void gfsm_automaton_reserve_arcs(gfsmAutomaton *fsm, guint n_arcs);
189 
198 
202 
209 
213 
221 void gfsm_automaton_set_root(gfsmAutomaton *fsm, gfsmStateId new_root_id);
222 
245 void gfsm_automaton_finals_foreach(gfsmAutomaton *fsm, GTraverseFunc func, gpointer data);
246 
256 
258 
259 /*======================================================================*/
264 
266 #define gfsm_automaton_is_transducer(fsm) ((fsm)->flags.is_transducer)
267 
269 #define gfsm_automaton_is_weighted(fsm) ((fsm)->flags.is_weighted)
270 
272 #define gfsm_automaton_sortmode(fsm) \
273  ((gfsmArcSortMode)(gfsm_acmask_nth((fsm)->flags.sort_mode,0)))
274 
275 // ((gfsmArcSortMode)((fsm)->flags.sort_mode))
276 
285  guint *n_lo_epsilon,
286  guint *n_hi_epsilon,
287  guint *n_both_epsilon);
288 
291  gfsmStateId qid,
292  gfsmBitVector *visited,
293  gfsmBitVector *completed);
294 
297 
299 #define gfsm_automaton_is_acyclic(fsm) (!gfsm_automaton_is_cyclic(fsm))
300 
315  gfsmLabelSide which,
316  gfsmAlphabet *alph);
317 
318 
327 
340 void gfsm_automaton_renumber_states_full(gfsmAutomaton *fsm, GArray *old2new, gfsmStateId n_new_states);
341 
344 
346 
347 /*======================================================================*/
349 
350 
362 
375 
383 
387 #define gfsm_automaton_find_state(fsm,qid) gfsm_automaton_open_state((fsm),(qid))
388 
392 #define gfsm_automaton_find_state_const(fsm,qid) ((const gfsmState*)(gfsm_automaton_open_state((fsm),(qid))))
393 
397 #define gfsm_automaton_get_state(fsm,qid) gfsm_automaton_open_state_force((fsm),(qid))
398 
400 
401 /*======================================================================*/
403 
404 
405 /*--------------------------------------------------------------
406  * has_state()
407  */
410 
421 
427 
433 
443 
453 
462 
464 #define gfsm_automaton_is_final_state(fsm,qid) gfsm_automaton_state_is_final((fsm),(qid))
465 
469 
480  gfsmStateId qid,
481  gboolean is_final,
482  gfsmWeight final_weight);
483 
488 void gfsm_automaton_set_final_state(gfsmAutomaton *fsm, gfsmStateId qid, gboolean is_final);
489 
493 
495 
496 /*======================================================================*/
498 
499 
512  gfsmStateId qid1,
513  gfsmStateId qid2,
514  gfsmLabelId lo,
515  gfsmLabelId hi,
516  gfsmWeight w);
517 
526  gfsmState *sp,
527  gfsmArcList *node);
528 
532 
536 
547 
559 void gfsm_automaton_arcsort_full(gfsmAutomaton *fsm, GCompareDataFunc cmpfunc, gpointer data);
560 
562 #define gfsm_automaton_arcsort_with_data(fsm,cmpfunc,data) gfsm_automaton_arcsort_full((fsm),(cmpfunc),(data))
563 
570 
572 
573 //-- inline definitions
574 #ifdef GFSM_INLINE_ENABLED
575 # include <gfsmAutomaton.hi>
576 #endif
577 
578 #endif /* _GFSM_AUTOMATON_H */