REP+SREP plan:
  >2gb files in linux (fseek!)
   static_statbuf!
    inmem    dictsize  h!
  -dl512 by default even with -l4k!?
  -d1g:512:c128 syntax and -mmap support
  inmem.compress: match_dist<Barrier? len<MINLEN1 : len<MINLEN2
     input_match  match -     (  )
                              min_match

  -m1/m2:          dictionary (      CDC,     inmem.compress;         )
  -m3:     2      !!!
       -    thread  bitarr/chunkarr
    m4/m5? -       
  multi-buffer optimization in prepare_block (2 GB/s as in compress_cdc); remix hash bits / use another secondary hash: universal, crc32c...
      -  hash_buffer   prepare+compress   statbuf   compress()
     8 ,    ,   8      ,   8...

compress():
  ? i=1+L*n;     CYCLES    ;    update-then-use (   )?
           -   mark_bitarr
      ,   prefetch,        -   chunkarr prefetching      LOOKAHEAD 
     bitarr prefetching     -   last_match_end    i+L
    ,   hashes1/2        (prefetch-bitarr/prefetch-chunkarr/find_match)     ,
       bitarr/chunkarr    .  (prefetch-chunkarr/find_match),     i+L
  hash1=crc32c, hash2a=hash1+a few bytes -      chunkarr,    hash2b  hasharr (RollingPolynom  l>1k; umac/universal hash )
      hasharr  hash2  b/g thread;        77m*512  2m*64k   hash2 (         )
      hash2 semi-rolling hash (  4   ,   4      ,    update  moveto   )
  hash1=CRC + hash2b=universal ==> zero false positives? reduce digest from 160 to 128 bits? join hasharr with digestarr. -m5: 16-bit hash2 + 8+8 bit I/O accelerator?
    hash2 -  ,   (         - 4%  )
    -hash128..224 (128 x86 default, 160 x64 default)
   LOOKAHEAD=64..1024 (using 1/4-1/8 of 32kb L1 cache)            -a/-l (,     ?    DDR3-1333)
   hash.moveto  if >=8, if >=4, if >=2, if >=1          [] 
   hash.update<N>      2 

