Commits

Ian....@Montana  committed ab205b2

Some more header file jiu-jitsu to prevent all this inclusion and make the compilation go much faster

  • Participants
  • Parent commits 85a1fe6

Comments (0)

Files changed (6)

File ppmz2/Coder.h

 #pragma once
 
+#include <memory>
 #include "Ppmz2.h"
-#include <memory>
+#include "IntMath.h"
 
 namespace Ppmz2
 {

File ppmz2/LocalOrderEstimation.cpp

 #include "stdafx.h"
-#include "LocalOrderEstimation.h"
+#include "LocalOrderEstimation.h"
+#include "Exclude.h"
+#include "Context.h"
+#include "ContextData.h"
+#include "See.h"
+
+__declspec(dllexport) int Ppmz2::LocalOrderEstimation::ChooseOrder(Ppmz2::LocalOrderEstimation::LOEType loeType, Ppmz2::Context ** contexts, unsigned long cntx, int maxOrder, Ppmz2::Exclude* exc, Ppmz2::See* see, bool useFull)
+{
+    int rating;
+
+    if ( loeType == LOETYPE_NONE )
+        return maxOrder;
+
+    int choseOrder  = 0;
+    int choseRating = 0;
+
+    for(int order = maxOrder; order >= 0; --order)
+    {
+        Context * c;
+        ContextData* cd;
+        int largestCount,totCount,escapeCount;
+        SeeState * ss;
+
+        if ( order == 0 && choseRating == 0 )
+	        return 0; //early out; this is our only choice
+
+        c = contexts[order];
+
+        //if ( ! c || c->full.totSymCount == 0 )
+        if ( ! c || c->_upex._totSymCount == 0 )
+        {
+	        assert( c->_upex._totSymCount == 0 );
+	        continue;
+        }
+
+        //if ( useFull && Context_ChooseFull(c,exc,see,cntx) )
+        //	cd = &(c->full);
+        //else
+	    cd = &(c->_upex);
+        cd->GetExcludedInfo(exc, &totCount, &largestCount, &escapeCount);
+    			        
+        if ( totCount == 0 )
+	        continue;
+
+        assert( largestCount >= 0 );
+
+
+        #ifdef DO_LOE_PENALIZE_NONDET
+        // ask if its det before exclusion or after?
+        //  doesn't seem to make much difference
+        if ( cd->_numSyms > 1 ) // this is before
+        //if ( largestCount != totCount ) // this is after
+        {
+	        totCount += escapeCount;
+        }
+        // note : this makes us a use a different seeState for LOE than we do for coding!
+        #endif
+
+        if ( totCount < escapeCount )
+	        ss = NULL;
+        else
+	        ss = see->GetState(escapeCount, totCount, cntx, order, cd->_numSyms, c);
+
+        //cd->loeSeeState = ss; //(disabled, see codecntx.c)
+
+        if ( loeType == LOETYPE_MPS )
+        {
+			rating = ((See::PPMZ2_IntProb_One - see->GetEscapeP(ss, escapeCount, totCount))
+			            * largestCount ) / totCount;
+        }
+        else 
+        {
+        int MPSP,MPSB;
+
+	        // a little pseudo-entropy
+	        // better on some files
+
+	        // <> todo : track performance of various LOE schemes & make a weighted rating :
+	        //	full_rating = Sum[i] weight(i) * rating(i)
+
+			MPSP = ((See::PPMZ2_IntProb_One - see->GetEscapeP(ss, escapeCount, totCount))
+			            * largestCount ) / totCount;
+
+			assert( MPSP > 0 && MPSP < See::PPMZ2_IntProb_One );
+
+			MPSB = ((See::PPMZ2_IntProb_Shift<<4) - ilog2x16(MPSP)); // = 16 * log(1/MPSP)
+			rating = MPSP * MPSB + ( See::PPMZ2_IntProb_One - MPSP ) * 128;
+	        rating = INT_MAX - rating;
+        }
+
+        if ( rating > choseRating )
+        {
+	        choseRating = rating;
+	        choseOrder = order;
+        }
+    }
+
+    return choseOrder;
+}

File ppmz2/LocalOrderEstimation.h

 #pragma once
 
-#include "Exclude.h"
-#include "Context.h"
-#include "ContextData.h"
-#include "See.h"
-
 #define DO_LOE_PENALIZE_NONDET // yep this helps; it's freaky
-#define PPMZ2_IntProb_Shift	(16)	// making this small hurts compression !!
-#define PPMZ2_IntProb_One	(1UL << PPMZ2_IntProb_Shift)
 
 namespace Ppmz2
 {
+	// Forward defs to reduce header file dependencies
+	class Context;
+	class Exclude;
+	class See;
+
     class LocalOrderEstimation
     {
     public:
 	        LOETYPE_COUNT
         } LOEType;
 
-        static int ChooseOrder(LOEType loeType, Context ** contexts, unsigned long cntx, int maxOrder, Exclude* exc, See* see, bool useFull)
-        {
-            int rating;
-
-	        if ( loeType == LOETYPE_NONE )
-		        return maxOrder;
-
-	        int choseOrder  = 0;
-	        int choseRating = 0;
-
-	        for(int order = maxOrder; order >= 0; --order)
-	        {
-	            Context * c;
-                ContextData* cd;
-	            int largestCount,totCount,escapeCount;
-	            SeeState * ss;
-
-		        if ( order == 0 && choseRating == 0 )
-			        return 0; //early out; this is our only choice
-
-		        c = contexts[order];
-
-		        //if ( ! c || c->full.totSymCount == 0 )
-		        if ( ! c || c->_upex._totSymCount == 0 )
-		        {
-			        assert( c->_upex._totSymCount == 0 );
-			        continue;
-		        }
-
-		        //if ( useFull && Context_ChooseFull(c,exc,see,cntx) )
-		        //	cd = &(c->full);
-		        //else
-			    cd = &(c->_upex);
-                cd->GetExcludedInfo(exc, &totCount, &largestCount, &escapeCount);
-            			        
-		        if ( totCount == 0 )
-			        continue;
-
-		        assert( largestCount >= 0 );
-
-
-		        #ifdef DO_LOE_PENALIZE_NONDET
-		        // ask if its det before exclusion or after?
-		        //  doesn't seem to make much difference
-		        if ( cd->_numSyms > 1 ) // this is before
-		        //if ( largestCount != totCount ) // this is after
-		        {
-			        totCount += escapeCount;
-		        }
-		        // note : this makes us a use a different seeState for LOE than we do for coding!
-		        #endif
-
-		        if ( totCount < escapeCount )
-			        ss = NULL;
-		        else
-			        ss = see->GetState(escapeCount, totCount, cntx, order, cd->_numSyms, c);
-
-		        //cd->loeSeeState = ss; //(disabled, see codecntx.c)
-
-		        if ( loeType == LOETYPE_MPS )
-		        {
-			        rating = ((PPMZ2_IntProb_One - see->GetEscapeP(ss, escapeCount, totCount))
-					            * largestCount ) / totCount;
-		        }
-		        else 
-		        {
-		        int MPSP,MPSB;
-
-			        // a little pseudo-entropy
-			        // better on some files
-
-			        // <> todo : track performance of various LOE schemes & make a weighted rating :
-			        //	full_rating = Sum[i] weight(i) * rating(i)
-
-			        MPSP = ((PPMZ2_IntProb_One - see->GetEscapeP(ss, escapeCount, totCount))
-					            * largestCount ) / totCount;
-
-			        assert( MPSP > 0 && MPSP < PPMZ2_IntProb_One );
-
-			        MPSB = ((PPMZ2_IntProb_Shift<<4) - ilog2x16(MPSP)); // = 16 * log(1/MPSP)
-			        rating = MPSP * MPSB + ( PPMZ2_IntProb_One - MPSP ) * 128;
-			        rating = INT_MAX - rating;
-		        }
-
-		        if ( rating > choseRating )
-		        {
-			        choseRating = rating;
-			        choseOrder = order;
-		        }
-	        }
-
-            return choseOrder;
-        }
+        __declspec(dllexport) static int ChooseOrder(LOEType loeType, Context ** contexts, unsigned long cntx, int maxOrder, Exclude* exc, See* see, bool useFull);		
     };
 }

