lz4hc.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. LZ4 HC - High Compression Mode of LZ4
  3. Header File
  4. Copyright (C) 2011-2014, Yann Collet.
  5. BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
  6. Redistribution and use in source and binary forms, with or without
  7. modification, are permitted provided that the following conditions are
  8. met:
  9. * Redistributions of source code must retain the above copyright
  10. notice, this list of conditions and the following disclaimer.
  11. * Redistributions in binary form must reproduce the above
  12. copyright notice, this list of conditions and the following disclaimer
  13. in the documentation and/or other materials provided with the
  14. distribution.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  16. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  17. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  18. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  19. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  22. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  23. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  25. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. You can contact the author at :
  27. - LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html
  28. - LZ4 source repository : http://code.google.com/p/lz4/
  29. */
  30. #pragma once
  31. #if defined (__cplusplus)
  32. extern "C" {
  33. #endif
  34. int LZ4_compressHC (const char* source, char* dest, int inputSize);
  35. /*
  36. LZ4_compressHC :
  37. return : the number of bytes in compressed buffer dest
  38. or 0 if compression fails.
  39. note : destination buffer must be already allocated.
  40. To avoid any problem, size it to handle worst cases situations (input data not compressible)
  41. Worst case size evaluation is provided by function LZ4_compressBound() (see "lz4.h")
  42. */
  43. int LZ4_compressHC_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize);
  44. /*
  45. LZ4_compress_limitedOutput() :
  46. Compress 'inputSize' bytes from 'source' into an output buffer 'dest' of maximum size 'maxOutputSize'.
  47. If it cannot achieve it, compression will stop, and result of the function will be zero.
  48. This function never writes outside of provided output buffer.
  49. inputSize : Max supported value is 1 GB
  50. maxOutputSize : is maximum allowed size into the destination buffer (which must be already allocated)
  51. return : the number of output bytes written in buffer 'dest'
  52. or 0 if compression fails.
  53. */
  54. int LZ4_compressHC2 (const char* source, char* dest, int inputSize, int compressionLevel);
  55. int LZ4_compressHC2_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
  56. /*
  57. Same functions as above, but with programmable 'compressionLevel'.
  58. Recommended values are between 4 and 9, although any value between 0 and 16 will work.
  59. 'compressionLevel'==0 means use default 'compressionLevel' value.
  60. Values above 16 behave the same as 16.
  61. Equivalent variants exist for all other compression functions below.
  62. */
  63. /* Note :
  64. Decompression functions are provided within LZ4 source code (see "lz4.h") (BSD license)
  65. */
  66. /**************************************
  67. Using an external allocation
  68. **************************************/
  69. int LZ4_sizeofStateHC(void);
  70. int LZ4_compressHC_withStateHC (void* state, const char* source, char* dest, int inputSize);
  71. int LZ4_compressHC_limitedOutput_withStateHC (void* state, const char* source, char* dest, int inputSize, int maxOutputSize);
  72. int LZ4_compressHC2_withStateHC (void* state, const char* source, char* dest, int inputSize, int compressionLevel);
  73. int LZ4_compressHC2_limitedOutput_withStateHC(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
  74. /*
  75. These functions are provided should you prefer to allocate memory for compression tables with your own allocation methods.
  76. To know how much memory must be allocated for the compression tables, use :
  77. int LZ4_sizeofStateHC();
  78. Note that tables must be aligned for pointer (32 or 64 bits), otherwise compression will fail (return code 0).
  79. The allocated memory can be provided to the compression functions using 'void* state' parameter.
  80. LZ4_compress_withStateHC() and LZ4_compress_limitedOutput_withStateHC() are equivalent to previously described functions.
  81. They just use the externally allocated memory for state instead of allocating their own (on stack, or on heap).
  82. */
  83. /**************************************
  84. Experimental Streaming Functions
  85. **************************************/
  86. #define LZ4_STREAMHCSIZE_U64 32774
  87. #define LZ4_STREAMHCSIZE (LZ4_STREAMHCSIZE_U64 * sizeof(unsigned long long))
  88. typedef struct { unsigned long long table[LZ4_STREAMHCSIZE_U64]; } LZ4_streamHC_t;
  89. /*
  90. LZ4_streamHC_t
  91. This structure allows static allocation of LZ4 HC streaming state.
  92. State must then be initialized using LZ4_resetStreamHC() before first use.
  93. Static allocation should only be used with statically linked library.
  94. If you want to use LZ4 as a DLL, please use construction functions below, which are more future-proof.
  95. */
  96. LZ4_streamHC_t* LZ4_createStreamHC(void);
  97. int LZ4_freeStreamHC (LZ4_streamHC_t* LZ4_streamHCPtr);
  98. /*
  99. These functions create and release memory for LZ4 HC streaming state.
  100. Newly created states are already initialized.
  101. Existing state space can be re-used anytime using LZ4_resetStreamHC().
  102. If you use LZ4 as a DLL, please use these functions instead of direct struct allocation,
  103. to avoid size mismatch between different versions.
  104. */
  105. void LZ4_resetStreamHC (LZ4_streamHC_t* LZ4_streamHCPtr, int compressionLevel);
  106. int LZ4_loadDictHC (LZ4_streamHC_t* LZ4_streamHCPtr, const char* dictionary, int dictSize);
  107. int LZ4_compressHC_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize);
  108. int LZ4_compressHC_limitedOutput_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize, int maxOutputSize);
  109. int LZ4_saveDictHC (LZ4_streamHC_t* LZ4_streamHCPtr, char* safeBuffer, int maxDictSize);
  110. /*
  111. These functions compress data in successive blocks of any size, using previous blocks as dictionary.
  112. One key assumption is that each previous block will remain read-accessible while compressing next block.
  113. Before starting compression, state must be properly initialized, using LZ4_resetStreamHC().
  114. A first "fictional block" can then be designated as initial dictionary, using LZ4_loadDictHC() (Optional).
  115. Then, use LZ4_compressHC_continue() or LZ4_compressHC_limitedOutput_continue() to compress each successive block.
  116. They work like usual LZ4_compressHC() or LZ4_compressHC_limitedOutput(), but use previous memory blocks to improve compression.
  117. Previous memory blocks (including initial dictionary when present) must remain accessible and unmodified during compression.
  118. If, for any reason, previous data block can't be preserved in memory during next compression block,
  119. you must save it to a safer memory space,
  120. using LZ4_saveDictHC().
  121. */
  122. /**************************************
  123. * Deprecated Streaming Functions
  124. * ************************************/
  125. /* Note : these streaming functions follows the older model, and should no longer be used */
  126. void* LZ4_createHC (const char* inputBuffer);
  127. char* LZ4_slideInputBufferHC (void* LZ4HC_Data);
  128. int LZ4_freeHC (void* LZ4HC_Data);
  129. int LZ4_compressHC2_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int compressionLevel);
  130. int LZ4_compressHC2_limitedOutput_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
  131. int LZ4_sizeofStreamStateHC(void);
  132. int LZ4_resetStreamStateHC(void* state, const char* inputBuffer);
  133. #if defined (__cplusplus)
  134. }
  135. #endif