SHARE
TWEET

Untitled

a guest Oct 2nd, 2011 447 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. uint* GetMatchesSpec1(
  2.   uint lenLimit, // forward length limit
  3.   uint curMatch, // hash4 pos
  4.   uint pos,
  5.   byte* cur,
  6.   uint* son,
  7.   uint _cyclicBufferPos, uint _cyclicBufferSize,
  8.   uint cutValue,
  9.   uint* distances,
  10.   uint maxLen
  11. ) {
  12.  
  13.   uint* ptr0 = &son[_cyclicBufferPos*2+1];
  14.   uint* ptr1 = &son[_cyclicBufferPos*2+0];
  15.   uint len0 = 0;
  16.   uint len1 = 0;
  17.  
  18.   for(;;) {
  19.     uint delta = pos - curMatch;
  20.  
  21.     if( ((cutValue--)==0) || (delta>=_cyclicBufferSize) ) {
  22.       *ptr0 = *ptr1 = kEmptyHashValue;
  23.       return distances;
  24.     }
  25.  
  26.     // tree node for hashtable's pos
  27.     uint ofs = (_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0));
  28.     uint* pair = son + ofs*2;
  29.  
  30.     byte* pb = cur - delta;
  31.     uint len = Min(len0,len1);
  32.  
  33.     // determine the match len found at hash4 and store
  34.     if( pb[len]==cur[len] ) {
  35.       while( ++len!=lenLimit ) if( pb[len]!=cur[len] ) break;
  36.       if( maxLen<len ) {
  37.         if( distances ) {
  38.           *distances++ = maxLen = len;
  39.           *distances++ = delta-1;
  40.         }
  41.         // stop if max len is reached
  42.         if( len==lenLimit ) {
  43.           // link both branches to the match
  44.           *ptr1 = pair[0];
  45.           *ptr0 = pair[1];
  46.           return distances;
  47.         }
  48.       }
  49.     }
  50.  
  51.     if( pb[len]<cur[len] ) {
  52.       ptr1[0] = curMatch; // curpos less branch would point to curMatch
  53.       ptr1 = &pair[1];  // and less-branch-ptr would point to match's node less branch
  54.       curMatch = ptr1[0];
  55.       len1 = len;
  56.     } else {
  57.       ptr0[0] = curMatch;
  58.       ptr0 = &pair[0];
  59.       curMatch = ptr0[0];
  60.       len0 = len;
  61.     }
  62.  
  63.   } // for
  64. }
  65.  
  66.  
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top