00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef __UT_FSA__
00027 #define __UT_FSA__
00028
00029 #include "UT_API.h"
00030 #include <SYS/SYS_Types.h>
00031
00032 class UT_StringArray;
00033 class UT_IntArray;
00034 class UT_WorkBuffer;
00035 class ut_fsa_node;
00036
00037 class UT_API ut_FSA_Token {
00038 public:
00039 ut_FSA_Token(int id=0, const char *token=0)
00040 {
00041 myId = id;
00042 myToken = token;
00043 }
00044 ~ut_FSA_Token() { }
00045
00046 void set(int id, const char *token)
00047 {
00048 myToken = token;
00049 myId = id;
00050 }
00051 int getId() const { return myId; }
00052 const char *getToken() const { return myToken; }
00053 private:
00054 const char *myToken;
00055 int myId;
00056 };
00057
00058 class UT_API UT_FSA {
00059 public:
00060 UT_FSA();
00061 ~UT_FSA();
00062
00063 bool build(const UT_StringArray &strings, const UT_IntArray &indices,
00064 int notfound_index = -1);
00065 bool build(int ntokens, const ut_FSA_Token tokens[],
00066 int notfound_index=-1);
00067 void clear();
00068
00069 int findSymbol(const char *symbol) const;
00070 int getNotFound() const { return myNotFound; }
00071
00072 int64 getMemUsage() const;
00073
00074 void dumpTables() const;
00075
00076
00077
00078 void extractStrings(UT_StringArray &list) const;
00079
00080 private:
00081 void resolveTree(ut_fsa_node *head);
00082
00083 int *myAccept;
00084 int *myNexts;
00085 int *myValidate;
00086 int myNSize, myVSize, myASize;
00087 int myNotFound;
00088 };
00089
00090 #endif