forked from WojciechMula/pyDAWG
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpydawg.c
More file actions
85 lines (67 loc) · 1.66 KB
/
Copy pathpydawg.c
File metadata and controls
85 lines (67 loc) · 1.66 KB
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
/*
This is part of pydawg Python module.
Python module body.
Author : Wojciech Mu³a, wojciech_mula@poczta.onet.pl
WWW : http://0x80.pl/proj/pydawg/
License : 3-clauses BSD (see LICENSE)
Date : $Date$
$Id$
*/
#include "common.h"
#include "dawgnode.h"
#include "dawg.h"
#include "DAWG_class.h"
#include "DAWGIterator_class.h"
// c library inlined
#include "dawgnode.c"
#include "dawg.c"
// python class
#include "utils.c"
#include "DAWG_class.c"
#include "DAWGIterator_class.c"
// module
static
PyModuleDef pydawg_module = {
PyModuleDef_HEAD_INIT,
"pydawg",
"pydawg module",
-1,
NULL
};
PyMODINIT_FUNC
PyInit_pydawg(void) {
PyObject* module;
dawg_as_sequence.sq_length = dawgmeth_len;
dawg_as_sequence.sq_contains = dawgmeth_contains;
dawg_type.tp_as_sequence = &dawg_as_sequence;
module = PyModule_Create(&pydawg_module);
if (module == NULL)
return NULL;
if (PyType_Ready(&dawg_type) < 0) {
Py_DECREF(module);
return NULL;
}
else
PyModule_AddObject(module, "DAWG", (PyObject*)&dawg_type);
#define constant(name) PyModule_AddIntConstant(module, #name, name)
constant(EMPTY);
constant(ACTIVE);
constant(CLOSED);
constant(MATCH_EXACT_LENGTH);
constant(MATCH_AT_MOST_PREFIX);
constant(MATCH_AT_LEAST_PREFIX);
#undef constant
#ifdef DAWG_PERFECT_HASHING
PyModule_AddIntConstant(module, "perfect_hashing", 1);
PyModule_AddIntConstant(module, "perfect_hasing", 1);
#else
PyModule_AddIntConstant(module, "perfect_hashing", 0);
PyModule_AddIntConstant(module, "perfect_hasing", 0);
#endif
#ifdef DAWG_UNICODE
PyModule_AddIntConstant(module, "unicode", 1);
#else
PyModule_AddIntConstant(module, "unicode", 0);
#endif
return module;
}