File ppmz2/PPMZ2.cpp

 		}
 		else
 		{
-	        sym = DecodeFromOrder(contexts, cntx, &useFull, &metrics);
+	        sym = DecodeFromOrder(contexts, cntx, &useFull, &metrics, &codedOrder);
 			metrics.UpdatingTime += Update(contexts, sym, cntx, codedOrder);
         }
 
 		}
 		else
         {
-	        EncodeFromOrder(contexts, sym, cntx, &useFull, &metrics);
+	        int codedOrder = EncodeFromOrder(contexts, sym, cntx, &useFull, &metrics);
 			metrics.UpdatingTime += Update(contexts, sym, cntx, codedOrder);
         }
 
 	return sym;
 }
 
-__declspec(dllexport) void Ppmz2::Ppmz::EncodeFromOrder(Context** contexts, int sym, unsigned long cntx, bool* useFull, CodingMetrics* metrics)
+__declspec(dllexport) int Ppmz2::Ppmz::EncodeFromOrder(Context** contexts, int sym, unsigned long cntx, bool* useFull, CodingMetrics* metrics)
 {
 	Stopwatch timer;
 	// do the initial LOE to pick a start order
 
 	// go down the orders
 
-	for(int order = LOE_Order; ; )
+	int order = LOE_Order;
+	while (true)
 	{
 	    // try to coder from order
 	    
         order = LocalOrderEstimation::ChooseOrder(_loeType, contexts, cntx, order-1, _exclude, _see, useFull);
 	}
 	metrics->CodeFromOrderTime += timer.Elapsed();
+	return order;
 }
 
