summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2014-12-03 14:22:52 -0500
committerAdrian Thurston <thurston@complang.org>2014-12-03 14:22:52 -0500
commit565c3ce507d349bcd3499a39990c2db49b2088a4 (patch)
treeda2f8dfd477b564e8ddb39826fbe78e82dda1c07
parent2188b56deeebb42a5be58bc75cce1e756aabfd39 (diff)
downloadragel-6-interleave.tar.gz
randomized interleavingragel-6-interleave
To get gapiness sorting back, define GAPINESS 1. refs #23
-rw-r--r--ragel/redfsm.cpp57
1 files changed, 31 insertions, 26 deletions
diff --git a/ragel/redfsm.cpp b/ragel/redfsm.cpp
index 775d8fe1..fcbf1ebc 100644
--- a/ragel/redfsm.cpp
+++ b/ragel/redfsm.cpp
@@ -24,9 +24,12 @@
#include "mergesort.h"
#include "ragel.h"
#include <iostream>
+#include <stdlib.h>
#include <sstream>
#include <iomanip>
+#define GAPINESS 0
+
using std::ostringstream;
string GenAction::nameOrLoc()
@@ -358,7 +361,7 @@ void RedFsmAp::postSortInterleave( const char *fsmName )
roll++;
double rollp = 100.0 * ( (double)roll / (double)stateList.length() );
- if ( rollp > thresh ) {
+ if ( rollp > ( GAPINESS ? thresh : 5 ) ) {
next = end;
roll = 0;
@@ -398,32 +401,9 @@ struct CmpGapiness
}
};
-void RedFsmAp::gapinessSort( const char *fsmName )
-{
- int numStates = stateList.length();
- RedStateAp **states = new RedStateAp*[numStates];
-
- int d = 0;
- for ( RedStateList::Iter st = stateList; st.lte(); st++ )
- states[d++] = st;
-
- MergeSort<RedStateAp*, CmpGapiness> gapinessSort;
- gapinessSort.sort( states, stateList.length() );
-
- stateList.abandon();
- for ( int s = 0; s < numStates; s++ )
- stateList.append( states[s] );
-
- delete[] states;
-
- if ( printStatistics ) {
- for ( RedStateList::Iter st = stateList; st.lte(); st++ )
- std::cout << "gapiness-" << fsmName << "\t" << st->gapiness << std::endl;
- }
-}
-
void RedFsmAp::analyzeInterleave( const char *fsmName )
{
+ srand( time( 0 ) );
for ( RedStateList::Iter st = stateList; st.lte(); st++ ) {
unsigned long long span = 0;
long long nondef = 0;
@@ -446,7 +426,7 @@ void RedFsmAp::analyzeInterleave( const char *fsmName )
if ( span > 0 )
gapiness = ( def * 1000 ) / span;
- st->gapiness = gapiness;
+ st->gapiness = GAPINESS ? gapiness : rand();
std::cout << "span-" << fsmName << "\t" << span << "\t" <<
nondef << "\t" << gapiness << "\t" << st->lowKey.getVal() << "\t" <<
@@ -478,6 +458,31 @@ void RedFsmAp::analyzeInterleave( const char *fsmName )
}
}
+void RedFsmAp::gapinessSort( const char *fsmName )
+{
+ int numStates = stateList.length();
+ RedStateAp **states = new RedStateAp*[numStates];
+
+ int d = 0;
+ for ( RedStateList::Iter st = stateList; st.lte(); st++ )
+ states[d++] = st;
+
+ MergeSort<RedStateAp*, CmpGapiness> gapinessSort;
+ gapinessSort.sort( states, stateList.length() );
+
+ stateList.abandon();
+ for ( int s = 0; s < numStates; s++ )
+ stateList.append( states[s] );
+
+ delete[] states;
+
+ if ( printStatistics ) {
+ for ( RedStateList::Iter st = stateList; st.lte(); st++ )
+ std::cout << "gapiness-" << fsmName << "\t" << st->gapiness << std::endl;
+ }
+}
+
+
void RedFsmAp::makeFlat()
{
for ( RedStateList::Iter st = stateList; st.lte(); st++ ) {