ContextGraph.xs

filter: Statementstmt 0.0% 0 / 68 Branchbran 0.0% 0 / 60 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 128 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/Search/bench.pl ↑ Summary cns.c »
1 /*
2 Search::ContextGraph - XS implementation
3  
4 (C) 2003 Schuyler Erle, Maciej Ceglowski
5
6 This is free software, released
7 under the GPL. See LICENSE for more
8 information.
9
10 */
11
12 #include "EXTERN.h"
13 #include "perl.h"
14 #include "XSUB.h"
15 #include "ppport.h"
16 #include "cns.h"
17 #include "const-c.inc"
18  
19  
20 #define DEFAULT_CAPACITY 2
21  
22
23 MODULE = Search::ContextGraph PACKAGE = Search::ContextGraph
24  
25 INCLUDE: const-xs.inc
26  
27 void
28 free_node(node)
29 Node * node
30  
31 Edge *
32 new_edge(edge, sink, weight)
33 Edge * edge
34 long sink
35 float weight
36  
37 Graph *
38 new_graph(graph, capacity = DEFAULT_CAPACITY, activationThreshold = 1, collectionThreshold = 1, maxDepth = 100000000)
39 Graph * graph
40 long capacity
41 float activationThreshold
42 float collectionThreshold
43 long maxDepth
44  
45 Node *
46 new_node(node, type, capacity=DEFAULT_CAPACITY)
47 Node * node
48 int type
49 long capacity
50  
51 MODULE = Search::ContextGraph PACKAGE = Search::ContextGraph::Graph
52  
53 Node *
54 add_node(graph, id, type, capacity=DEFAULT_CAPACITY)
55 Graph * graph
56 long id
57 int type
58 long capacity
59  
60  
61 void
62 collect_results(graph)
63 Graph * graph
64
65 PREINIT:
66 AV * list;
67 AV *entry;
68 SV *undef;
69 Edge *result;
70 int startSize;
71 int i;
72 int result_count;
73
74 INIT:
75 0 result_count = 0;
76 0 undef = (SV*) &PL_sv_undef;
77 0 list = (AV *) sv_2mortal((SV *)newAV());
78 0 startSize = 64;
79
80 PPCODE:
81 0 result = collect_results(graph);
82 0 ▶ for (i = 0; result[i].weight > 0; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; result[i].weight > 0; i++) { 0 0 0
83 0 entry = newAV();
84 /* fprintf( stderr, "weight %ld, %ld, %f \n", i, result[i].sink, result[i].weight);
85 */
86 0 av_push(entry, newSViv(result[i].sink));
87 0 av_push(entry, newSVnv(result[i].weight));
88 0 av_push(list, newRV_noinc((SV *)entry));
89 0 result_count++;
90 }
91
92 //fprintf( stderr, "result count %ld ", result_count);
93  
94 0 ▶ if ( result_count > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( result_count > 0 ) { 0 0 0
95 0 ▶ XPUSHs(newRV_noinc((SV *)list));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(newRV_noinc((SV *)list)); 0 0 0
96 } else {
97 0 ▶ XPUSHs( undef );
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs( undef ); 0 0 0
98 }
99 0 free( result );
100
101
102  
103 int
104 energize_node(graph, id, energy, isStart)
105 Graph * graph
106 int id
107 float energy
108 int isStart
109  
110 void
111 preallocate( graph, number )
112 Graph * graph
113 int number
114
115 void
116 reset_graph(graph)
117 Graph * graph
118  
119 void
120 free_graph(graph)
121 Graph * graph
122  
123 Graph *
124 new(CLASS, startingEnergy = 100, activationEnergy = 1, collectionEnergy = 1, maxDepth = 100000000)
125 char *CLASS = NO_INIT
126 float startingEnergy;
127 float activationEnergy;
128 float collectionEnergy;
129 long maxDepth;
130
131 PROTOTYPE: $;$$$$
132 CODE:
133 /* Zero((void*)&RETVAL, sizeof(RETVAL), char); */
134 0 RETVAL = malloc(sizeof(Graph));
135 /* fprintf( stderr, "NEW called: %p\n", RETVAL ); */
136 0 new_graph(
137 (Graph *)RETVAL, DEFAULT_CAPACITY,
138 activationEnergy, collectionEnergy, maxDepth);
139 OUTPUT:
140 RETVAL
141  
142 void
143 DESTROY(THIS)
144 Graph * THIS;
145 PROTOTYPE: $
146 CODE:
147
148 0 free_graph(THIS);
149  
150 long
151 size(THIS, __value = NO_INIT)
152 Graph * THIS
153 long __value
154 PROTOTYPE: $;$
155 CODE:
156 0 ▶ if (items > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (items > 1) 0 0 0
157 0 THIS->size = __value;
158 0 ▶ RETVAL = THIS->size;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = THIS->size; 0 0 0
159 OUTPUT:
160 RETVAL
161  
162 long
163 capacity(THIS, __value = NO_INIT)
164 Graph * THIS
165 long __value
166 PROTOTYPE: $;$
167
168 CODE:
169 0 ▶ if (items > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (items > 1) 0 0 0
170 0 THIS->capacity = __value;
171 0 ▶ RETVAL = THIS->capacity;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = THIS->capacity; 0 0 0
172 OUTPUT:
173 RETVAL
174  
175 float
176 activationThreshold(THIS, __value = NO_INIT)
177 Graph * THIS
178 float __value
179 PROTOTYPE: $;$
180
181 CODE:
182 0 ▶ if (items > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (items > 1) 0 0 0
183 0 THIS->activationThreshold = __value;
184 0 ▶ RETVAL = THIS->activationThreshold;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = THIS->activationThreshold; 0 0 0
185 OUTPUT:
186 RETVAL
187  
188 float
189 collectionThreshold(THIS, __value = NO_INIT)
190 Graph * THIS
191 float __value
192 PROTOTYPE: $;$
193 CODE:
194 0 ▶ if (items > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (items > 1) 0 0 0
195 0 THIS->collectionThreshold = __value;
196 0 ▶ RETVAL = THIS->collectionThreshold;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = THIS->collectionThreshold; 0 0 0
197 OUTPUT:
198 RETVAL
199  
200 float
201 startingEnergy(THIS, __value = NO_INIT)
202 Graph * THIS
203 float __value
204 PROTOTYPE: $;$
205 CODE:
206 0 ▶ if (items > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (items > 1) 0 0 0
207 0 THIS->startingEnergy = __value;
208 0 ▶ RETVAL = THIS->startingEnergy;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = THIS->startingEnergy; 0 0 0
209 OUTPUT:
210 RETVAL
211  
212 int
213 maxDepth( THIS )
214 Graph * THIS
215 PROTOTYPE: $
216 CODE:
217 0 ▶ RETVAL = THIS->maxDepth;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = THIS->maxDepth; 0 0 0
218 OUTPUT:
219 RETVAL
220
221 int
222 numCalls( THIS )
223 Graph * THIS
224 PROTOTYPE: $
225 CODE:
226 0 ▶ RETVAL = THIS->numCalls;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = THIS->numCalls; 0 0 0
227 OUTPUT:
228 RETVAL
229
230 long
231 debug(THIS, __value = NO_INIT)
232 Graph * THIS
233 long __value
234 PROTOTYPE: $;$
235 CODE:
236 0 ▶ if (items > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (items > 1) 0 0 0
237 0 THIS->debug = __value;
238 0 ▶ RETVAL = THIS->debug;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = THIS->debug; 0 0 0
239 OUTPUT:
240 RETVAL
241  
242 long
243 indent(THIS, __value = NO_INIT)
244 Graph * THIS
245 long __value
246 PROTOTYPE: $;$
247
248 CODE:
249 0 ▶ if (items > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (items > 1) 0 0 0
250 0 THIS->indent = __value;
251 0 ▶ RETVAL = THIS->indent;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = THIS->indent; 0 0 0
252 OUTPUT:
253 RETVAL
254  
255 void
256 set_edge(THIS, source, sink, weight)
257 Graph *THIS
258 long source
259 long sink
260 float weight
261 PROTOTYPE: $$$$
262 PREINIT:
263 Node *n;
264 Node *m;
265
266 CODE:
267 0 n = THIS->nodes + source;
268 0 m = THIS->nodes + sink;
269 0 add_edge( n, sink, weight );
270 0 add_edge( m, source, weight );
271  
272 void
273 presize_node( THIS, node, size )
274 Graph *THIS
275 long node
276 int size
277  
278  
279 void
280 set_directed_edge(THIS, source, sink, weight)
281 Graph *THIS
282 long source
283 long sink
284 float weight
285 PROTOTYPE: $$$$
286 PREINIT:
287 Node *n;
288 CODE:
289 0 n = THIS->nodes + source;
290 0 add_edge( n, sink, weight );
291
292 MODULE = Search::ContextGraph PACKAGE = Search::ContextGraph::Node
293  
294 Edge *
295 add_edge(node, sink, weight)
296 Node * node
297 long sink
298 float weight
299  
300 Node *
301 new(CLASS, type, capacity = DEFAULT_CAPACITY)
302 char *CLASS = NO_INIT
303 int type
304 long capacity
305 PROTOTYPE: $$;$
306 CODE:
307 /* Zero((void*)&RETVAL, sizeof(RETVAL), char); */
308 0 RETVAL = malloc(sizeof(Node));
309 0 new_node((Node *)RETVAL, type, capacity);
310 OUTPUT:
311 RETVAL
312  
313  
314  
315 long
316 degree(THIS, __value = NO_INIT)
317 Node * THIS
318 long __value
319 PROTOTYPE: $;$
320 CODE:
321 0 ▶ if (items > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (items > 1) 0 0 0
322 0 THIS->degree = __value;
323 0 ▶ RETVAL = THIS->degree;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = THIS->degree; 0 0 0
324 OUTPUT:
325 RETVAL
326  
327 long
328 capacity(THIS, __value = NO_INIT)
329 Node * THIS
330 long __value
331 PROTOTYPE: $;$
332 CODE:
333 0 ▶ if (items > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (items > 1) 0 0 0
334 0 THIS->capacity = __value;
335 0 ▶ RETVAL = THIS->capacity;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = THIS->capacity; 0 0 0
336 OUTPUT:
337 RETVAL
338  
339 float
340 energy(THIS, __value = NO_INIT)
341 Node * THIS
342 float __value
343 PROTOTYPE: $;$
344 CODE:
345 0 ▶ if (items > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (items > 1) 0 0 0
346 0 THIS->energy = __value;
347 0 ▶ RETVAL = THIS->energy;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = THIS->energy; 0 0 0
348 OUTPUT:
349 RETVAL
350  
351  
352 MODULE = Search::ContextGraph PACKAGE = Search::ContextGraph::Edge
353  
354 Edge *
355 new(CLASS, sink, weight)
356 long sink
357 float weight
358 PROTOTYPE: $$$
359 INIT:
360 0 sink = 0;
361 0 weight = 0;
362 CODE:
363 0 RETVAL = malloc(sizeof(Edge));
364 0 new_edge((Edge *)RETVAL, sink, weight);
365 OUTPUT:
366 RETVAL
367  
368 long
369 sink(THIS, __value = NO_INIT)
370 Edge * THIS
371 long __value
372 PROTOTYPE: $;$
373 CODE:
374 0 ▶ if (items > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (items > 1) 0 0 0
375 0 THIS->sink = __value;
376 0 ▶ RETVAL = THIS->sink;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = THIS->sink; 0 0 0
377 OUTPUT:
378 RETVAL
379  
380 float
381 weight(THIS, __value = NO_INIT)
382 Edge * THIS
383 float __value
384 PROTOTYPE: $;$
385 CODE:
386 0 ▶ if (items > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (items > 1) 0 0 0
387 0 THIS->weight = __value;
388 0 ▶ RETVAL = THIS->weight;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = THIS->weight; 0 0 0
389 OUTPUT:
390 RETVAL
391  
« blib/lib/Search/bench.pl ↑ Summary cns.c »