oleg-st / ZstdSharp

Port of zstd compression library to c#
MIT License
200 stars 29 forks source link

Request: Support for long distance matching #28

Closed minimalisticMe closed 6 months ago

minimalisticMe commented 6 months ago

Hi,

is it possible to configure usage of long distance matching for compression? I could find it in file https://github.com/oleg-st/ZstdSharp/blob/7dfb8b45862d4eac067a5d6f99b09a23ed521e90/src/ZstdSharp/Unsafe/ZstdLdm.cs#L195 but I don't see how I can configure it. Is there something I am missing out or is it currently not possible to configure for long distance matching?

oleg-st commented 6 months ago

Hi,

you can use compressor.SetParameter(ZSTD_cParameter.ZSTD_c_enableLongDistanceMatching, 1);

minimalisticMe commented 6 months ago

That works, thank you very much, is this enabling long distance matching or is it also possible to set a windows log?

Reference: https://github.com/facebook/zstd/tree/dev/programs

--long[=#]: enable long distance matching with given window log (default: 27)

oleg-st commented 6 months ago

You can use parameters from here: https://facebook.github.io/zstd/zstd_manual.html#Chapter5

ZSTD_c_enableLongDistanceMatching, ZSTD_c_windowLog etc

ZSTD_c_enableLongDistanceMatching=160, / Enable long distance matching. This parameter is designed to improve compression ratio for large inputs, by finding large matches at long distance. It increases memory usage and window size. Note: enabling this parameter increases default ZSTD_c_windowLog to 128 MB except when expressly set to a different value. Note: will be enabled by default if ZSTD_c_windowLog >= 128 MB and compression strategy >= ZSTD_btopt (== compression level 16+) /

minimalisticMe commented 6 months ago

Thank you very much!