SIS
Symmetric Index Structures
/Users/dbr/ma/src/lmu/cis/sis/adapter/ScdawgAdapter.hpp
Go to the documentation of this file.
00001 #ifndef SCDAWGADAPTER_HPP
00002 #define SCDAWGADAPTER_HPP
00003 
00004 #include "../cppbase.hpp"
00005 
00006 #include <iostream>
00007 #include <fstream>
00008 #include <string>
00009 #include <vector>
00010 
00011 #include "CompressedAutomatonAdapter.hpp"
00012 #include "SerializingAutomaton.hpp"
00013 #include "VoidSequenceAdapter.hpp"
00014 
00015 
00016 
00017 namespace lmu { namespace cis { namespace sis {
00018 
00021 class SCDAWGAdapterInterface {
00022     virtual bool delta_left() = 0;
00023     virtual bool delta_right() = 0;
00024 };
00025 
00026 
00027 
00034 
00035 class SCDAWGAdapter
00036     : public virtual CompressedAutomatonAdapter
00037     , public virtual CompressedAutomatonDumpingInterface
00038     , public SerializingAutomaton<SCDAWG>
00039     // , public virtual SCDAWGAdapterInterface
00040 {
00041 protected:
00042     /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00043     /* * * * * * * * * * * *  Members  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00044     /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00045 
00046     SCDAWG*                     C_SCDAWG;               
00047     SCDAWGBuildHelp*            C_SCDAWGBuildHelp;      
00048 
00049 
00050 public:
00051 
00052 
00053     /* unfortunately constructor delegation is not supported by gcc just yet */
00054     // using CompressedAutomatonAdapter::CompressedAutomatonAdapter;
00055 
00056 
00057     /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00058     /* * * * * * * * * * * *  Constructors   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00059     /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00060 
00065     SCDAWGAdapter() : CompressedAutomatonAdapter(1) {
00066         if (DEBUG_LEVEL >= 5) std::cerr << "SCDAWGAdapter::SCDAWGAdapter()" << std::endl;
00067     }
00068 
00076     SCDAWGAdapter(UINT symbolsize)
00077         : C_SCDAWG( SCDAWGInit(symbolsize) )
00078         , C_SCDAWGBuildHelp( SCDAWGBuildHelpInit( this->C_SCDAWG ) )
00079         // , : CompressedAutomatonAdapter( symbolsize )
00080         {
00081             if (DEBUG_LEVEL >= 5) std::cerr << "SCDAWGAdapter::SCDAWGAdapter( UINT symbolSize = " << symbolsize << " )" << std::endl;
00082     }
00083 
00084     virtual inline UINT get_symbol_size() const { return automaton()->data->elementSize; }
00085 
00086     /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00087     /* * * * * * * * * * * *  Destructors  * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00088     /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00089 
00095     virtual ~SCDAWGAdapter() {
00096         if (DEBUG_LEVEL >= 5) std::cerr << "virtual SCDAWGAdapter::~SCDAWGAdapter()" << std::endl;
00097         SCDAWGBuildHelpFree(C_SCDAWGBuildHelp);
00098         // TODO!
00099         // if( tarjanTable ){
00100         //     SCDAWGAddTarjanTable( aut );
00101         // }
00102         SCDAWGFree(C_SCDAWG);
00103     }
00104 
00105 
00106     /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00107     /* * * * * * * * * * * *  Copy-Constructors  * * * * * * * * * * * * * * * * * * * * * * * * * */
00108     /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00109     SCDAWGAdapter( const SCDAWGAdapter& other ) = delete;               
00110     SCDAWGAdapter& operator=( const SCDAWGAdapter& other ) = delete;    
00111 
00112 
00113 
00114     /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00115     /* * * * * * * * * * * *  Methods  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00116     /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00117 
00126     virtual SinkState Add( const VoidSequence * sharpDocumentDollar ) override;
00127 
00128 
00129 
00134     virtual SCDAWG * Read( FILE * fp );
00135     virtual SCDAWG * Read( const S8* fn );  
00136 
00137 
00138 
00146     virtual void Close();
00147 
00148 
00149 
00155     virtual void Shrink();
00156 
00157 
00158 
00164     virtual void Write( FILE * fp );
00165     virtual void Write( const S8* fn );   
00166 
00167 
00168 
00174     virtual void DumpStat( FILE * fp ) const;
00175     virtual void DumpStat( const S8* fn ) const; 
00176 
00177 
00178 
00184     virtual void DumpGV( const S8 * fn, UINT encoding = ENCODING_PLAIN ) const;
00185     
00186 
00187 
00195     void dumpGV(const S8 * fn, UINT encoding) const;
00196     
00197 
00198 
00199 
00205     void DumpGVRight( const S8 * fn, UINT encoding = ENCODING_PLAIN ) const;
00206 
00207 
00208 
00214     virtual void AddTarjanTable();
00215 
00216 
00217 
00223     virtual void GenerateLanguage( const S8* fnOut, UINT encoding = ENCODING_PLAIN ) const;
00224 
00225 
00226 
00232     virtual void SortTransitions();
00233 
00234     // virtual void GenerateLanguage(FILE*, void (*)(FILE*, const VoidSequence*, UINT), UINT) const {
00235 
00236 
00237 
00238 
00245     void BuildSCDAWG( const S8 * fnIn, const S8 * fnOutOutput, UINT bitsPerSymbol = 8, UINT enc = ENCODING_PLAIN, boolean tarjanTable = NO );
00246 
00247 
00248 
00249 protected:
00257     virtual UINT suffixLink( const UINT& state ) const;
00258 
00259 
00260 
00266     virtual CompressedAutomaton* automaton() const;
00267 
00268 
00269 
00275     virtual CompressedAutomaton* left_automaton() const;
00276 
00277 
00278 
00284     virtual PairState GetInitialPairState() const override;
00285 
00286 
00287 
00293     virtual SCDAWGBuildHelp* buildhelp() const;
00294 
00295 
00296 
00302     virtual PairState Delta( const PairState * state, const void * symbol ) const override;
00303 
00304 
00305 
00311     virtual inline CompressedAutomaton* mRight() { return C_SCDAWGBuildHelp->aut->right; }
00312 
00313 
00314 
00320     virtual inline CompressedAutomaton* mLeft() { return C_SCDAWGBuildHelp->aut->left; }
00321 
00322 
00323 
00329     virtual inline SCDAWGBuildHelp* help() { return C_SCDAWGBuildHelp; }
00330 
00331 
00332 
00338     virtual UINT FindRightState( UINT l );
00339 
00340 
00341 
00342 
00348     public: virtual inline UINT printsymbolsize() const { return automaton()->data->elementSize; }
00349 
00350 }; /* End of class SCDAWGAdapter */
00351 
00352 }}} /* End of namespace lmu::cis::sis */
00353 
00354 #endif /* end of include guard: SCDAWGADAPTER_HPP */