misc:
   statbuf[]      -m1/2 (  chunks)  -m3/3f -d- ( match_src)
   i     / : decompression memory, compressed/decompressed=ratio%, matches_count/bytes_occupied_by_matches/%_of_the_compressed_file
       decompression memory   
  L!=2^N: L=k*CYCLES ( ),  blocksize=2^N*L ( )
    digestarr[chunk] may not be filled at all! in particular, for L!=2^n
    put into HashTable chunks split between two input blocks (situation that's almost impossible when L==2^n)
    new  malloc     
   -t        (:     for mode=COMPRESS,DECOMPRESS) {if (mode==COMPRESS or COMPRESS_AND_TEST) ...; if (mode==DECOMPRESS or COMPRESS_AND_TEST) ...;}
  Future-LZ/Index-LZ:      ,        

DictionaryCompressor
    -m0   -m5     hash table
  hashsize = 125-150% of used space + multiple checks + caching of hash bits + prefetching
     Deduplicator(prepare_block,compress_block,memreq,errcode)   DictionaryCompressor<uint32/uint64>  
     compress<uint32/uint64>/prepare<type> to optimize memory usage with dictionaries <4gb
  hash chains for 256-byte chunks  .  + interface Deduplicator
  reimplement REP using interface Deduplicator with choice of compression algos, from CDC to hash-chains
  use Cockoo hashing for DictionaryCompressor::hasharr?

  REP+SREP:
  1. REP-,   
  2.      64-1
  2.1. ,    REP-,   bitarr/chunkarr/hasharr
  2.2.        bitarr/chunkarr/hasharr
  2.3.     ,  

REP+SREP:
    compress()  inmem.compress()
   BUFFERS  (2/3    dictsize;   secondary stats buf  dictsize==0;         stat[i]/header[i]     )
  m5:      I/O      dictsize!    -    h      inmem
  multi-pass, f.e. -m2:l4k+m0:lc64+tempfile+m5:l512
       : hdd-to-hdd compression: 10% of real time spent in disk seeks (see srep-on-slow-HDD)
  m3?/m4/m5 -       

CDC:
  -m1: start hash checking from the first byte of STRIPE (prehash 48 bytes before the stripe if not at the bufstart)
  -m2: 32/size_t bits depending on L (4k/64k), STRIPE=block_size/NumThreads
  move chunkarr into separate classs used both by CDC and non-CDC global-context classes
  5 GB/s: mmap+crc32c(asm)+lock-free queue+Yield+1.25memacces/chunk(use higher chunkarr[] bits for hash)+prefetch+compute splitted VMAC by parts inside worker threads
       vhash (     add_hash)
  min..len..max (  min/max    ?)
   /     hash>maxhash
  allocate startarr[]/digestarr[]/hasharr[], say, in 4mb chunks when required (also useful for -m3..-m5 since it doesn't need large contiguous memory blocks)
  add more entropy to cryptographic_prng besides of clock()
  ? universal   hash  16 ,     
       (  2-4      8-    16 )
   32- hash  chunkarr           (    chunknum,       filesize/L)
    g     -m1/-m2,   (hash1..32+chunknum)+(chunklen+hash128..192)
    add_hash  digest[curchunk],        > total_chunks (      )
  ?stripe=3*5*7*N
rolling crc (*3 to defer data dependencies?):
  pextrb al, xmm0, i
  crc ebx, al
  pextrb cl, xmm0, i
  xor ebx, table[ecx]
  cmp ebx, edx  +  ja large_crc_found

-m3..m5:
  compress<ACCELERATOR=XXX> -     XXX (  XXX=16.    XXX=4)
  smarter -a default / -aX handling depending on L   (-a16/16  16/8  vhd/22g  -l512);  -a2/4 - default?
  -a0/-a1    3.90,     ,    compress() -    512- 
    -a0: 64-bit hash2 only (2*32-bit on x86)
    -a1: 64-bit hash==hash2 (32-bit hash + 32-bit hash2 on x86)
    >1: 2*32-bit hash2  x86
  crc32c  hash1/hash2
  PolynomialRollingHash: hash+a-b*k ==> hash^a^b*k (     )
  hash.moveto: load 16 bytes; shuffle 4 lower bytes into 32-bit subwords of SSE register; pmul by 1,K,K^2,K^3; next 4 bytes mul by K^4,K^5,K^6,K^7...; pmul accum by K^16; add them all together
  CombinedRollingHash<crc,32bit-mul>  x86
  replace sha1 with vhash/cbc-mac(aes) or universal hashing with fortuna-generated key-array
      + prefetch  -  ~20  
      32   512- ,     16  (    -a1,    : 55 /16=3.5 )
       6 / (48 )  bitarr      96  , ..   hasharr - 35 +7 
  hasharr += chunkarr (reduce mem accesses). alternatively: search first in hasharr, indexed by hash+hash2. once hasharr[i]==hash2 found, read chunkarr[i]
    match  sha1        match    10 
     (  ,       4*L,     -      )
  add_hash/mark_match_possibility -   prefetch        L (4% )
         512-   ,     (    -);
          8       ;      **       
  nullify 4 lower bits of chunkarr[] index so that we check 4*16 bytes == cpu cache line (and make sure that chunkarr itself is aligned at 64)
  ?asm bitarr setting so that it uses one asm operation
   -l512/4k/64k  slp+-        L      TLB

-m5:
  incremental SliceHash (i-     32*i )      chunk -       
  SlicedArray classs (use only in win/x86 because x64 doesn't have memory fragmentation and on linux malloc will leave unused bytes - may be we need sbrk?)
  1-bit hash for every L/8 bytes (try incremental hash of 256+32*i bytes) OR try "bit hashtab[32][256]"
  save/try multiple entries with the same 256-byte hash (-hN[x])
  BUFSIZE = 32k/256k/2m (     )
    256- ,      512 ,     256-    chunk       (  false matches)? . update  2013-07-07 00:12
        ""  256..511        :       -  
  overlap (plus m/t to increase I/O Queue Depth?) I/O with computations in -m4/5
  -m3f: reduce memreqs by not storing sha1 hashes in memory, instead saving sha1 hashes of potential matches in the matchstream and checking them on the second pass
  -m3f:   256      ,      
  save potential match bytes (checked by 32-bit hash plus 2*L bytes around) to the tempfiles (one tempfile per each 1/10 of match src range) and check them in second pass
        hash,  match     
  -l512 -c256     false positives:
    dll100 7.072.327 309.211 8.829   dll700 22.443.465 1.444.311 33.207    5g 332.911.300 13.556.124 454.055   lp2 338.343.016 26.385.285 1.447.763
    if (k==saved_k && saved_match_len+(i-saved_i)<MIN_MATCH)   return last_match_end;   -m5 -   

misc:
    >4,   32*32->64,    (int[0]*C)/2+int[1]....
  -f:
    BUG:          ,    
          ,   
  BUG: -m1/-m2/-f (de)compression may place any number of LZ matches per block, not limited to 8mb/L (now patched by using MAX_STATS_PER_BLOCK=blocksize/sizeof(STAT))
      (32-1024 ?)     (64-1024 )     <1024    ?
  like REP, allow to use larger MinMatchLen for small distances.      lzma:64mb :
    -   <64     <4  -      (     !)
    -   <64     >4  - 
    -   >64     >32  - 
  segmentation algorithm: split data into 128 kb blocks, build *full* index on 512-byte chunks, and compute amount of repeated bytes for every pair of blocks
  Cuckoo/Hopscotch hashing:     

REP:
      -     ,       SetDecompressionMem
    1-     1   ,       
   dict   VMAC hashes:    

high-level:
    : io.c+hashes.c+far_matches+near_matches+compress/compress_cdc/decompress+future_lz+main_cycle+cmdline_driver+to-do.txt
  I/O      exit code (      )
   bcj/dispack/lz4/tor/lzma/delta   
  error checking: make all printf in main thread, perform "goto cleanup" instead of error() after file open operations
  use WinAPI to create VMFILE as temporary file not necessarily saved to disk
      ,   VirtualAlloc
  use mmap for uncompressed file and/or keep a few last uncompressed blocks in memory
    mmap      -      ;     ?
     r/w  md5/sha1 (especially important for -m1 w/o -mmap, or I/O-bound situations - i.e. almost any compression on HDD)
   mmap/read/mmap+read,    4   mmap-
  EnvSetConsoleTitle
   -datafile ( -index); -write0s (  datafile    ); -basefile (  ); -non-buffered (   CreateFile)
    ,      ,  ,        

m/t:
  1.  ReadLock   
  2.    .  small_index_head[]
  3.  digestarr(SHA1)  hasharr(rolling hash),   small_index_head[]     . 
  4.  ,    small_index_head[]  full_index,  small_index_head[]
  5.  UpdateLock      full_index with rolling hashes of the block (   )
 -     ,         

  m/t:
  1.    sliding hash        (   ACCELERATOR ).
      ,   8      64 ,    .     
       / -
  2.         -       .
            " " (             )

   ( bitarr,  content-based champions selection):
  1.  crc32c (509 bytes)  4/8/16  (crc32c+3*clmul/8),  prefetch  bitarr,  crc32c  xmm:    1-2 
  2.  .     bitarr,     64-bit hash2(512 bytes)   4-8-16   hasharr (, crc64):
            =  512  = 20-30   100  , .. 1 /1  
  3.  .  (?)    hasharr     hash2,            hash2
  4.      sha1 - aes-based hashing (0.5sec/gb  calc+check,   -   I/O)

  : ,    , ,      ,    
   .  SHA1       (      ),      
     ,            . ,   ,
        L ,        .

 :
        512 ,     "" 256  (  . -)   offset .  
    256-  : chunk (4 bytes) + hash256 (4 bytes) + offset (2-4 bytes) + hash512 (2-4 bytes)
       64-256   "",  hash256   ,     hash512

- :
   K    L,   L-K+1.    C ,      (lb(K)    0  ..).
     bitarr.     bitarr    l-K+1,    .
  ,  32   L-31     -.      16   L-31   .     bitarr  .
      bitarr  (?)   ( .  16     .  32 ).
:
   K     .  max   K/2 ,    K/2   .. -  K/2+1 ,     .
     bitarr.
      max   K/2     bitarr  .
:
    bitarr    K  L-K+1.
     .    K     bitarr.

Further optimizations:
              
          8            ..
            ACCEL       ..: for (i=0..ACCEL-1)  bitarr [hash[j-L+i..j+i]] ~= (1<<i)
        aka: mark_bitarr -  i%CYCLES-   1/2/4../64- , check_bitarr -  ( )    ,       hash2,   
            (     ACCEL    - 15%   -a4)
      ,       (  sha1 mismatches)
