delete [] states;
}
-bool Skeleton::count (SkeletonState * s, uint n, uint & result)
+bool Skeleton::estimate_path_count (SkeletonState * s, uint prefixes, uint & result)
{
if (s->is_end ())
{
- const bool overflow = MAX_PATHS - n < result;
+ const bool overflow = MAX_PATHS - prefixes < result;
if (!overflow)
{
- result += n;
+ result += prefixes;
}
return overflow;
}
else if (s->visited < 2)
{
s->visited++;
- for (SkeletonState::go_t::iterator i = s->go.begin (); i != s->go.end (); ++i)
+ bool overflow = false;
+ for (SkeletonState::go_t::iterator i = s->go.begin (); !overflow && i != s->go.end (); ++i)
{
- if (count (i->first, i->second.size () * n, result))
- {
- return true;
- }
+ overflow = overflow || estimate_path_count (i->first, i->second.size () * prefixes, result);
}
s->visited--;
- return false;
+ return overflow;
}
else
{
}
}
-void Skeleton::generate_data (std::vector<Path> & results)
+void Skeleton::generate_paths (std::vector<Path> & results)
{
// set paths for final states and default state
// (those with zero outgoing arrows)
void Skeleton::emit_data (DataFile & o)
{
uint result = 0;
- fprintf (stderr, "%d\n", count (states, 1, result));
+ fprintf (stderr, "%d\n", estimate_path_count (states, 1, result));
uint ind = 0;
std::string yyctype;
o.file << indent (ind) << "{\n";
std::vector<Path> ys;
- generate_data (ys);
+ generate_paths (ys);
const uint count = ys.size ();
Skeleton (const DFA & dfa);
~Skeleton ();
- bool count (SkeletonState * s, uint n, uint & result);
- void generate_data (std::vector<Path> & results);
+ bool estimate_path_count (SkeletonState * s, uint prefixes, uint & result);
+ void generate_paths (std::vector<Path> & results);
void emit_data (DataFile & o);
};
-unsigned long count_data (SkeletonState * s, unsigned long count);
void skeleton_emit_prolog (OutputFile & o, uint ind, const char * data_name);
void skeleton_emit_epilog (OutputFile & o, uint ind);
void generate (SkeletonState * s, const std::vector<Path> & prefixes, std::vector<Path> & results);