Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2011
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.08 KB | None | 0 0
  1. enum {
  2.   kMaxValForNormalize=0xFFFFFFFF,
  3.   kNormalizeStepMin = 1<<10, // it must be power of 2
  4.   kNormalizeMask    = ~(kNormalizeStepMin-1)
  5. };
  6.  
  7. void MatchFinder_CheckLimits( uint flag=0 ) {
  8.  
  9.   // reached 4G?
  10.   if( pos==kMaxValForNormalize ) {
  11.     uint subValue = (pos - historySize - 1) & kNormalizeMask;
  12.     uint i;
  13.     uint* items = hash;
  14.     uint numItems = hashSizeSum + numSons;
  15.     for( i=0; i<numItems; i++ ) {
  16.       uint value = items[i];
  17.       value = (value<=subValue) ? kEmptyHashValue : value-subValue;
  18.       items[i] = value;
  19.     }
  20.     posLimit -= subValue;
  21.     pos -= subValue;
  22.     streamPos -= subValue;
  23.   }
  24.  
  25.   if( flag || ((!streamEndWasReached) && (pos+keepSizeAfter==streamPos)) ) {
  26.  
  27.     if( buffer+keepSizeAfter>=bufferBase+blockSize ) {
  28.       memmove( bufferBase, buffer - keepSizeBefore, streamPos+keepSizeBefore - pos );
  29.       buffer = bufferBase + keepSizeBefore;
  30.     }
  31.  
  32.     if( streamEndWasReached==0 ) {
  33.  
  34.       byte* dest = buffer + (streamPos-pos);
  35.       uint  size = bufferBase + blockSize - dest;
  36.  
  37.       if( size>0 ) {
  38.         // here "size" is what we can read max
  39.         chkinp(); // yield if no input
  40.         if( f_quit ) size=0; else {
  41.           uint inplen = getinplen(); // coro has this much input
  42.           size = Min(size,inplen);
  43.           memcpy( dest, (byte*)inpptr, size ); // fetch what we have of input
  44.           inpptr += size; // normally would pointer to inpend now
  45.         }
  46.         if( size==0 ) streamEndWasReached=1;
  47.         streamPos += size;
  48.       }
  49.     }
  50.   }
  51.  
  52.   if( cyclicBufferPos==cyclicBufferSize ) cyclicBufferPos=0;
  53.  
  54.   lenLimit = Min<uint>( matchMaxLen, streamPos - pos );
  55.  
  56.   uint limit = kMaxValForNormalize - pos; // bytes until 4G
  57.  
  58.   uint limit2 = cyclicBufferSize - cyclicBufferPos; // bytes until end of tree buf
  59.   if( limit2<limit ) limit=limit2;
  60.  
  61.   limit2 = streamPos - pos; // bytes until end of stream-keepSizeAfter
  62.   if( limit2<=keepSizeAfter ) {
  63.     if( limit2>0 ) limit2=1;
  64.   } else {
  65.     limit2 -= keepSizeAfter;
  66.   }
  67.   if( limit2<limit ) limit = limit2;
  68.  
  69.   posLimit = pos + limit;
  70. }
  71.  
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement