aboutsummaryrefslogtreecommitdiff
path: root/gfsm/gfsm/src/libgfsm/gfsmCompound.hi
blob: cf0f006fc7d4617e8ef7a0d95a9f7f7b1182be4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*=============================================================================*\
 * File: gfsmCompound.hi
 * Author: Bryan Jurish <moocow@ling.uni-potsdam.de>
 * Description: finite state machine library: compound states: inline definitions
 *
 * Copyright (c) 2004-2007 Bryan Jurish.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *=============================================================================*/

#include <gfsmMem.h>
#include <stdlib.h>
#include <gfsmUtils.h>


/*======================================================================
 * Label Pair: Methods
 */

//--------------------------------------------------------------
// labelpair_new()
GFSM_INLINE
gfsmLabelPair gfsm_labelpair_new(guint32 lo, guint32 hi)
{
  return ((hi<<16)|lo);
}

//--------------------------------------------------------------
// labelpair_lower()
GFSM_INLINE
gfsmLabelId gfsm_labelpair_lower(gfsmLabelPair lp)
{ return (lp & 0xffff); }

//--------------------------------------------------------------
// labelpair_upper()
GFSM_INLINE
gfsmLabelId gfsm_labelpair_upper(gfsmLabelPair lp)
{ return ((lp>>16) & 0xffff); }


/*--------------------------------------------------------------
 * labelpair_compare()
 */
GFSM_INLINE
gint gfsm_labelpair_compare_inline(gfsmLabelPair lp1, gfsmLabelPair lp2)
{
  gfsmLabelId
    lo1 = gfsm_labelpair_lower(lp1),
    lo2 = gfsm_labelpair_lower(lp2),
    hi1 = gfsm_labelpair_upper(lp1),
    hi2 = gfsm_labelpair_upper(lp2);
  return (lo1 < lo2          ? -1
	  : (lo1 > lo2       ?  1
	     : (hi1 < hi2    ? -1
		: (hi1 > hi2 ?  1
		   :            0))));
}


/*======================================================================
 * Methods: gfsmStatePair
 */

/*--------------------------------------------------------------
 * statepair_new()
 */
GFSM_INLINE
gfsmStatePair *gfsm_statepair_new(gfsmStateId id1, gfsmStateId id2)
{
  gfsmStatePair *sp = g_new(gfsmStatePair,1);
  sp->id1 = id1;
  sp->id2 = id2;
  return sp;
}

/*--------------------------------------------------------------
 * statepair_clone()
 */
GFSM_INLINE
gfsmStatePair *gfsm_statepair_clone(gfsmStatePair *sp)
{
  return (gfsmStatePair*)gfsm_mem_dup_n(sp, sizeof(gfsmStatePair));
}

/*--------------------------------------------------------------
 * statepair_free()
 */
#if 0
GFSM_INLINE
void gfsm_statepair_free(gfsmStatePair *sp)
{ g_free(sp); }
#endif



/*======================================================================
 * Methods: gfsmComposeState
 */

/*--------------------------------------------------------------
 * compose_state_new()
 */
GFSM_INLINE
gfsmComposeState *gfsm_compose_state_new(gfsmStateId id1, gfsmStateId id2, gfsmComposeFilterState idf)
{
  gfsmComposeState *sp = g_new(gfsmComposeState,1);
  sp->id1 = id1;
  sp->id2 = id2;
  sp->idf = idf;
  return sp;
}

/*--------------------------------------------------------------
 * compose_state_clone()
 */
GFSM_INLINE
gfsmComposeState *gfsm_compose_state_clone(gfsmComposeState *sp)
{
  return (gfsmComposeState*)gfsm_mem_dup_n(sp, sizeof(gfsmComposeState));
}

/*--------------------------------------------------------------
 * compose_state_free()
 */
#if 0
GFSM_INLINE
void gfsm_compose_state_free(gfsmComposeState *sp)
{ g_free(sp); }
#endif



/*======================================================================
 * Methods: gfsmStateWeightPair
 */

//--------------------------------------------------------------
GFSM_INLINE
gfsmStateWeightPair *gfsm_state_weight_pair_new(gfsmStateId id, gfsmWeight w)
{
  gfsmStateWeightPair *swp = g_new(gfsmStateWeightPair,1);
  swp->id = id;
  swp->w  = w;
  return swp;
}

//--------------------------------------------------------------
GFSM_INLINE
gfsmStateWeightPair *gfsm_state_weight_pair_clone(const gfsmStateWeightPair *swp)
{
  return gfsm_state_weight_pair_new(swp->id,swp->w);
}

//--------------------------------------------------------------
#if 0
GFSM_INLINE
void gfsm_state_weight_pair_free(gfsmStateWeightPair *swp)
{ g_free(swp); }
#endif


/*======================================================================
 * Methods: gfsmStatePairEnum
 */

/*--------------------------------------------------------------
 * statepair_enum_new()
 */
GFSM_INLINE
gfsmStatePairEnum *gfsm_statepair_enum_new(void)
{
  return gfsm_enum_new_full((gfsmDupFunc)gfsm_statepair_clone,
			    (GHashFunc)gfsm_statepair_hash,
			    (GEqualFunc)gfsm_statepair_equal,
			    (GDestroyNotify)g_free);
}


/*======================================================================
 * Methods: gfsmComposeStateEnum
 */

/*--------------------------------------------------------------
 * compose_state_enum_new()
 */
GFSM_INLINE
gfsmComposeStateEnum *gfsm_compose_state_enum_new(void)
{
  return gfsm_enum_new_full((gfsmDupFunc)gfsm_compose_state_clone,
			    (GHashFunc)gfsm_compose_state_hash,
			    (GEqualFunc)gfsm_compose_state_equal,
			    (GDestroyNotify)g_free);
}

/*======================================================================
 * Methods: StatePair2WeightHash
 */
GFSM_INLINE
gfsmStatePair2WeightHash *gfsm_statepair2weighthash_new(void)
{
  return gfsm_weighthash_new_full((gfsmDupFunc)gfsm_statepair_clone,
				  (GHashFunc)gfsm_statepair_hash,
				  (GEqualFunc)gfsm_statepair_equal,
				  (GDestroyNotify)g_free);
}