Main Page
Related Pages
Data Structures
Files
File List
Globals
src
libgfsm
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;
51
}
gfsmAutomatonFlags
;
52
57
typedef
struct
{
58
//-- basic data
59
gfsmAutomatonFlags
flags
;
60
gfsmSemiring
*
sr
;
61
GArray *
states
;
62
gfsmWeightMap
*
finals
;
63
gfsmStateId
root_id
;
64
}
gfsmAutomaton
;
65
66
/*======================================================================
67
* Constants
68
*/
70
extern
const
gfsmStateId
gfsmAutomatonDefaultSize
;
71
73
extern
const
gfsmAutomatonFlags
gfsmAutomatonDefaultFlags
;
74
76
extern
const
gfsmSRType
gfsmAutomatonDefaultSRType
;
77
78
/*======================================================================*/
80
81
83
GFSM_INLINE
84
gfsmAutomaton
*
gfsm_automaton_new_full
(
gfsmAutomatonFlags
flags,
gfsmSRType
srtype,
gfsmStateId
n_states);
85
87
GFSM_INLINE
88
gfsmAutomaton
*
gfsm_automaton_new
(
void
);
89
94
GFSM_INLINE
95
gfsmAutomaton
*
gfsm_automaton_clone
(
gfsmAutomaton
*fsm);
96
105
GFSM_INLINE
106
gfsmAutomaton
*
gfsm_automaton_copy_shallow
(
gfsmAutomaton
*dst,
gfsmAutomaton
*src);
107
109
gfsmAutomaton
*
gfsm_automaton_copy
(
gfsmAutomaton
*dst,
gfsmAutomaton
*src);
110
115
GFSM_INLINE
116
gfsmAutomaton
*
gfsm_automaton_shadow
(
gfsmAutomaton
*fsm);
117
119
GFSM_INLINE
120
void
gfsm_automaton_swap
(
gfsmAutomaton
*fsm1,
gfsmAutomaton
*fsm2);
121
123
void
gfsm_automaton_clear
(
gfsmAutomaton
*fsm);
124
126
GFSM_INLINE
127
void
gfsm_automaton_free
(
gfsmAutomaton
*fsm);
129
130
131
/*======================================================================*/
133
134
136
GFSM_INLINE
137
gfsmSemiring
*
gfsm_automaton_get_semiring
(
gfsmAutomaton
*fsm);
138
148
GFSM_INLINE
149
gfsmSemiring
*
gfsm_automaton_set_semiring
(
gfsmAutomaton
*fsm,
gfsmSemiring
*sr);
150
159
GFSM_INLINE
160
void
gfsm_automaton_set_semiring_type
(
gfsmAutomaton
*fsm,
gfsmSRType
srtype);
161
163
164
/*======================================================================*/
166
167
172
GFSM_INLINE
173
void
gfsm_automaton_reserve_states
(
gfsmAutomaton
*fsm,
gfsmStateId
n_states);
174
178
#define gfsm_automaton_reserve(fsm,n_states) gfsm_automaton_reserve_states((fsm),(n_states))
179
180
187
GFSM_INLINE
188
void
gfsm_automaton_reserve_arcs
(
gfsmAutomaton
*fsm, guint n_arcs);
189
196
GFSM_INLINE
197
gfsmStateId
gfsm_automaton_n_states
(
gfsmAutomaton
*fsm);
198
200
GFSM_INLINE
201
gfsmStateId
gfsm_automaton_n_final_states
(
gfsmAutomaton
*fsm);
202
207
GFSM_INLINE
208
guint
gfsm_automaton_n_arcs
(
gfsmAutomaton
*fsm);
209
211
GFSM_INLINE
212
gfsmStateId
gfsm_automaton_get_root
(
gfsmAutomaton
*fsm);
213
220
GFSM_INLINE
221
void
gfsm_automaton_set_root
(
gfsmAutomaton
*fsm,
gfsmStateId
new_root_id);
222
244
GFSM_INLINE
245
void
gfsm_automaton_finals_foreach
(
gfsmAutomaton
*fsm, GTraverseFunc func, gpointer data);
246
254
GFSM_INLINE
255
gfsmStateWeightPairArray
*
gfsm_automaton_finals_to_array
(
gfsmAutomaton
*fsm,
gfsmStateWeightPairArray
*array);
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
284
guint
gfsm_automaton_n_arcs_full
(
gfsmAutomaton
*fsm,
285
guint *n_lo_epsilon,
286
guint *n_hi_epsilon,
287
guint *n_both_epsilon);
288
290
gboolean
gfsm_automaton_is_cyclic_state
(
gfsmAutomaton
*fsm,
291
gfsmStateId
qid,
292
gfsmBitVector
*visited,
293
gfsmBitVector
*completed);
294
296
gboolean
gfsm_automaton_is_cyclic
(
gfsmAutomaton
*fsm);
297
299
#define gfsm_automaton_is_acyclic(fsm) (!gfsm_automaton_is_cyclic(fsm))
300
314
gfsmAlphabet
*
gfsm_automaton_get_alphabet
(
gfsmAutomaton
*fsm,
315
gfsmLabelSide
which,
316
gfsmAlphabet
*alph);
317
318
326
void
gfsm_automaton_renumber_states
(
gfsmAutomaton
*fsm);
327
340
void
gfsm_automaton_renumber_states_full
(
gfsmAutomaton
*fsm, GArray *old2new,
gfsmStateId
n_new_states);
341
343
void
gfsm_automaton_truncate_invalid_states
(
gfsmAutomaton
*fsm);
344
346
347
/*======================================================================*/
349
350
360
GFSM_INLINE
361
gfsmState
*
gfsm_automaton_open_state
(
gfsmAutomaton
*fsm,
gfsmStateId
qid);
362
373
GFSM_INLINE
374
gfsmState
*
gfsm_automaton_open_state_force
(
gfsmAutomaton
*fsm,
gfsmStateId
qid);
375
381
GFSM_INLINE
382
void
gfsm_automaton_close_state
(
gfsmAutomaton
*fsm,
gfsmState
*qp);
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
*/
408
GFSM_INLINE
409
gboolean
gfsm_automaton_has_state
(
gfsmAutomaton
*fsm,
gfsmStateId
qid);
410
419
GFSM_INLINE
420
gfsmStateId
gfsm_automaton_add_state_full
(
gfsmAutomaton
*fsm,
gfsmStateId
qid);
421
425
GFSM_INLINE
426
gfsmStateId
gfsm_automaton_ensure_state
(
gfsmAutomaton
*fsm,
gfsmStateId
qid);
427
431
GFSM_INLINE
432
gfsmStateId
gfsm_automaton_add_state
(
gfsmAutomaton
*fsm);
433
441
GFSM_INLINE
442
void
gfsm_automaton_remove_state
(
gfsmAutomaton
*fsm,
gfsmStateId
qid);
443
451
GFSM_INLINE
452
gboolean
gfsm_automaton_lookup_final
(
gfsmAutomaton
*fsm,
gfsmStateId
qid,
gfsmWeight
*wp);
453
460
GFSM_INLINE
461
gboolean
gfsm_automaton_state_is_final
(
gfsmAutomaton
*fsm,
gfsmStateId
qid);
462
464
#define gfsm_automaton_is_final_state(fsm,qid) gfsm_automaton_state_is_final((fsm),(qid))
465
467
GFSM_INLINE
468
gfsmWeight
gfsm_automaton_get_final_weight
(
gfsmAutomaton
*fsm,
gfsmStateId
qid);
469
478
GFSM_INLINE
479
void
gfsm_automaton_set_final_state_full
(
gfsmAutomaton
*fsm,
480
gfsmStateId
qid,
481
gboolean is_final,
482
gfsmWeight
final_weight);
483
487
GFSM_INLINE
488
void
gfsm_automaton_set_final_state
(
gfsmAutomaton
*fsm,
gfsmStateId
qid, gboolean is_final);
489
491
GFSM_INLINE
492
guint
gfsm_automaton_out_degree
(
gfsmAutomaton
*fsm,
gfsmStateId
qid);
493
495
496
/*======================================================================*/
498
499
510
GFSM_INLINE
511
void
gfsm_automaton_add_arc
(
gfsmAutomaton
*fsm,
512
gfsmStateId
qid1,
513
gfsmStateId
qid2,
514
gfsmLabelId
lo,
515
gfsmLabelId
hi,
516
gfsmWeight
w);
517
524
GFSM_INLINE
525
void
gfsm_automaton_add_arc_node
(
gfsmAutomaton
*fsm,
526
gfsmState
*sp,
527
gfsmArcList
*node);
528
530
GFSM_INLINE
531
void
gfsm_automaton_remove_arc_ptr
(
gfsmAutomaton
*fsm,
gfsmArc
*a);
532
534
GFSM_INLINE
535
void
gfsm_automaton_remove_arc_node
(
gfsmAutomaton
*fsm,
gfsmState
*sp,
gfsmArcList
*node);
536
545
GFSM_INLINE
546
gfsmAutomaton
*
gfsm_automaton_arcsort
(
gfsmAutomaton
*fsm,
gfsmArcCompMask
mode);
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
569
gfsmAutomaton
*
gfsm_automaton_arcuniq
(
gfsmAutomaton
*fsm);
570
572
573
//-- inline definitions
574
#ifdef GFSM_INLINE_ENABLED
575
# include <gfsmAutomaton.hi>
576
#endif
577
578
#endif
/* _GFSM_AUTOMATON_H */
Generated on Tue Oct 21 2014 09:44:47 for libgfsm by
1.8.1.2