@@ -2832,6 +2832,90 @@ static int basicUnitTests(U32 const seed, double compressibility)
2832
2832
}
2833
2833
DISPLAYLEVEL (3 , "OK \n" );
2834
2834
2835
+ DISPLAYLEVEL (3 , "test%3i : ZSTD_fast attach dictionary with hashLog = 25 and chainLog = 25 : " , testNb ++ );
2836
+ {
2837
+ ZSTD_CCtx_params * cctxParams = ZSTD_createCCtxParams ();
2838
+ ZSTD_customMem customMem = {NULL , NULL , NULL };
2839
+ ZSTD_DCtx * dctx = ZSTD_createDCtx ();
2840
+ ZSTD_CDict * cdict ;
2841
+ CHECK_Z (ZSTD_CCtxParams_setParameter (cctxParams , ZSTD_c_strategy , ZSTD_fast ));
2842
+ /* Set windowLog to 25 so hash/chain logs don't get sized down */
2843
+ CHECK_Z (ZSTD_CCtxParams_setParameter (cctxParams , ZSTD_c_windowLog , 25 ));
2844
+ CHECK_Z (ZSTD_CCtxParams_setParameter (cctxParams , ZSTD_c_hashLog , 25 ));
2845
+ CHECK_Z (ZSTD_CCtxParams_setParameter (cctxParams , ZSTD_c_chainLog , 25 ));
2846
+ /* Set srcSizeHint to 2^25 so hash/chain logs don't get sized down */
2847
+ CHECK_Z (ZSTD_CCtxParams_setParameter (cctxParams , ZSTD_c_srcSizeHint , 1u << 25 ));
2848
+ cdict = ZSTD_createCDict_advanced2 (dictBuffer , dictSize , ZSTD_dlm_byRef , ZSTD_dct_auto , cctxParams , customMem );
2849
+ CHECK_Z (ZSTD_CCtx_reset (cctx , ZSTD_reset_session_and_parameters ));
2850
+ CHECK_Z (ZSTD_CCtx_setParameter (cctx , ZSTD_c_forceAttachDict , ZSTD_dictForceAttach ));
2851
+ CHECK_Z (ZSTD_CCtx_setParameter (cctx , ZSTD_c_checksumFlag , 1 ));
2852
+ CHECK_Z (ZSTD_CCtx_refCDict (cctx , cdict ));
2853
+ cSize = ZSTD_compress2 (cctx , compressedBuffer , compressedBufferSize , CNBuffer , CNBuffSize );
2854
+ CHECK_Z (cSize );
2855
+ CHECK_Z (ZSTD_decompress_usingDict (dctx , decodedBuffer , CNBuffSize , compressedBuffer , cSize , dictBuffer , dictSize ));
2856
+ ZSTD_freeCDict (cdict );
2857
+ ZSTD_freeDCtx (dctx );
2858
+ ZSTD_freeCCtxParams (cctxParams );
2859
+ }
2860
+ DISPLAYLEVEL (3 , "OK \n" );
2861
+
2862
+ DISPLAYLEVEL (3 , "test%3i : ZSTD_dfast attach dictionary with hashLog = 25 and chainLog = 25 : " , testNb ++ );
2863
+ {
2864
+ ZSTD_CCtx_params * cctxParams = ZSTD_createCCtxParams ();
2865
+ ZSTD_customMem customMem = {NULL , NULL , NULL };
2866
+ ZSTD_DCtx * dctx = ZSTD_createDCtx ();
2867
+ ZSTD_CDict * cdict ;
2868
+ CHECK_Z (ZSTD_CCtxParams_setParameter (cctxParams , ZSTD_c_strategy , ZSTD_dfast ));
2869
+ /* Set windowLog to 25 so hash/chain logs don't get sized down */
2870
+ CHECK_Z (ZSTD_CCtxParams_setParameter (cctxParams , ZSTD_c_windowLog , 25 ));
2871
+ CHECK_Z (ZSTD_CCtxParams_setParameter (cctxParams , ZSTD_c_hashLog , 25 ));
2872
+ CHECK_Z (ZSTD_CCtxParams_setParameter (cctxParams , ZSTD_c_chainLog , 25 ));
2873
+ /* Set srcSizeHint to 2^25 so hash/chain logs don't get sized down */
2874
+ CHECK_Z (ZSTD_CCtxParams_setParameter (cctxParams , ZSTD_c_srcSizeHint , 1u << 25 ));
2875
+ cdict = ZSTD_createCDict_advanced2 (dictBuffer , dictSize , ZSTD_dlm_byRef , ZSTD_dct_auto , cctxParams , customMem );
2876
+ CHECK_Z (ZSTD_CCtx_reset (cctx , ZSTD_reset_session_and_parameters ));
2877
+ CHECK_Z (ZSTD_CCtx_setParameter (cctx , ZSTD_c_forceAttachDict , ZSTD_dictForceAttach ));
2878
+ CHECK_Z (ZSTD_CCtx_setParameter (cctx , ZSTD_c_checksumFlag , 1 ));
2879
+ CHECK_Z (ZSTD_CCtx_refCDict (cctx , cdict ));
2880
+ cSize = ZSTD_compress2 (cctx , compressedBuffer , compressedBufferSize , CNBuffer , CNBuffSize );
2881
+ CHECK_Z (cSize );
2882
+ CHECK_Z (ZSTD_decompress_usingDict (dctx , decodedBuffer , CNBuffSize , compressedBuffer , cSize , dictBuffer , dictSize ));
2883
+ ZSTD_freeCDict (cdict );
2884
+ ZSTD_freeDCtx (dctx );
2885
+ ZSTD_freeCCtxParams (cctxParams );
2886
+ }
2887
+ DISPLAYLEVEL (3 , "OK \n" );
2888
+
2889
+ DISPLAYLEVEL (3 , "test%3i : ZSTD_lazy attach dictionary with hashLog = 29 and searchLog = 4 : " , testNb ++ );
2890
+ if (MEM_64bits ()) {
2891
+ ZSTD_CCtx_params * cctxParams = ZSTD_createCCtxParams ();
2892
+ ZSTD_customMem customMem = {NULL , NULL , NULL };
2893
+ ZSTD_DCtx * dctx = ZSTD_createDCtx ();
2894
+ ZSTD_CDict * cdict ;
2895
+ CHECK_Z (ZSTD_CCtxParams_setParameter (cctxParams , ZSTD_c_strategy , ZSTD_lazy ));
2896
+ /* Force enable row based match finder, and disable dedicated dict search. */
2897
+ CHECK_Z (ZSTD_CCtxParams_setParameter (cctxParams , ZSTD_c_useRowMatchFinder , ZSTD_ps_enable ));
2898
+ CHECK_Z (ZSTD_CCtxParams_setParameter (cctxParams , ZSTD_c_enableDedicatedDictSearch , 0 ));
2899
+ CHECK_Z (ZSTD_CCtxParams_setParameter (cctxParams , ZSTD_c_searchLog , 4 ));
2900
+ /* Set windowLog to 29 so hash/chain logs don't get sized down */
2901
+ CHECK_Z (ZSTD_CCtxParams_setParameter (cctxParams , ZSTD_c_windowLog , 29 ));
2902
+ CHECK_Z (ZSTD_CCtxParams_setParameter (cctxParams , ZSTD_c_hashLog , 29 ));
2903
+ /* Set srcSizeHint to 2^29 so hash/chain logs don't get sized down */
2904
+ CHECK_Z (ZSTD_CCtxParams_setParameter (cctxParams , ZSTD_c_srcSizeHint , 1u << 29 ));
2905
+ cdict = ZSTD_createCDict_advanced2 (dictBuffer , dictSize , ZSTD_dlm_byRef , ZSTD_dct_auto , cctxParams , customMem );
2906
+ CHECK_Z (ZSTD_CCtx_reset (cctx , ZSTD_reset_session_and_parameters ));
2907
+ CHECK_Z (ZSTD_CCtx_setParameter (cctx , ZSTD_c_forceAttachDict , ZSTD_dictForceAttach ));
2908
+ CHECK_Z (ZSTD_CCtx_setParameter (cctx , ZSTD_c_checksumFlag , 1 ));
2909
+ CHECK_Z (ZSTD_CCtx_refCDict (cctx , cdict ));
2910
+ cSize = ZSTD_compress2 (cctx , compressedBuffer , compressedBufferSize , CNBuffer , CNBuffSize );
2911
+ CHECK_Z (cSize );
2912
+ CHECK_Z (ZSTD_decompress_usingDict (dctx , decodedBuffer , CNBuffSize , compressedBuffer , cSize , dictBuffer , dictSize ));
2913
+ ZSTD_freeCDict (cdict );
2914
+ ZSTD_freeDCtx (dctx );
2915
+ ZSTD_freeCCtxParams (cctxParams );
2916
+ }
2917
+ DISPLAYLEVEL (3 , "OK \n" );
2918
+
2835
2919
DISPLAYLEVEL (3 , "test%3i : Dictionary with non-default repcodes : " , testNb ++ );
2836
2920
{ U32 u ; for (u = 0 ; u < nbSamples ; u ++ ) samplesSizes [u ] = sampleUnitSize ; }
2837
2921
dictSize = ZDICT_trainFromBuffer (dictBuffer , dictSize ,
0 commit comments