@@ -35,7 +35,7 @@ const AMQF_FALSE_POSITIVE_RATE: f64 = 0.01;
3535const KEY_COMPRESSION_DICTIONARY_SIZE : usize = 64 * 1024 - 1 ;
3636/// The maximum bytes that should be selected as key samples to create a compression dictionary
3737const KEY_COMPRESSION_SAMPLES_SIZE : usize = 256 * 1024 ;
38- /// The minimum bytes that should be selected as keys samples. Below that no compression dictionary
38+ /// The minimum bytes that should be selected as key samples. Below that no compression dictionary
3939/// is used.
4040const MIN_KEY_COMPRESSION_SAMPLES_SIZE : usize = 1024 ;
4141/// The bytes that are used per key entry for a sample.
@@ -147,12 +147,10 @@ pub fn write_static_stored_file<E: Entry>(
147147}
148148
149149fn get_compression_buffer_capacity ( total_key_size : usize ) -> usize {
150- let mut size = 0 ;
151- if total_key_size >= MIN_KEY_COMPRESSION_SAMPLES_SIZE {
152- let key_compression_samples_size = min ( KEY_COMPRESSION_SAMPLES_SIZE , total_key_size / 16 ) ;
153- size = key_compression_samples_size;
150+ if total_key_size < MIN_KEY_COMPRESSION_SAMPLES_SIZE {
151+ return 0 ;
154152 }
155- size
153+ min ( KEY_COMPRESSION_SAMPLES_SIZE , total_key_size / 16 )
156154}
157155
158156/// Computes compression dictionaries from keys of all entries
@@ -162,10 +160,11 @@ fn compute_key_compression_dictionary<E: Entry>(
162160 total_key_size : usize ,
163161 buffer : & mut Vec < u8 > ,
164162) -> Result < Vec < u8 > > {
165- if total_key_size < MIN_KEY_COMPRESSION_SAMPLES_SIZE {
163+ let key_compression_samples_size = get_compression_buffer_capacity ( total_key_size) ;
164+ if key_compression_samples_size == 0 {
166165 return Ok ( Vec :: new ( ) ) ;
167166 }
168- let key_compression_samples_size = min ( KEY_COMPRESSION_SAMPLES_SIZE , total_key_size / 16 ) ;
167+
169168 let mut sample_sizes = Vec :: new ( ) ;
170169
171170 // Limit the number of iterations to avoid infinite loops
0 commit comments