aboutsummaryrefslogtreecommitdiff
path: root/gfsm/gfsm/src/libgfsm/gfsmSet.hi
blob: 6ff98af9e1b929c93497d8772ec0bd94cfaa7dd8 (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
/*=============================================================================*\
 * File: gfsmSet.hi
 * Author: Bryan Jurish <moocow@ling.uni-potsdam.de>
 * Description: finite state machine library
 *
 * 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
 *=============================================================================*/

/*======================================================================
 * Converters
 */

/*--------------------------------------------------------------
 * to_slist()
 */
GFSM_INLINE
GSList *gfsm_set_to_slist(gfsmSet *set)
{
  GSList *l = NULL;
  gfsm_set_foreach(set,(GTraverseFunc)gfsm_set_to_slist_foreach_func, &l);
  return l;
}

/*--------------------------------------------------------------
 * to_ptr_array()
 */
GFSM_INLINE
void gfsm_set_to_ptr_array(gfsmSet *set, GPtrArray *array)
{
  gfsm_set_foreach(set,(GTraverseFunc)gfsm_set_to_ptr_array_foreach_func, array);
}


/*======================================================================
 * Constructors etc.
 */

/*--------------------------------------------------------------
 * new_full()
 */
GFSM_INLINE
gfsmSet *gfsm_set_new_full(GCompareDataFunc key_cmp_func, gpointer key_cmp_data, GDestroyNotify key_free_func)
{
  return g_tree_new_full(key_cmp_func, key_cmp_data, key_free_func, NULL);
}

/*--------------------------------------------------------------
 * new()
 */
GFSM_INLINE
gfsmSet *gfsm_set_new(GCompareFunc key_cmp_func)
{
  return g_tree_new(key_cmp_func);
}

/*--------------------------------------------------------------
 * copy()
 */
GFSM_INLINE
gfsmSet *gfsm_set_copy(gfsmSet *dst, gfsmSet *src)
{
  gfsm_set_clear(dst);
  g_tree_foreach(src, (GTraverseFunc)gfsm_set_copy_foreach_func, dst);
  return dst;
}


/*--------------------------------------------------------------
 * clear()
 */
//-- extern

/*--------------------------------------------------------------
 * free()
 */
#if 0
GFSM_INLINE
void gfsm_set_free(gfsmSet *set)
{
  g_tree_destroy(set);
}
#endif


/*======================================================================
 * Set Algebra
 */

/*--------------------------------------------------------------
 * union(): data
 */
typedef struct {
  gfsmSet      *dst;
  gfsmDupFunc   dupfunc;
} gfsmSetUnionData;


/*--------------------------------------------------------------
 * union()
 */
gboolean gfsm_set_union_func(gpointer key, gpointer value, gfsmSetUnionData *data);

GFSM_INLINE
gfsmSet *gfsm_set_union(gfsmSet *set1, gfsmSet *set2, gfsmDupFunc dupfunc)
{
  gfsmSetUnionData data = { set1, dupfunc };
  g_tree_foreach(set2, (GTraverseFunc)gfsm_set_union_func, &data);
  return set1;
}

/*--------------------------------------------------------------
 * difference()
 */
gboolean gfsm_set_difference_func(gpointer key, gpointer value, gfsmSet *set1);

GFSM_INLINE
gfsmSet *gfsm_set_difference(gfsmSet *set1, gfsmSet *set2)
{
  g_tree_foreach(set2, (GTraverseFunc)gfsm_set_difference_func, set1);
  return set1;
}