"Fossies" - the Fresh Open Source Software Archive

Member "lzip-1.22-rc2/fast_encoder.h" (30 Apr 2020, 1853 Bytes) of package /linux/misc/lzip-1.22-rc2.tar.lz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "fast_encoder.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.21_vs_1.22-rc1.

    1 /* Lzip - LZMA lossless data compressor
    2    Copyright (C) 2008-2020 Antonio Diaz Diaz.
    3 
    4    This program is free software: you can redistribute it and/or modify
    5    it under the terms of the GNU General Public License as published by
    6    the Free Software Foundation, either version 2 of the License, or
    7    (at your option) any later version.
    8 
    9    This program is distributed in the hope that it will be useful,
   10    but WITHOUT ANY WARRANTY; without even the implied warranty of
   11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12    GNU General Public License for more details.
   13 
   14    You should have received a copy of the GNU General Public License
   15    along with this program.  If not, see <http://www.gnu.org/licenses/>.
   16 */
   17 
   18 class FLZ_encoder : public LZ_encoder_base
   19   {
   20   unsigned key4;            // key made from latest 4 bytes
   21 
   22   void reset_key4()
   23     {
   24     key4 = 0;
   25     for( int i = 0; i < 3 && i < available_bytes(); ++i )
   26       key4 = ( key4 << 4 ) ^ buffer[i];
   27     }
   28 
   29   int longest_match_len( int * const distance );
   30 
   31   void update_and_move( int n )
   32     {
   33     while( --n >= 0 )
   34       {
   35       if( available_bytes() >= 4 )
   36         {
   37         key4 = ( ( key4 << 4 ) ^ buffer[pos+3] ) & key4_mask;
   38         pos_array[cyclic_pos] = prev_positions[key4];
   39         prev_positions[key4] = pos + 1;
   40         }
   41       move_pos();
   42       }
   43     }
   44 
   45   enum { before_size = 0,
   46          dict_size = 65536,
   47          // bytes to keep in buffer after pos
   48          after_size = max_match_len,
   49          dict_factor = 16,
   50          num_prev_positions23 = 0,
   51          pos_array_factor = 1 };
   52 
   53 public:
   54   FLZ_encoder( const int ifd, const int outfd )
   55     :
   56     LZ_encoder_base( before_size, dict_size, after_size, dict_factor,
   57                      num_prev_positions23, pos_array_factor, ifd, outfd )
   58     {}
   59 
   60   bool encode_member( const unsigned long long member_size );
   61   };