-__declspec(dllexport) int Ppmz2::Ppmz::DecodeFromOrder(Context** contexts, unsigned long cntx, bool* useFull, CodingMetrics* metrics)
+__declspec(dllexport) int Ppmz2::Ppmz::DecodeFromOrder(Context** contexts, unsigned long cntx, bool* useFull, CodingMetrics* metrics, int* codedOrder)
 {
 	Stopwatch timer;
 	// do the initial LOE to pick a start order
 
 	// go down the orders
 	int sym;
-	for(int order=LOE_Order;;)
+	for(*codedOrder = LOE_Order;;)
 	{
 	    // try to coder from order
 
-	    if ( DecodeFromContext(contexts[order], cntx, &sym, useFull) )
+	    if ( DecodeFromContext(contexts[*codedOrder], cntx, &sym, useFull) )
 	    {
 	        break;
 	    }
     
-	    if ( order == 0 )
+	    if ( *codedOrder == 0 )
 		{
 			sym = DecodeOrderMinusOne(&(metrics->MinusOneOrderTime));
 	        break;
 		}
     		
 	    // maybe skip down a few :
-        order = LocalOrderEstimation::ChooseOrder(_loeType, contexts, cntx, order-1, _exclude, _see, useFull);
+        *codedOrder = LocalOrderEstimation::ChooseOrder(_loeType, contexts, cntx, *codedOrder-1, _exclude, _see, useFull);
 	}
 	metrics->CodeFromOrderTime += timer.Elapsed();
 	return sym;
 
     assert(0); // !! should not get here!
 	return false;
+}
+
+__declspec(dllexport) void Ppmz2::Ppmz::ReInitCoder()
+{
+    // re-init the arithcoder, but keep the model
+    delete _arithInfo;
+    _arithInfo = new ArithInfo();
 }

File ppmz2/PPMZ2.h

         __declspec(dllexport) unsigned int EncodeArraySub(unsigned char* rawBuf, unsigned int rawLen, unsigned char* compBuf);
 		__declspec(dllexport) __int64 EncodeOrderMinusOne(int sym);
 		__declspec(dllexport) __int64 Update(Context** contexts, int sym, unsigned long cntx, int order);
-		__declspec(dllexport) void EncodeFromOrder(Context** contexts, int sym, unsigned long cntx, bool* useFull, CodingMetrics* metrics);
+		__declspec(dllexport) int EncodeFromOrder(Context** contexts, int sym, unsigned long cntx, bool* useFull, CodingMetrics* metrics);
 		__declspec(dllexport) bool DetEncode(unsigned char* rawPtr, unsigned char* rawBuf, int sym, Context** contexts, bool* useFull, __int64* codingTime);
 		__declspec(dllexport) __int64 DetUpdate(unsigned char* rawPtr, unsigned char* rawBuf, int sym);		
 		__declspec(dllexport) int DecodeOrderMinusOne(__int64* minusOneOrderTime);
-		__declspec(dllexport) int DecodeFromOrder(Context** contexts, unsigned long cntx, bool* useFull, CodingMetrics* metrics);		
+		__declspec(dllexport) int DecodeFromOrder(Context** contexts, unsigned long cntx, bool* useFull, CodingMetrics* metrics, int* codedOrder);
 		__declspec(dllexport) bool DetDecode(unsigned char* rawPtr, unsigned char* rawBuf, int* sym, Context** contexts, bool* useFull, __int64* codingTime);
 		__declspec(dllexport) bool DecodeArraySub(unsigned char* rawBuf, unsigned int rawLength, unsigned char* compBuf);
         
-        void ReInitCoder()
-        {            
-	        // re-init the arithcoder, but keep the model
-            delete _arithInfo;
-            _arithInfo = new ArithInfo();
-        }
+        __declspec(dllexport) void ReInitCoder();
+		
         
 		__declspec(dllexport) unsigned int DecodeOrderMinusOneText();
 		__declspec(dllexport) void EncodeOrderMinusOne(unsigned int sym, unsigned int numChars);
         static const unsigned int See_ScaleDown			    = 8000;
         static const unsigned int See_Esc_ScaleDown		    = 500;
         static const unsigned int PPMZ2_IntProb_Shift       = 16;	// making this small hurts compression !!
+		static const unsigned int PPMZ2_IntProb_One	 = (1UL << PPMZ2_IntProb_Shift);
         static const unsigned int See_Init_Scale	        = 7;
         static const unsigned int See_Init_Esc		        = 8;
         static const unsigned int See_Init_Tot		        = 18;