Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uint* GetMatchesSpec1(
- uint lenLimit, // forward length limit
- uint curMatch, // hash4 pos
- uint pos,
- byte* cur,
- uint* son,
- uint _cyclicBufferPos, uint _cyclicBufferSize,
- uint cutValue,
- uint* distances,
- uint maxLen
- ) {
- uint* ptr0 = &son[_cyclicBufferPos*2+1];
- uint* ptr1 = &son[_cyclicBufferPos*2+0];
- uint len0 = 0;
- uint len1 = 0;
- for(;;) {
- uint delta = pos - curMatch;
- if( ((cutValue--)==0) || (delta>=_cyclicBufferSize) ) {
- *ptr0 = *ptr1 = kEmptyHashValue;
- return distances;
- }
- // tree node for hashtable's pos
- uint ofs = (_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0));
- uint* pair = son + ofs*2;
- byte* pb = cur - delta;
- uint len = Min(len0,len1);
- // determine the match len found at hash4 and store
- if( pb[len]==cur[len] ) {
- while( ++len!=lenLimit ) if( pb[len]!=cur[len] ) break;
- if( maxLen<len ) {
- if( distances ) {
- *distances++ = maxLen = len;
- *distances++ = delta-1;
- }
- // stop if max len is reached
- if( len==lenLimit ) {
- // link both branches to the match
- *ptr1 = pair[0];
- *ptr0 = pair[1];
- return distances;
- }
- }
- }
- if( pb[len]<cur[len] ) {
- ptr1[0] = curMatch; // curpos less branch would point to curMatch
- ptr1 = &pair[1]; // and less-branch-ptr would point to match's node less branch
- curMatch = ptr1[0];
- len1 = len;
- } else {
- ptr0[0] = curMatch;
- ptr0 = &pair[0];
- curMatch = ptr0[0];
- len0 = len;
- }
- } // for
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement