Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

dfa_profile.cc

Go to the documentation of this file.
00001 /*
00002  *  File:       dfa_profile.cc
00003  *              $Id: dfa_profile.cc,v 1.1 2002/06/23 23:42:29 alec Exp $
00004  *
00005  *  Author:     Alec Panoviciu (alecu@email.com)
00006  *
00007  *  Comments:
00008  *
00009  *  Revision history:
00010  *
00011  *  $Log: dfa_profile.cc,v $
00012  *  Revision 1.1  2002/06/23 23:42:29  alec
00013  *  profiling based optimization added
00014  *
00015  */
00016 
00017 /* 
00018   Copyright (C) 2002 Alexandru Panoviciu (alecu@email.com)
00019 
00020   This program is free software; you can redistribute it and/or modify
00021   it under the terms of the GNU General Public License as published by
00022   the Free Software Foundation; either version 2 of the License, or
00023   (at your option) any later version.
00024 
00025   This program is distributed in the hope that it will be useful,
00026   but WITHOUT ANY WARRANTY; without even the implied warranty of
00027   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00028   GNU General Public License for more details.
00029 
00030   You should have received a copy of the GNU General Public License
00031   along with this program; if not, write to the Free Software
00032   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00033 
00034  */
00035 
00036 
00037 #include <set>
00038 
00039 #include "dfa_profile.hh"
00040 #include "scanner_dfa_spec.hh"
00041 #include "basic_dfa_spec.hh"
00042 
00043 ScannerDfaProfile::ScannerDfaProfile (ScannerDfaSpec &dfa)
00044 {
00045   for (int i = 0; i < dfa.states.size(); i++)
00046     dfaProfiles.push_back(BasicDfaProfile(*dfa.states[i]));
00047 }
00048 
00049 BasicDfaProfile::BasicDfaProfile (BasicDfaSpec &dfa)
00050 {
00051   for (int i = 0; i < dfa.states.size(); i++)
00052     stateProfiles.push_back(DfaStateProfile(dfa.states[i]));
00053 }
00054 
00055 DfaStateProfile::DfaStateProfile (BasicDfaSpec::State &s)
00056 {
00057   set<unsigned int> toSet;
00058   for (int i = 0; i < s.transitions.size(); i++)
00059     toSet.insert(s.transitions[i].to);
00060   freqs.resize(toSet.size());
00061   for (int i = 0; i < freqs.size(); i++)
00062     freqs[i] = 0;
00063 }
00064   
00065 bool ScannerDfaProfile::read (istream &is)
00066 {
00067   for (int i = 0; i < dfaProfiles.size(); i++)
00068     if (!dfaProfiles[i].read(is))
00069       return false;
00070   return true;
00071 }
00072 
00073 bool BasicDfaProfile::read (istream &is)
00074 {
00075   for (int i = 0; i < stateProfiles.size(); i++)
00076     if (!stateProfiles[i].read(is))
00077       return false;
00078   return true;
00079 }
00080 
00081 
00082 bool DfaStateProfile::read (istream &is)
00083 {
00084   for (int i = 0; i < freqs.size(); i++) {
00085     is >> freqs[i];
00086   }
00087 
00088   return (bool) is;
00089 }
00090 
00091 void ScannerDfaProfile::reset ()
00092 {
00093   for (int i = 0; i < dfaProfiles.size(); i++)
00094     dfaProfiles[i].reset();
00095 }
00096 
00097 void BasicDfaProfile::reset ()
00098 {
00099   for (int i = 0; i < stateProfiles.size(); i++)
00100     stateProfiles[i].reset();
00101 }
00102 
00103 
00104 void DfaStateProfile::reset ()
00105 {
00106   for (int i = 0; i < freqs.size(); i++) {
00107     freqs[i] = 0;;
00108   }
00109 }

Generated at Tue Jul 9 21:05:43 2002 for CppCC by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001