aboutsummaryrefslogtreecommitdiff
path: root/gfsm/gfsm/src/libgfsm/gfsmCompound.c
blob: ec54502dc1f3ff80cbf02765fbf116530f6517c4 (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
/*=============================================================================*\
 * File: gfsmCompound.c
 * Author: Bryan Jurish <moocow@ling.uni-potsdam.de>
 * Description: finite state machine library: compound states
 *
 * 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 <gfsmCompound.h>

//-- no-inline definitions
#ifndef GFSM_INLINE_ENABLED
# include <gfsmCompound.hi>
#endif

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

/*--------------------------------------------------------------
 * labelpair_compare()
 */
gint gfsm_labelpair_compare(gfsmLabelPair lp1, gfsmLabelPair lp2)
{ return gfsm_labelpair_compare_inline(lp1,lp2); }

/*--------------------------------------------------------------
 * labelpair_compare_with_data()
 */
gint gfsm_labelpair_compare_with_data(gfsmLabelPair lp1, gfsmLabelPair lp2, gpointer data)
{ return gfsm_labelpair_compare_inline(lp1,lp2); }


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

/*--------------------------------------------------------------
 * statepair_hash()
 */
guint gfsm_statepair_hash(gfsmStatePair *sp)
{
  //return 7*sp->id1 + sp->id2;
  //return 5039*sp->id1 + sp->id2;
  return 7949*sp->id1 + sp->id2;
}


/*--------------------------------------------------------------
 * statepair_compare()
 */
gint gfsm_statepair_compare(const gfsmStatePair *sp1, const gfsmStatePair *sp2)
{
  return (sp1->id1 < sp2->id1 ? -1
	  : (sp1->id1 > sp2->id1 ? 1
	     : (sp1->id2 < sp2->id2 ? -1
		: (sp1->id2 > sp2->id2 ? 1
		   : 0))));
}

/*--------------------------------------------------------------
 * statepair_equal()
 */
gboolean gfsm_statepair_equal(const gfsmStatePair *sp1, const gfsmStatePair *sp2)
{
  return sp1->id1==sp2->id1 && sp1->id2==sp2->id2;
}



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

/*--------------------------------------------------------------
 * compose_state_hash()
 */
guint gfsm_compose_state_hash(gfsmComposeState *sp)
{
  return 7949*sp->id1 + sp->id2 + 7963*sp->idf;
}


/*--------------------------------------------------------------
 * compose_state_compare()
 */
gint gfsm_compose_state_compare(const gfsmComposeState *sp1, const gfsmComposeState *sp2)
{
  return (sp1->id1 < sp2->id1 ? -1
	  : (sp1->id1 > sp2->id1 ? 1
	     : (sp1->id2 < sp2->id2 ? -1
		: (sp1->id2 > sp2->id2 ? 1
		   : (sp1->idf < sp2->idf ? -1
		      : (sp1->idf > sp2->idf ? 1
			 : 0))))));
}

/*--------------------------------------------------------------
 * compose_state_equal()
 */
gboolean gfsm_compose_state_equal(const gfsmComposeState *sp1, const gfsmComposeState *sp2)
{
  return sp1->id1==sp2->id1 && sp1->id2==sp2->id2 && sp1->idf==sp2->idf;
}



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

//--------------------------------------------------------------
guint gfsm_state_weight_pair_hash(gfsmStateWeightPair *swp)
{
  return swp->id;
}

//--------------------------------------------------------------
gint gfsm_state_weight_pair_compare(const gfsmStateWeightPair *swp1, const gfsmStateWeightPair *swp2, gfsmSemiring *sr)
{
  return (swp1->id < swp2->id ? -1
	  : (swp1->id > swp2->id ? 1
	     : gfsm_sr_compare(sr,swp1->w,swp2->w)));
}

//--------------------------------------------------------------
gboolean gfsm_state_weight_pair_equal(const gfsmStateWeightPair *swp1, const gfsmStateWeightPair *swp2)
{
  return swp1->id==swp2->id && swp1->w==swp2->w;
}


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


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