Commit a22a734413385f29408ca87248f37a7d7dd789e7
1 parent
41cbc0cc
- różne drobne poprawki
git-svn-id: svn://svn.nlp.ipipan.waw.pl/morfeusz/morfeusz@5 ff4e3ee1-f430-4e82-ade0-24591c43f1fd
Showing
5 changed files
with
39 additions
and
32 deletions
fsa/CMakeLists.txt
1 | 1 | |
2 | 2 | add_executable (test_dict test_dict.cpp) |
3 | 3 | add_executable (test_speed test_speed.cpp) |
4 | +add_executable (test_speed_profile test_speed.cpp) | |
4 | 5 | set_target_properties ( test_dict PROPERTIES COMPILE_FLAGS "-std=gnu++0x -Wall -g" ) |
5 | 6 | set_target_properties ( test_speed PROPERTIES COMPILE_FLAGS "-std=gnu++0x -Wall -O2" ) |
7 | +set_target_properties ( test_speed_profile PROPERTIES COMPILE_FLAGS "-std=gnu++0x -Wall -g -O2" ) | |
... | ... |
fsa/_fsa_impl.hpp
... | ... | @@ -30,9 +30,9 @@ struct TransitionData { |
30 | 30 | |
31 | 31 | #pragma pack(pop) /* restore original alignment from stack */ |
32 | 32 | |
33 | -static bool compareTransitions(TransitionData t1, TransitionData t2) { | |
34 | - return t1.label < t2.label; | |
35 | -} | |
33 | +//static bool compareTransitions(TransitionData t1, TransitionData t2) { | |
34 | +// return t1.label < t2.label; | |
35 | +//} | |
36 | 36 | |
37 | 37 | template <class T> |
38 | 38 | SimpleFSA<T>::SimpleFSA(const unsigned char* ptr, const Deserializer<T>& deserializer) |
... | ... | @@ -44,23 +44,32 @@ SimpleFSA<T>::~SimpleFSA() { |
44 | 44 | |
45 | 45 | } |
46 | 46 | |
47 | -static void debugState(const StateData* stateData) { | |
48 | - cerr << "STATE" << endl; | |
49 | - cerr << stateData->transitionsNum << " " << stateData->accepting << endl; | |
50 | -} | |
51 | - | |
52 | -static void debugTransitions(const TransitionData* transitionsTable, const TransitionData* transitionsEnd) { | |
53 | - int offset = 0; | |
54 | - cerr << "TRANSITIONS" << endl; | |
55 | - while (transitionsTable + offset < transitionsEnd) { | |
56 | - const TransitionData td = *(transitionsTable + offset); | |
57 | - if ((td.label <= 'z' && 'a' <= td.label)) | |
58 | - cerr << td.label << " " << td.targetOffset << endl; | |
59 | - else { | |
60 | - cerr << ((int) td.label) << " " << td.targetOffset << endl; | |
47 | +//static void debugState(const StateData* stateData) { | |
48 | +// cerr << "STATE" << endl; | |
49 | +// cerr << stateData->transitionsNum << " " << stateData->accepting << endl; | |
50 | +//} | |
51 | +// | |
52 | +//static void debugTransitions(const TransitionData* transitionsTable, const TransitionData* transitionsEnd) { | |
53 | +// int offset = 0; | |
54 | +// cerr << "TRANSITIONS" << endl; | |
55 | +// while (transitionsTable + offset < transitionsEnd) { | |
56 | +// const TransitionData td = *(transitionsTable + offset); | |
57 | +// if ((td.label <= 'z' && 'a' <= td.label)) | |
58 | +// cerr << td.label << " " << td.targetOffset << endl; | |
59 | +// else { | |
60 | +// cerr << ((int) td.label) << " " << td.targetOffset << endl; | |
61 | +// } | |
62 | +// offset++; | |
63 | +// } | |
64 | +//} | |
65 | + | |
66 | +static inline const TransitionData* findTransition(const TransitionData* start, const TransitionData* end, const char c) { | |
67 | + for (const TransitionData* td = start; td != end; td++) { | |
68 | + if (td->label == c) { | |
69 | + return td; | |
61 | 70 | } |
62 | - offset++; | |
63 | 71 | } |
72 | + return end; | |
64 | 73 | } |
65 | 74 | |
66 | 75 | template <class T> |
... | ... | @@ -75,14 +84,10 @@ void SimpleFSA<T>::proceedToNext(const char c, State<T>& state) const { |
75 | 84 | transitionsTableOffset += state.getValueSize(); |
76 | 85 | // cerr << "transitionsTableOffset " << transitionsTableOffset + state.getOffset() << " because value is " << state.getValue() << endl; |
77 | 86 | } |
78 | - const StateData* stateData = reinterpret_cast<const StateData*> (fromPointer); | |
79 | - const TransitionData* transitionsTable = reinterpret_cast<const TransitionData*> (fromPointer + transitionsTableOffset); | |
80 | - const TransitionData* transitionsEnd = transitionsTable + stateData->transitionsNum; | |
81 | -// debugState(stateData); | |
82 | -// debugTransitions(transitionsTable, transitionsEnd); | |
83 | - const TransitionData* foundTransition = std::lower_bound( | |
84 | - transitionsTable, transitionsEnd, | |
85 | - TransitionData{c, 0}, compareTransitions); | |
87 | + const StateData stateData = *reinterpret_cast<const StateData*> (fromPointer); | |
88 | + const TransitionData* transitionsStart = reinterpret_cast<const TransitionData*> (fromPointer + transitionsTableOffset); | |
89 | + const TransitionData* transitionsEnd = transitionsStart + stateData.transitionsNum; | |
90 | + const TransitionData* foundTransition = findTransition(transitionsStart, transitionsEnd, c); | |
86 | 91 | if (foundTransition == transitionsEnd || foundTransition->label != c) { |
87 | 92 | // cerr << "SINK" << (foundTransition == transitionsEnd) << " " << foundTransition->label << " for " << c << endl; |
88 | 93 | state.setNextAsSink(); |
... | ... |
fsa/_state_impl.hpp
... | ... | @@ -30,7 +30,7 @@ bool State<T>::isAccepting() const { |
30 | 30 | |
31 | 31 | template <class T> |
32 | 32 | void State<T>::proceedToNext(const char c) { |
33 | - if (this->isSink()) { | |
33 | + if (this->sink) { | |
34 | 34 | return; |
35 | 35 | } |
36 | 36 | else { |
... | ... | @@ -63,14 +63,14 @@ State<T>::~State() { |
63 | 63 | |
64 | 64 | template <class T> |
65 | 65 | void State<T>::setNext(const unsigned int offset) { |
66 | - assert(!this->isSink()); | |
66 | +// assert(!this->isSink()); | |
67 | 67 | this->offset = offset; |
68 | 68 | this->accepting = false; |
69 | 69 | } |
70 | 70 | |
71 | 71 | template <class T> |
72 | 72 | void State<T>::setNext(const unsigned int offset, const T& value, const unsigned int valueSize) { |
73 | - assert(!this->isSink()); | |
73 | +// assert(!this->isSink()); | |
74 | 74 | this->offset = offset; |
75 | 75 | this->accepting = true; |
76 | 76 | this->value = value; |
... | ... |
fsa/fsa.hpp
... | ... | @@ -87,8 +87,6 @@ private: |
87 | 87 | |
88 | 88 | }; |
89 | 89 | |
90 | -#include "_fsa_impl.hpp" | |
91 | - | |
92 | 90 | /** |
93 | 91 | * A state in an FSA. |
94 | 92 | */ |
... | ... | @@ -143,6 +141,7 @@ private: |
143 | 141 | int valueSize; |
144 | 142 | }; |
145 | 143 | |
144 | +#include "_fsa_impl.hpp" | |
146 | 145 | #include "_state_impl.hpp" |
147 | 146 | |
148 | 147 | #endif /* FSA_HPP */ |
... | ... |
fsa/test_speed.cpp
... | ... | @@ -28,11 +28,12 @@ int main(int argc, char** argv) { |
28 | 28 | string line; |
29 | 29 | while (getline(ifs, line)) { |
30 | 30 | char* val; |
31 | +// cout << line << endl; | |
31 | 32 | if (fsa.tryToRecognize(line.c_str(), val)) { |
32 | 33 | // printf("%s: *OK*\n", line.c_str()); |
33 | 34 | } |
34 | 35 | else { |
35 | -// printf("%s: NOT FOUND", line.c_str()); | |
36 | +// printf("%s: NOT FOUND\n", line.c_str()); | |
36 | 37 | } |
37 | 38 | } |
38 | 39 | return 0; |
... | ... |