/[Search-TokyoDystopia]/TokyoDystopia.xs
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /TokyoDystopia.xs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 32 - (show annotations)
Tue Sep 2 16:13:06 2008 UTC (15 years, 6 months ago) by dpavlin
File size: 6115 byte(s)
added Q-gram API which segfaults on tcqdbput right now [0.01]
1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4 #include <dystopia.h>
5 #include <stdlib.h>
6 #include <stdbool.h>
7 #include <stdint.h>
8
9
10 MODULE = Search::TokyoDystopia PACKAGE = Search::TokyoDystopia
11 PROTOTYPES: DISABLE
12
13
14 const char *
15 tdversion()
16 CODE:
17 RETVAL = tdversion;
18 OUTPUT:
19 RETVAL
20
21
22 const char *
23 tcidberrmsg(ecode)
24 int ecode
25 CODE:
26 RETVAL = tcidberrmsg(ecode);
27 OUTPUT:
28 RETVAL
29
30
31 void *
32 tcidbnew()
33 PREINIT:
34 TCIDB *idb;
35 CODE:
36 idb = tcidbnew();
37 RETVAL = idb;
38 OUTPUT:
39 RETVAL
40
41
42 void
43 tcidbdel(idb)
44 void * idb
45 CODE:
46 tcidbdel(idb);
47
48
49 int
50 tcidbecode(idb)
51 void * idb
52 CODE:
53 RETVAL = tcidbecode(idb);
54 OUTPUT:
55 RETVAL
56
57
58 int
59 tcidbtune(idb, ernum, etnum, iusiz, opts)
60 void * idb
61 int ernum
62 int etnum
63 int iusiz
64 int opts
65 CODE:
66 RETVAL = tcidbtune(idb, ernum, etnum, iusiz, opts);
67 OUTPUT:
68 RETVAL
69
70
71 int
72 tcidbsetcache(idb, icsiz, lcnum)
73 void * idb
74 int icsiz
75 int lcnum
76 CODE:
77 RETVAL = tcidbsetcache(idb, icsiz, lcnum);
78 OUTPUT:
79 RETVAL
80
81
82 int
83 tcidbsetfwmmax(idb, fwmax)
84 void * idb
85 int fwmax
86 CODE:
87 RETVAL = tcidbsetfwmmax(idb, fwmax);
88 OUTPUT:
89 RETVAL
90
91
92 int
93 tcidbopen(idb, path, omode)
94 void * idb
95 char * path
96 int omode
97 CODE:
98 RETVAL = tcidbopen(idb, path, omode);
99 OUTPUT:
100 RETVAL
101
102
103 int
104 tcidbclose(idb)
105 void * idb
106 CODE:
107 RETVAL = tcidbclose(idb);
108 OUTPUT:
109 RETVAL
110
111
112 int
113 tcidbput(idb, id, val)
114 void * idb
115 int id
116 SV * val
117 PREINIT:
118 STRLEN vsiz;
119 const char *vbuf;
120 CODE:
121 vbuf = SvPV(val, vsiz);
122 RETVAL = tcidbput(idb, id, vbuf);
123 OUTPUT:
124 RETVAL
125
126
127 int
128 tcidbout(idb, id)
129 void * idb
130 int id
131 CODE:
132 RETVAL = tcidbout(idb, id);
133 OUTPUT:
134 RETVAL
135
136
137 void
138 tcidbget(idb, id)
139 void * idb
140 int id
141 PREINIT:
142 char *vbuf;
143 PPCODE:
144 vbuf = tcidbget(idb, id);
145 if(vbuf){
146 XPUSHs(sv_2mortal(newSVpvn(vbuf, strlen(vbuf))));
147 tcfree(vbuf);
148 } else {
149 XPUSHs((SV *)&PL_sv_undef);
150 }
151 XSRETURN(1);
152
153
154 void
155 tcidbsearch(idb, word, smode)
156 void * idb
157 SV * word
158 int smode
159 PREINIT:
160 AV *av;
161 STRLEN wsize;
162 uint64_t *results;
163 const char *wbuf;
164 int i, rnum;
165 PPCODE:
166 wbuf = SvPV(word, wsize);
167 results = tcidbsearch(idb, wbuf, smode, &rnum);
168 if ( rnum > 0 ) {
169 av = newAV();
170 for(i = 0; i < rnum; i++){
171 av_push(av, newSViv( (int)results[i] ));
172 }
173 XPUSHs(sv_2mortal(newRV_noinc((SV *)av)));
174 } else {
175 XPUSHs((SV *)&PL_sv_undef);
176 }
177 XSRETURN(1);
178
179
180 void
181 tcidbsearch2(idb, expr)
182 void * idb
183 SV * expr
184 PREINIT:
185 AV *av;
186 STRLEN wsize;
187 uint64_t *results;
188 const char *wbuf;
189 int i, rnum;
190 PPCODE:
191 wbuf = SvPV(expr, wsize);
192 results = tcidbsearch2(idb, wbuf, &rnum);
193 if ( rnum > 0 ) {
194 av = newAV();
195 for(i = 0; i < rnum; i++){
196 av_push(av, newSViv( (int)results[i] )); // FIXME convert to double?
197 }
198 XPUSHs(sv_2mortal(newRV_noinc((SV *)av)));
199 } else {
200 XPUSHs((SV *)&PL_sv_undef);
201 }
202 XSRETURN(1);
203
204
205 int
206 tcidbiterinit(idb)
207 void * idb
208 CODE:
209 RETVAL = tcidbiterinit(idb);
210 OUTPUT:
211 RETVAL
212
213
214 double
215 tcidbiternext(idb)
216 void * idb
217 CODE:
218 RETVAL = tcidbiternext(idb);
219 OUTPUT:
220 RETVAL
221
222
223 int
224 tcidbsync(idb)
225 void * idb
226 CODE:
227 RETVAL = tcidbsync(idb);
228 OUTPUT:
229 RETVAL
230
231
232 int
233 tcidboptimize(idb)
234 void * idb
235 CODE:
236 RETVAL = tcidboptimize(idb);
237 OUTPUT:
238 RETVAL
239
240
241 int
242 tcidbvanish(idb)
243 void * idb
244 CODE:
245 RETVAL = tcidbvanish(idb);
246 OUTPUT:
247 RETVAL
248
249
250 int
251 tcidbcopy(idb, path)
252 void * idb
253 char * path
254 CODE:
255 RETVAL = tcidbcopy(idb, path);
256 OUTPUT:
257 RETVAL
258
259
260 void
261 tcidbpath(idb)
262 void * idb
263 PREINIT:
264 const char *path;
265 PPCODE:
266 path = tcidbpath(idb);
267 if(path){
268 XPUSHs(sv_2mortal(newSVpv(path, 0)));
269 } else {
270 XPUSHs((SV *)&PL_sv_undef);
271 }
272 XSRETURN(1);
273
274
275 double
276 tcidbrnum(idb)
277 void * idb
278 CODE:
279 RETVAL = tcidbrnum(idb);
280 OUTPUT:
281 RETVAL
282
283
284 double
285 tcidbfsiz(idb)
286 void * idb
287 CODE:
288 RETVAL = tcidbfsiz(idb);
289 OUTPUT:
290 RETVAL
291
292
293 #include <tcqdb.h>
294
295 const char *
296 tcqdberrmsg(ecode)
297 int ecode
298 CODE:
299 RETVAL = tcqdberrmsg(ecode);
300 OUTPUT:
301 RETVAL
302
303
304 void *
305 tcqdbnew()
306 PREINIT:
307 TCQDB *qdb;
308 CODE:
309 qdb = tcqdbnew();
310 RETVAL = qdb;
311 OUTPUT:
312 RETVAL
313
314
315 void
316 tcqdbdel(qdb)
317 void * qdb
318 CODE:
319 tcqdbdel(qdb);
320
321
322 int
323 tcqdbecode(qdb)
324 void * qdb
325 CODE:
326 RETVAL = tcqdbecode(qdb);
327 OUTPUT:
328 RETVAL
329
330
331 int
332 tcqdbtune(qdb, etnum, opts)
333 void * qdb
334 int etnum
335 int opts
336 CODE:
337 RETVAL = tcqdbtune(qdb, etnum, opts);
338 OUTPUT:
339 RETVAL
340
341
342 int
343 tcqdbsetcache(qdb, icsiz, lcnum)
344 void * qdb
345 int icsiz
346 int lcnum
347 CODE:
348 RETVAL = tcqdbsetcache(qdb, icsiz, lcnum);
349 OUTPUT:
350 RETVAL
351
352
353 int
354 tcqdbsetfwmmax(qdb, fwmax)
355 void * qdb
356 int fwmax
357 CODE:
358 RETVAL = tcqdbsetfwmmax(qdb, fwmax);
359 OUTPUT:
360 RETVAL
361
362
363 int
364 tcqdbopen(qdb, path, omode)
365 void * qdb
366 char * path
367 int omode
368 CODE:
369 RETVAL = tcqdbopen(qdb, path, omode);
370 OUTPUT:
371 RETVAL
372
373
374 int
375 tcqdbclose(qdb)
376 void * qdb
377 CODE:
378 RETVAL = tcqdbclose(qdb);
379 OUTPUT:
380 RETVAL
381
382
383 int
384 tcqdbput(qdb, id, val)
385 void * qdb
386 int id
387 SV * val
388 PREINIT:
389 STRLEN vsiz;
390 const char *vbuf;
391 CODE:
392 vbuf = SvPV(val, vsiz);
393 RETVAL = tcqdbput(qdb, id, vbuf);
394 OUTPUT:
395 RETVAL
396
397
398 int
399 tcqdbout(qdb, id)
400 void * qdb
401 int id
402 const char *text; /* FIXME return old value */
403 CODE:
404 RETVAL = tcqdbout(qdb, id, text);
405 OUTPUT:
406 RETVAL
407
408
409 void
410 tcqdbsearch(qdb, word, smode)
411 void * qdb
412 SV * word
413 int smode
414 PREINIT:
415 AV *av;
416 STRLEN wsize;
417 uint64_t *results;
418 const char *wbuf;
419 int i, rnum;
420 PPCODE:
421 wbuf = SvPV(word, wsize);
422 results = tcqdbsearch(qdb, wbuf, smode, &rnum);
423 if ( rnum > 0 ) {
424 av = newAV();
425 for(i = 0; i < rnum; i++){
426 av_push(av, newSViv( (int)results[i] ));
427 }
428 XPUSHs(sv_2mortal(newRV_noinc((SV *)av)));
429 } else {
430 XPUSHs((SV *)&PL_sv_undef);
431 }
432 XSRETURN(1);
433
434
435 int
436 tcqdbsync(qdb)
437 void * qdb
438 CODE:
439 RETVAL = tcqdbsync(qdb);
440 OUTPUT:
441 RETVAL
442
443
444 int
445 tcqdboptimize(qdb)
446 void * qdb
447 CODE:
448 RETVAL = tcqdboptimize(qdb);
449 OUTPUT:
450 RETVAL
451
452
453 int
454 tcqdbvanish(qdb)
455 void * qdb
456 CODE:
457 RETVAL = tcqdbvanish(qdb);
458 OUTPUT:
459 RETVAL
460
461
462 int
463 tcqdbcopy(qdb, path)
464 void * qdb
465 char * path
466 CODE:
467 RETVAL = tcqdbcopy(qdb, path);
468 OUTPUT:
469 RETVAL
470
471
472 void
473 tcqdbpath(qdb)
474 void * qdb
475 PREINIT:
476 const char *path;
477 PPCODE:
478 path = tcqdbpath(qdb);
479 if(path){
480 XPUSHs(sv_2mortal(newSVpv(path, 0)));
481 } else {
482 XPUSHs((SV *)&PL_sv_undef);
483 }
484 XSRETURN(1);
485
486
487 double
488 tcqdbtnum(qdb)
489 void * qdb
490 CODE:
491 RETVAL = tcqdbtnum(qdb);
492 OUTPUT:
493 RETVAL
494
495
496 double
497 tcqdbfsiz(qdb)
498 void * qdb
499 CODE:
500 RETVAL = tcqdbfsiz(qdb);
501 OUTPUT:
502 RETVAL
503

  ViewVC Help
Powered by ViewVC 1.1.26