-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathencode.rs
executable file
·3071 lines (2952 loc) · 121 KB
/
encode.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#![allow(dead_code)]
use super::hash_to_binary_tree::InitializeH10;
use super::constants::{BROTLI_WINDOW_GAP, BROTLI_CONTEXT_LUT, BROTLI_CONTEXT,
BROTLI_NUM_HISTOGRAM_DISTANCE_SYMBOLS, BROTLI_MAX_NPOSTFIX, BROTLI_MAX_NDIRECT};
use super::backward_references::{BrotliCreateBackwardReferences, Struct1, UnionHasher,
BrotliEncoderParams, BrotliEncoderMode, BrotliHasherParams, H2Sub,
H3Sub, H4Sub, H5Sub, H6Sub, H54Sub, HQ5Sub, HQ7Sub, AdvHasher, BasicHasher, H9,
H9_BUCKET_BITS, H9_BLOCK_SIZE, H9_BLOCK_BITS, H9_NUM_LAST_DISTANCES_TO_CHECK,
AnyHasher, HowPrepared, StoreLookaheadThenStore, AdvHashSpecialization};
use alloc::Allocator;
pub use super::parameters::BrotliEncoderParameter;
use super::combined_alloc::BrotliAlloc;
use super::interface;
use super::bit_cost::{BitsEntropy, ShannonEntropy};
#[allow(unused_imports)]
use super::block_split::BlockSplit;
#[allow(unused_imports)]
use super::brotli_bit_stream::{BrotliBuildAndStoreHuffmanTreeFast, BrotliStoreHuffmanTree,
BrotliStoreMetaBlock, BrotliStoreMetaBlockFast,
BrotliStoreMetaBlockTrivial, BrotliStoreUncompressedMetaBlock,
BrotliWriteEmptyLastMetaBlock,
BrotliWritePaddingMetaBlock, BrotliWriteMetadataMetaBlock,
MetaBlockSplit, RecoderState, JumpToByteBoundary};
use enc::input_pair::InputReferenceMut;
use super::command::{Command, GetLengthCode, BrotliDistanceParams};
use super::compress_fragment::BrotliCompressFragmentFast;
use super::compress_fragment_two_pass::{BrotliCompressFragmentTwoPass, BrotliWriteBits};
#[allow(unused_imports)]
use super::entropy_encode::{BrotliConvertBitDepthsToSymbols, BrotliCreateHuffmanTree, HuffmanTree};
use super::metablock::{BrotliBuildMetaBlock, BrotliBuildMetaBlockGreedy, BrotliOptimizeHistograms, BrotliInitDistanceParams};
use super::static_dict::{BrotliGetDictionary, kNumDistanceCacheEntries};
use super::histogram::{ContextType, HistogramLiteral, HistogramCommand, HistogramDistance, CostAccessors};
use super::super::alloc;
use super::super::alloc::{SliceWrapper, SliceWrapperMut};
use super::utf8_util::BrotliIsMostlyUTF8;
use super::util::{brotli_min_size_t, Log2FloorNonZero};
use core;
//fn BrotliCreateHqZopfliBackwardReferences(m: &mut [MemoryManager],
// dictionary: &[BrotliDictionary],
// num_bytes: usize,
// position: usize,
// ringbuffer: &[u8],
// ringbuffer_mask: usize,
// params: &[BrotliEncoderParams],
// hasher: &mut [u8],
// dist_cache: &mut [i32],
// last_insert_len: &mut [usize],
// commands: &mut [Command],
// num_commands: &mut [usize],
// num_literals: &mut [usize]);
//fn BrotliCreateZopfliBackwardReferences(m: &mut [MemoryManager],
// dictionary: &[BrotliDictionary],
// num_bytes: usize,
// position: usize,
// ringbuffer: &[u8],
// ringbuffer_mask: usize,
// params: &[BrotliEncoderParams],
// hasher: &mut [u8],
// dist_cache: &mut [i32],
// last_insert_len: &mut [usize],
// commands: &mut [Command],
// num_commands: &mut [usize],
// num_literals: &mut [usize]);
//fn BrotliInitBlockSplit(xself: &mut BlockSplit);
//fn BrotliInitMemoryManager(m: &mut [MemoryManager],
// alloc_func: fn(&mut [::std::os::raw::c_void], usize)
// -> *mut ::std::os::raw::c_void,
// free_func: fn(*mut ::std::os::raw::c_void,
// *mut ::std::os::raw::c_void),
// opaque: *mut ::std::os::raw::c_void);
//fn BrotliInitZopfliNodes(array: &mut [ZopfliNode], length: usize);
//fn BrotliWipeOutMemoryManager(m: &mut [MemoryManager]);
static kCompressFragmentTwoPassBlockSize: usize = (1i32 << 17i32) as (usize);
static kMinUTF8Ratio: super::util::floatX = 0.75 as super::util::floatX;
pub struct RingBuffer<AllocU8: alloc::Allocator<u8>> {
pub size_: u32,
pub mask_: u32,
pub tail_size_: u32,
pub total_size_: u32,
pub cur_size_: u32,
pub pos_: u32,
pub data_mo: AllocU8::AllocatedMemory,
pub buffer_index: usize,
}
#[derive(PartialEq, Eq, Copy, Clone)]
#[repr(i32)]
pub enum BrotliEncoderStreamState {
BROTLI_STREAM_PROCESSING = 0,
BROTLI_STREAM_FLUSH_REQUESTED = 1,
BROTLI_STREAM_FINISHED = 2,
BROTLI_STREAM_METADATA_HEAD = 3,
BROTLI_STREAM_METADATA_BODY = 4,
}
#[derive(Clone,Copy,Debug)]
enum NextOut {
DynamicStorage(u32),
TinyBuf(u32),
None,
}
fn GetNextOutInternal<'a>(
next_out :&NextOut,
storage : &'a mut [u8],
tiny_buf : &'a mut [u8;16],
) -> &'a mut[u8]{
match next_out {
&NextOut::DynamicStorage(offset) =>
return &mut storage[offset as usize..],
&NextOut::TinyBuf(offset) =>
return &mut tiny_buf[offset as usize..],
&NextOut::None => &mut [],
}
}
macro_rules! GetNextOut {
($s : expr) => {
GetNextOutInternal(&$s.next_out_,
$s.storage_.slice_mut(),
&mut $s.tiny_buf_)
};
}
fn NextOutIncrement(next_out :&NextOut, inc : i32) -> NextOut{
match next_out {
&NextOut::DynamicStorage(offset) =>
return NextOut::DynamicStorage((offset as i32 + inc) as u32),
&NextOut::TinyBuf(offset) =>
return NextOut::TinyBuf((offset as i32 + inc) as u32),
&NextOut::None => NextOut::None,
}
}
fn IsNextOutNull(next_out :&NextOut) -> bool {
match next_out {
&NextOut::DynamicStorage(_) =>
false,
&NextOut::TinyBuf(_) =>
false,
&NextOut::None => true,
}
}
#[derive(Clone,Copy,Debug)]
pub enum IsFirst {
NothingWritten,
HeaderWritten,
FirstCatableByteWritten,
BothCatableBytesWritten,
}
pub struct BrotliEncoderStateStruct<Alloc: BrotliAlloc>
{
pub params: BrotliEncoderParams,
pub m8: Alloc,
pub hasher_: UnionHasher<Alloc>,
pub input_pos_: u64,
pub ringbuffer_: RingBuffer<Alloc>,
pub cmd_alloc_size_: usize,
pub commands_: <Alloc as Allocator<Command>>::AllocatedMemory, // not sure about this one
pub num_commands_: usize,
pub num_literals_: usize,
pub last_insert_len_: usize,
pub last_flush_pos_: u64,
pub last_processed_pos_: u64,
pub dist_cache_: [i32; 16],
pub saved_dist_cache_: [i32; kNumDistanceCacheEntries],
pub last_bytes_: u16,
pub last_bytes_bits_: u8,
pub prev_byte_: u8,
pub prev_byte2_: u8,
pub storage_size_: usize,
pub storage_: <Alloc as Allocator<u8>>::AllocatedMemory,
pub small_table_: [i32; 1024],
pub large_table_: <Alloc as Allocator<i32>>::AllocatedMemory,
// pub large_table_size_: usize, // <-- get this by doing large_table_.len()
pub cmd_depths_: [u8; 128],
pub cmd_bits_: [u16; 128],
pub cmd_code_: [u8; 512],
pub cmd_code_numbits_: usize,
pub command_buf_: <Alloc as Allocator<u32>>::AllocatedMemory,
pub literal_buf_: <Alloc as Allocator<u8>>::AllocatedMemory,
next_out_: NextOut,
pub available_out_: usize,
pub total_out_: u64,
pub tiny_buf_: [u8; 16],
pub remaining_metadata_bytes_: u32,
pub stream_state_: BrotliEncoderStreamState,
pub is_last_block_emitted_: bool,
pub is_initialized_: bool,
pub is_first_mb: IsFirst,
pub literal_scratch_space: <HistogramLiteral as CostAccessors>::i32vec,
pub command_scratch_space: <HistogramCommand as CostAccessors>::i32vec,
pub distance_scratch_space: <HistogramDistance as CostAccessors>::i32vec,
pub recoder_state: RecoderState,
custom_dictionary: bool,
}
pub fn set_parameter(params: &mut BrotliEncoderParams,
p: BrotliEncoderParameter,
value: u32) -> i32 {
if p as (i32) == BrotliEncoderParameter::BROTLI_PARAM_MODE as (i32) {
params.mode = match value {
0 => BrotliEncoderMode::BROTLI_MODE_GENERIC,
1 => BrotliEncoderMode::BROTLI_MODE_TEXT,
2 => BrotliEncoderMode::BROTLI_MODE_FONT,
3 => BrotliEncoderMode::BROTLI_FORCE_LSB_PRIOR,
4 => BrotliEncoderMode::BROTLI_FORCE_MSB_PRIOR,
5 => BrotliEncoderMode::BROTLI_FORCE_UTF8_PRIOR,
6 => BrotliEncoderMode::BROTLI_FORCE_SIGNED_PRIOR,
_ => BrotliEncoderMode::BROTLI_MODE_GENERIC,
};
return 1i32;
}
if p as (i32) == BrotliEncoderParameter::BROTLI_PARAM_QUALITY as (i32) {
params.quality = value as (i32);
return 1i32;
}
if p as (i32) == BrotliEncoderParameter::BROTLI_PARAM_STRIDE_DETECTION_QUALITY as (i32) {
params.stride_detection_quality = value as (u8);
return 1i32;
}
if p as (i32) == BrotliEncoderParameter::BROTLI_PARAM_HIGH_ENTROPY_DETECTION_QUALITY as (i32) {
params.high_entropy_detection_quality = value as (u8);
return 1i32;
}
if p as (i32) == BrotliEncoderParameter::BROTLI_PARAM_CDF_ADAPTATION_DETECTION as (i32) {
params.cdf_adaptation_detection = value as (u8);
return 1i32;
}
if p as (i32) == BrotliEncoderParameter::BROTLI_PARAM_Q9_5 as (i32) {
params.q9_5 = (value != 0);
return 1i32;
}
if p as (i32) == BrotliEncoderParameter::BROTLI_PARAM_PRIOR_BITMASK_DETECTION as (i32) {
params.prior_bitmask_detection = value as u8;
return 1i32;
}
if p as (i32) == BrotliEncoderParameter::BROTLI_PARAM_SPEED as (i32) {
params.literal_adaptation[1].0 = value as u16;
if params.literal_adaptation[0] == (0,0) {
params.literal_adaptation[0].0 = value as u16;
}
return 1i32;
}
if p as (i32) == BrotliEncoderParameter::BROTLI_PARAM_SPEED_MAX as (i32) {
params.literal_adaptation[1].1 = value as u16;
if params.literal_adaptation[0].1 == 0 {
params.literal_adaptation[0].1 = value as u16;
}
return 1i32;
}
if p as (i32) == BrotliEncoderParameter::BROTLI_PARAM_CM_SPEED as (i32) {
params.literal_adaptation[3].0 = value as u16;
if params.literal_adaptation[2] == (0,0) {
params.literal_adaptation[2].0 = value as u16;
}
return 1i32;
}
if p as (i32) == BrotliEncoderParameter::BROTLI_PARAM_CM_SPEED_MAX as (i32) {
params.literal_adaptation[3].1 = value as u16;
if params.literal_adaptation[2].1 == 0 {
params.literal_adaptation[2].1 = value as u16;
}
return 1i32;
}
if p as (i32) == BrotliEncoderParameter::BROTLI_PARAM_SPEED_LOW as (i32) {
params.literal_adaptation[0].0 = value as u16;
return 1i32;
}
if p as (i32) == BrotliEncoderParameter::BROTLI_PARAM_SPEED_LOW_MAX as (i32) {
params.literal_adaptation[0].1 = value as u16;
return 1i32;
}
if p as (i32) == BrotliEncoderParameter::BROTLI_PARAM_CM_SPEED_LOW as (i32) {
params.literal_adaptation[2].0 = value as u16;
return 1i32;
}
if p as (i32) == BrotliEncoderParameter::BROTLI_PARAM_CM_SPEED_LOW_MAX as (i32) {
params.literal_adaptation[2].1 = value as u16;
return 1i32;
}
if p as (i32) == BrotliEncoderParameter::BROTLI_PARAM_LITERAL_BYTE_SCORE as (i32) {
params.hasher.literal_byte_score = value as i32;
return 1i32;
}
if p as (i32) == BrotliEncoderParameter::BROTLI_METABLOCK_CALLBACK as (i32) {
params.log_meta_block = if value != 0 {true} else {false};
return 1i32;
}
if p as (i32) == BrotliEncoderParameter::BROTLI_PARAM_LGWIN as (i32) {
params.lgwin = value as (i32);
return 1i32;
}
if p as (i32) == BrotliEncoderParameter::BROTLI_PARAM_LGBLOCK as (i32) {
params.lgblock = value as (i32);
return 1i32;
}
if p as (i32) == BrotliEncoderParameter::BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING as (i32) {
if value != 0u32 && (value != 1u32) {
return 0i32;
}
params.disable_literal_context_modeling = if !!!(value == 0) { 1i32 } else { 0i32 };
return 1i32;
}
if p as (i32) == BrotliEncoderParameter::BROTLI_PARAM_SIZE_HINT as (i32) {
params.size_hint = value as (usize);
return 1i32;
}
if p as (i32) == BrotliEncoderParameter::BROTLI_PARAM_LARGE_WINDOW as (i32) {
params.large_window = value != 0;
return 1i32;
}
if p as (i32) == BrotliEncoderParameter::BROTLI_PARAM_AVOID_DISTANCE_PREFIX_SEARCH as (i32) {
params.avoid_distance_prefix_search = value != 0;
return 1i32;
}
if p as (i32) == BrotliEncoderParameter::BROTLI_PARAM_CATABLE as (i32) {
params.catable = value != 0;
if !params.appendable {
params.appendable = value != 0;
}
params.use_dictionary = (value == 0);
return 1i32;
}
if p as (i32) == BrotliEncoderParameter::BROTLI_PARAM_APPENDABLE as (i32) {
params.appendable = value != 0;
return 1i32;
}
if p as (i32) == BrotliEncoderParameter::BROTLI_PARAM_MAGIC_NUMBER as (i32) {
params.magic_number = value != 0;
return 1i32;
}
if p as (i32) == BrotliEncoderParameter::BROTLI_PARAM_FAVOR_EFFICIENCY as (i32) {
params.favor_cpu_efficiency = value != 0;
return 1i32;
}
if p as (i32) == BrotliEncoderParameter::BROTLI_PARAM_BYTE_ALIGN as (i32) {
params.byte_align = value != 0;
return 1i32;
}
if p as (i32) == BrotliEncoderParameter::BROTLI_PARAM_BARE_STREAM as (i32) {
params.bare_stream = value != 0;
if !params.byte_align {
params.byte_align = value != 0;
}
return 1i32;
}
0i32
}
pub fn BrotliEncoderSetParameter<Alloc: BrotliAlloc>
(state: &mut BrotliEncoderStateStruct<Alloc>,
p: BrotliEncoderParameter,
value: u32)
-> i32 {
if (*state).is_initialized_ {
return 0i32;
}
set_parameter(&mut state.params, p, value)
}
/* "Large Window Brotli" */
pub const BROTLI_LARGE_MAX_DISTANCE_BITS: u32 = 62;
pub const BROTLI_LARGE_MIN_WBITS: u32 = 10;
pub const BROTLI_LARGE_MAX_WBITS: u32 = 30;
pub const BROTLI_MAX_DISTANCE_BITS:u32 = 24;
pub const BROTLI_MAX_WINDOW_BITS:usize = BROTLI_MAX_DISTANCE_BITS as usize;
pub const BROTLI_MAX_DISTANCE:usize = 0x3FFFFFC;
pub const BROTLI_MAX_ALLOWED_DISTANCE:usize = 0x7FFFFFC;
pub const BROTLI_NUM_DISTANCE_SHORT_CODES:u32 = 16;
pub fn BROTLI_DISTANCE_ALPHABET_SIZE(NPOSTFIX: u32, NDIRECT:u32, MAXNBITS: u32) -> u32 {
BROTLI_NUM_DISTANCE_SHORT_CODES + (NDIRECT) +
((MAXNBITS) << ((NPOSTFIX) + 1))
}
//#define BROTLI_NUM_DISTANCE_SYMBOLS \
// BROTLI_DISTANCE_ALPHABET_SIZE( \
// BROTLI_MAX_NDIRECT, BROTLI_MAX_NPOSTFIX, BROTLI_LARGE_MAX_DISTANCE_BITS)
pub const BROTLI_NUM_DISTANCE_SYMBOLS:usize = 1128;
pub fn BrotliEncoderInitParams() -> BrotliEncoderParams {
return BrotliEncoderParams {
dist: BrotliDistanceParams {
distance_postfix_bits:0,
num_direct_distance_codes:0,
alphabet_size: BROTLI_DISTANCE_ALPHABET_SIZE(0, 0, BROTLI_MAX_DISTANCE_BITS),
max_distance: BROTLI_MAX_DISTANCE,
},
mode: BrotliEncoderMode::BROTLI_MODE_GENERIC,
log_meta_block: false,
large_window:false,
avoid_distance_prefix_search:false,
quality: 11,
q9_5: false,
lgwin: 22i32,
lgblock: 0i32,
size_hint: 0usize,
disable_literal_context_modeling: 0i32,
stride_detection_quality: 0,
high_entropy_detection_quality: 0,
cdf_adaptation_detection: 0,
prior_bitmask_detection: 0,
literal_adaptation: [(0,0);4],
byte_align: false,
bare_stream: false,
catable: false,
use_dictionary: true,
appendable: false,
magic_number: false,
favor_cpu_efficiency:false,
hasher: BrotliHasherParams {
type_: 6,
block_bits: 9 - 1,
bucket_bits: 15,
hash_len: 5,
num_last_distances_to_check: 16,
literal_byte_score: 0,
},
};
}
fn ExtendLastCommand<Alloc:BrotliAlloc>(
s: &mut BrotliEncoderStateStruct<Alloc>,
bytes: &mut u32,
wrapped_last_processed_pos: &mut u32
) {
let last_command = &mut s.commands_.slice_mut()[s.num_commands_ - 1];
let mask = s.ringbuffer_.mask_;
let max_backward_distance:u64 = (1u64 << s.params.lgwin) - BROTLI_WINDOW_GAP as u64;
let last_copy_len = u64::from(last_command.copy_len_) & 0x1ffffff;
let last_processed_pos:u64 = s.last_processed_pos_ - last_copy_len;
let max_distance:u64 = if last_processed_pos < max_backward_distance {
last_processed_pos
} else {
max_backward_distance
};
let cmd_dist:u64 = s.dist_cache_[0] as u64;
let distance_code:u32 = super::command::CommandRestoreDistanceCode(last_command, &s.params.dist);
if (distance_code < BROTLI_NUM_DISTANCE_SHORT_CODES ||
distance_code as u64 - (BROTLI_NUM_DISTANCE_SHORT_CODES - 1) as u64 == cmd_dist) {
if (cmd_dist <= max_distance) {
while (*bytes != 0 &&
s.ringbuffer_.data_mo.slice()[s.ringbuffer_.buffer_index + (*wrapped_last_processed_pos as usize & mask as usize)] ==
s.ringbuffer_.data_mo.slice()[s.ringbuffer_.buffer_index + (((*wrapped_last_processed_pos as usize).wrapping_sub(cmd_dist as usize)) & mask as usize)]) {
last_command.copy_len_+=1;
(*bytes)-=1;
(*wrapped_last_processed_pos)+=1;
}
}
/* The copy length is at most the metablock size, and thus expressible. */
GetLengthCode(last_command.insert_len_ as usize,
((last_command.copy_len_ & 0x1FFFFFF) as i32 +
(last_command.copy_len_ >> 25) as i32) as usize,
((last_command.dist_prefix_ & 0x3FF) == 0) as i32,
&mut last_command.cmd_prefix_);
}
}
fn RingBufferInit<AllocU8: alloc::Allocator<u8>>() -> RingBuffer<AllocU8> {
return RingBuffer {
size_: 0,
mask_: 0, // 0xff??
tail_size_: 0,
total_size_: 0,
cur_size_: 0,
pos_: 0,
data_mo: AllocU8::AllocatedMemory::default(),
buffer_index: 0usize,
};
}
pub fn BrotliEncoderCreateInstance<Alloc: BrotliAlloc>
(m8: Alloc)
-> BrotliEncoderStateStruct<Alloc> {
let cache: [i32; 16] = [4, 11, 15, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
BrotliEncoderStateStruct::<Alloc> {
params: BrotliEncoderInitParams(),
input_pos_: 0,
num_commands_: 0usize,
num_literals_: 0usize,
last_insert_len_: 0usize,
last_flush_pos_: 0,
last_processed_pos_: 0,
prev_byte_: 0i32 as (u8),
prev_byte2_: 0i32 as (u8),
storage_size_: 0usize,
storage_: <Alloc as Allocator<u8>>::AllocatedMemory::default(),
hasher_: UnionHasher::<Alloc>::default(),
large_table_: <Alloc as Allocator<i32>>::AllocatedMemory::default(),
// large_table_size_: 0usize,
cmd_code_numbits_: 0usize,
command_buf_: <Alloc as Allocator<u32>>::AllocatedMemory::default(),
literal_buf_: <Alloc as Allocator<u8>>::AllocatedMemory::default(),
next_out_: NextOut::None,
available_out_: 0usize,
total_out_: 0u64,
is_first_mb: IsFirst::NothingWritten,
stream_state_: BrotliEncoderStreamState::BROTLI_STREAM_PROCESSING,
is_last_block_emitted_: false,
is_initialized_: false,
ringbuffer_: RingBufferInit(),
commands_: <Alloc as Allocator<Command>>::AllocatedMemory::default(),
cmd_alloc_size_: 0usize,
dist_cache_: cache,
saved_dist_cache_: [cache[0], cache[1], cache[2], cache[3]],
cmd_bits_: [0; 128],
cmd_depths_: [0; 128],
last_bytes_: 0,
last_bytes_bits_: 0,
cmd_code_: [0; 512],
m8: m8,
remaining_metadata_bytes_: 0,
small_table_: [0; 1024],
tiny_buf_: [0; 16],
literal_scratch_space: HistogramLiteral::make_nnz_storage(),
command_scratch_space: HistogramCommand::make_nnz_storage(),
distance_scratch_space: HistogramDistance::make_nnz_storage(),
recoder_state: RecoderState::new(),
custom_dictionary: false,
}
}
fn RingBufferFree<AllocU8: alloc::Allocator<u8>>(m: &mut AllocU8,
rb: &mut RingBuffer<AllocU8>) {
m.free_cell(core::mem::replace(&mut rb.data_mo, AllocU8::AllocatedMemory::default()));
}
fn DestroyHasher<Alloc:alloc::Allocator<u16> + alloc::Allocator<u32>>(
m16: &mut Alloc, handle: &mut UnionHasher<Alloc>){
handle.free(m16);
}
/*
fn DestroyHasher<AllocU16:alloc::Allocator<u16>, AllocU32:alloc::Allocator<u32>>(
m16: &mut AllocU16, m32:&mut AllocU32, handle: &mut UnionHasher<AllocU16, AllocU32>){
match handle {
&mut UnionHasher::H2(ref mut hasher) => {
m32.free_cell(core::mem::replace(&mut hasher.buckets_.buckets_, <Alloc as Allocator<u32>>::AllocatedMemory::default()));
}
&mut UnionHasher::H3(ref mut hasher) => {
m32.free_cell(core::mem::replace(&mut hasher.buckets_.buckets_, <Alloc as Allocator<u32>>::AllocatedMemory::default()));
}
&mut UnionHasher::H4(ref mut hasher) => {
m32.free_cell(core::mem::replace(&mut hasher.buckets_.buckets_, <Alloc as Allocator<u32>>::AllocatedMemory::default()));
}
&mut UnionHasher::H54(ref mut hasher) => {
m32.free_cell(core::mem::replace(&mut hasher.buckets_.buckets_, <Alloc as Allocator<u32>>::AllocatedMemory::default()));
}
&mut UnionHasher::H5(ref mut hasher) => {
m16.free_cell(core::mem::replace(&mut hasher.num, AllocU16::AllocatedMemory::default()));
m32.free_cell(core::mem::replace(&mut hasher.buckets, <Alloc as Allocator<u32>>::AllocatedMemory::default()));
}
&mut UnionHasher::H6(ref mut hasher) => {
m16.free_cell(core::mem::replace(&mut hasher.num, AllocU16::AllocatedMemory::default()));
m32.free_cell(core::mem::replace(&mut hasher.buckets, <Alloc as Allocator<u32>>::AllocatedMemory::default()));
}
&mut UnionHasher::H9(ref mut hasher) => {
m16.free_cell(core::mem::replace(&mut hasher.num_, AllocU16::AllocatedMemory::default()));
m32.free_cell(core::mem::replace(&mut hasher.buckets_, <Alloc as Allocator<u32>>::AllocatedMemory::default()));
}
_ => {}
}
*handle = UnionHasher::<AllocU16, AllocU32>::default();
}
*/
fn BrotliEncoderCleanupState<Alloc:BrotliAlloc>
(s: &mut BrotliEncoderStateStruct<Alloc>) {
{
<Alloc as Allocator<u8>>::free_cell(&mut s.m8, core::mem::replace(&mut (*s).storage_,
<Alloc as Allocator<u8>>::AllocatedMemory::default()));
}
{
<Alloc as Allocator<Command>>::free_cell(&mut s.m8, core::mem::replace(&mut (*s).commands_,
<Alloc as Allocator<Command>>::AllocatedMemory::default()));
}
RingBufferFree(&mut s.m8, &mut (*s).ringbuffer_);
DestroyHasher(&mut s.m8, &mut (*s).hasher_);
{
<Alloc as Allocator<i32>>::free_cell(&mut s.m8, core::mem::replace(&mut (*s).large_table_,
<Alloc as Allocator<i32>>::AllocatedMemory::default()));
}
{
<Alloc as Allocator<u32>>::free_cell(&mut s.m8, core::mem::replace(&mut (*s).command_buf_,
<Alloc as Allocator<u32>>::AllocatedMemory::default()));
}
{
<Alloc as Allocator<u8>>::free_cell(&mut s.m8, core::mem::replace(&mut (*s).literal_buf_, <Alloc as Allocator<u8>>::AllocatedMemory::default()));
}
}
pub fn BrotliEncoderDestroyInstance<Alloc: BrotliAlloc>
(s: &mut BrotliEncoderStateStruct<Alloc>) {
BrotliEncoderCleanupState(s);
}
fn brotli_min_int(a: i32, b: i32) -> i32 {
if a < b { a } else { b }
}
fn brotli_max_int(a: i32, b: i32) -> i32 {
if a > b { a } else { b }
}
#[cfg(not(feature="disallow_large_window_size"))]
fn check_large_window_ok() -> bool {
true
}
#[cfg(feature="disallow_large_window_size")]
fn check_large_window_ok() -> bool {
false
}
pub fn SanitizeParams(params: &mut BrotliEncoderParams) {
(*params).quality = brotli_min_int(11i32, brotli_max_int(0i32, (*params).quality));
if (*params).lgwin < 10i32 {
(*params).lgwin = 10i32;
} else if (*params).lgwin > 24i32 {
if params.large_window && check_large_window_ok() {
if (*params).lgwin > 30i32 {
(*params).lgwin = 30i32;
}
} else {
(*params).lgwin = 24i32;
}
}
if params.catable {
params.appendable = true;
}
if params.bare_stream {
params.byte_align = true;
} else if !params.appendable {
params.byte_align = false;
}
}
fn ComputeLgBlock(params: &BrotliEncoderParams) -> i32 {
let mut lgblock: i32 = (*params).lgblock;
if (*params).quality == 0i32 || (*params).quality == 1i32 {
lgblock = (*params).lgwin;
} else if (*params).quality < 4i32 {
lgblock = 14i32;
} else if lgblock == 0i32 {
lgblock = 16i32;
if (*params).quality >= 9i32 && ((*params).lgwin > lgblock) {
lgblock = brotli_min_int(18i32, (*params).lgwin);
}
} else {
lgblock = brotli_min_int(24i32, brotli_max_int(16i32, lgblock));
}
lgblock
}
fn ComputeRbBits(params: &BrotliEncoderParams) -> i32 {
1i32 + brotli_max_int((*params).lgwin, (*params).lgblock)
}
fn RingBufferSetup<AllocU8: alloc::Allocator<u8>>(params: &BrotliEncoderParams,
rb: &mut RingBuffer<AllocU8>) {
let window_bits: i32 = ComputeRbBits(params);
let tail_bits: i32 = (*params).lgblock;
*(&mut (*rb).size_) = 1u32 << window_bits;
*(&mut (*rb).mask_) = (1u32 << window_bits).wrapping_sub(1u32);
*(&mut (*rb).tail_size_) = 1u32 << tail_bits;
*(&mut (*rb).total_size_) = (*rb).size_.wrapping_add((*rb).tail_size_);
}
fn EncodeWindowBits(lgwin: i32, large_window: bool, last_bytes: &mut u16, last_bytes_bits: &mut u8) {
if large_window {
*last_bytes = (((lgwin & 0x3F) << 8) | 0x11) as u16;
*last_bytes_bits = 14;
} else {
if lgwin == 16i32 {
*last_bytes = 0i32 as (u16);
*last_bytes_bits = 1i32 as (u8);
} else if lgwin == 17i32 {
*last_bytes = 1i32 as (u16);
*last_bytes_bits = 7i32 as (u8);
} else if lgwin > 17i32 {
*last_bytes = (lgwin - 17i32 << 1i32 | 1i32) as (u16);
*last_bytes_bits = 4i32 as (u8);
} else {
*last_bytes = (lgwin - 8i32 << 4i32 | 1i32) as (u16);
*last_bytes_bits = 7i32 as (u8);
}
}
}
fn InitCommandPrefixCodes(cmd_depths: &mut [u8],
cmd_bits: &mut [u16],
cmd_code: &mut [u8],
cmd_code_numbits: &mut usize) {
static kDefaultCommandDepths: [u8; 128] = [
0,4,4,5,6,6,7,7,7,7,7,8,8,8,8,8,0,0,0,4,4,4,4,4,5,5,6,6,6,6,7,7,7,7,
10,10,10,10,10,10,0,4,4,5,5,5,6,6,7,8,8,9,10,10,10,10,10,10,10,10,10,10,10,10,
5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,6,6,6,6,6,5,5,5,5,5,5,4,4,4,4,4,4,4,5,5,5,5,5,5,
6,6,7,7,7,8,10,12,12,12,12,12,12,12,12,12,12,12,12,0,0,0,0];
static kDefaultCommandBits: [u16; 128] = [
0,0,8,9,3,35,7,71,39,103,23,47,175,111,239,31,0,0,0,4,12,2,10,6,13,29,
11,43,27,59,87,55,15,79,319,831,191,703,447,959,0,14,1,25,5,21,19,51,
119,159,95,223,479,991,63,575,127,639,383,895,255,767,511,1023,14,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,27,59,7,39,23,55,30,1,17,9,25,5,0,8,4,12,
2,10,6,21,13,29,3,19,11,15,47,31,95,63,127,255,767,2815,1791,3839,
511,2559,1535,3583,1023,3071,2047,4095,0,0,0,0];
static kDefaultCommandCode: [u8; 57] = [
0xff,0x77,0xd5,0xbf,0xe7,0xde,0xea,0x9e,0x51,0x5d,0xde,0xc6,0x70,0x57,
0xbc,0x58,0x58,0x58,0xd8,0xd8,0x58,0xd5,0xcb,0x8c,0xea,0xe0,0xc3,0x87,
0x1f,0x83,0xc1,0x60,0x1c,0x67,0xb2,0xaa,0x6,0x83,0xc1,0x60,0x30,0x18,
0xcc,0xa1,0xce,0x88,0x54,0x94,0x46,0xe1,0xb0,0xd0,0x4e,0xb2,0xf7,0x4,0x0];
static kDefaultCommandCodeNumBits: usize = 448usize;
cmd_depths[..].clone_from_slice(&kDefaultCommandDepths[..]);
cmd_bits[..].clone_from_slice(&kDefaultCommandBits[..]);
cmd_code[..kDefaultCommandCode.len()].clone_from_slice(&kDefaultCommandCode[..]);
*cmd_code_numbits = kDefaultCommandCodeNumBits;
}
fn EnsureInitialized<Alloc: BrotliAlloc>
(s: &mut BrotliEncoderStateStruct<Alloc>)
-> i32 {
if (*s).is_initialized_ {
return 1i32;
}
SanitizeParams(&mut (*s).params);
(*s).params.lgblock = ComputeLgBlock(&mut (*s).params);
ChooseDistanceParams(&mut s.params);
(*s).remaining_metadata_bytes_ = !(0u32);
RingBufferSetup(&mut (*s).params, &mut (*s).ringbuffer_);
{
let mut lgwin: i32 = (*s).params.lgwin;
if (*s).params.quality == 0i32 || (*s).params.quality == 1i32 {
lgwin = brotli_max_int(lgwin, 18i32);
}
if !((*s).params.catable && (*s).params.bare_stream) {
EncodeWindowBits(lgwin, s.params.large_window, &mut (*s).last_bytes_, &mut (*s).last_bytes_bits_);
}
}
if (*s).params.quality == 0i32 {
InitCommandPrefixCodes(&mut (*s).cmd_depths_[..],
&mut (*s).cmd_bits_[..],
&mut (*s).cmd_code_[..],
&mut (*s).cmd_code_numbits_);
}
if s.params.catable {
// if we want to properly concatenate, then we need to ignore any distances
// this value 0x7ffffff0 was chosen to be larger than max_distance + gap
// but small enough so that +/-3 will not overflow (due to distance modifications)
for item in s.dist_cache_.iter_mut() {
*item = 0x7ffffff0;
}
for item in s.saved_dist_cache_.iter_mut() {
*item = 0x7ffffff0;
}
}
(*s).is_initialized_ = true;
1i32
}
fn RingBufferInitBuffer<AllocU8: alloc::Allocator<u8>>(m: &mut AllocU8,
buflen: u32,
rb: &mut RingBuffer<AllocU8>) {
static kSlackForEightByteHashingEverywhere: usize = 7usize;
let mut new_data =
m.alloc_cell(((2u32).wrapping_add(buflen) as (usize))
.wrapping_add(kSlackForEightByteHashingEverywhere));
let mut i: usize;
if (*rb).data_mo.slice().len() != 0 {
let lim: usize = ((2u32).wrapping_add((*rb).cur_size_) as (usize))
.wrapping_add(kSlackForEightByteHashingEverywhere);
new_data.slice_mut()[..lim].clone_from_slice(&(*rb).data_mo.slice()[..lim]);
m.free_cell(core::mem::replace(&mut (*rb).data_mo, AllocU8::AllocatedMemory::default()));
}
let _ = core::mem::replace(&mut (*rb).data_mo, new_data);
(*rb).cur_size_ = buflen;
(*rb).buffer_index = 2usize;
(*rb).data_mo.slice_mut()[((*rb).buffer_index.wrapping_sub(2usize))] = 0;
(*rb).data_mo.slice_mut()[((*rb).buffer_index.wrapping_sub(1usize))] = 0;
i = 0usize;
while i < kSlackForEightByteHashingEverywhere {
{
(*rb).data_mo.slice_mut()[((*rb)
.buffer_index
.wrapping_add((*rb).cur_size_ as (usize))
.wrapping_add(i) as (usize))] = 0;
}
i = i.wrapping_add(1 as (usize));
}
}
fn RingBufferWriteTail<AllocU8: alloc::Allocator<u8>>(bytes: &[u8],
n: usize,
rb: &mut RingBuffer<AllocU8>) {
let masked_pos: usize = ((*rb).pos_ & (*rb).mask_) as (usize);
if masked_pos < (*rb).tail_size_ as (usize) {
let p: usize = ((*rb).size_ as (usize)).wrapping_add(masked_pos);
let begin = ((*rb).buffer_index.wrapping_add(p) as (usize));
let lim = brotli_min_size_t(n, ((*rb).tail_size_ as (usize)).wrapping_sub(masked_pos));
(*rb).data_mo.slice_mut()[begin..(begin + lim)].clone_from_slice(&bytes[..lim]);
}
}
fn RingBufferWrite<AllocU8: alloc::Allocator<u8>>(m: &mut AllocU8,
bytes: &[u8],
n: usize,
rb: &mut RingBuffer<AllocU8>) {
if (*rb).pos_ == 0u32 && (n < (*rb).tail_size_ as (usize)) {
(*rb).pos_ = n as (u32);
RingBufferInitBuffer(m, (*rb).pos_, rb);
(*rb).data_mo.slice_mut()[((*rb).buffer_index as (usize))..(((*rb).buffer_index as (usize)) + n)]
.clone_from_slice(&bytes[..n]);
return;
}
if (*rb).cur_size_ < (*rb).total_size_ {
RingBufferInitBuffer(m, (*rb).total_size_, rb);
if !(0i32 == 0) {
return;
}
(*rb).data_mo.slice_mut()[((*rb)
.buffer_index
.wrapping_add((*rb).size_ as (usize))
.wrapping_sub(2usize) as (usize))] = 0i32 as (u8);
(*rb).data_mo.slice_mut()[((*rb)
.buffer_index
.wrapping_add((*rb).size_ as (usize))
.wrapping_sub(1usize) as (usize))] = 0i32 as (u8);
}
{
let masked_pos: usize = ((*rb).pos_ & (*rb).mask_) as (usize);
RingBufferWriteTail(bytes, n, rb);
if masked_pos.wrapping_add(n) <= (*rb).size_ as (usize) {
// a single write fits
let start = ((*rb).buffer_index.wrapping_add(masked_pos) as (usize));
(*rb).data_mo.slice_mut()[start..(start + n)].clone_from_slice(&bytes[..n]);
} else {
{
let start = ((*rb).buffer_index.wrapping_add(masked_pos) as (usize));
let mid = brotli_min_size_t(n, ((*rb).total_size_ as (usize)).wrapping_sub(masked_pos));
(*rb).data_mo.slice_mut()[start..(start + mid)].clone_from_slice(&bytes[..mid]);
}
let xstart = ((*rb).buffer_index.wrapping_add(0usize) as (usize));
let size = n.wrapping_sub(((*rb).size_ as (usize)).wrapping_sub(masked_pos));
let bytes_start = (((*rb).size_ as (usize)).wrapping_sub(masked_pos) as (usize));
(*rb).data_mo.slice_mut()[xstart..(xstart + size)].clone_from_slice(&bytes[bytes_start..
(bytes_start +
size)]);
}
}
let data_2 = (*rb).data_mo.slice()[((*rb)
.buffer_index
.wrapping_add((*rb).size_ as (usize))
.wrapping_sub(2usize) as (usize))];
(*rb).data_mo.slice_mut()[((*rb).buffer_index.wrapping_sub(2usize) as (usize))] = data_2;
let data_1 = (*rb).data_mo.slice()[((*rb)
.buffer_index
.wrapping_add((*rb).size_ as (usize))
.wrapping_sub(1usize) as (usize))];
(*rb).data_mo.slice_mut()[((*rb).buffer_index.wrapping_sub(1usize) as (usize))] = data_1;
(*rb).pos_ = (*rb).pos_.wrapping_add(n as (u32));
if (*rb).pos_ > 1u32 << 30i32 {
(*rb).pos_ = (*rb).pos_ & (1u32 << 30i32).wrapping_sub(1u32) | 1u32 << 30i32;
}
}
fn CopyInputToRingBuffer<Alloc: BrotliAlloc>
(s: &mut BrotliEncoderStateStruct<Alloc>,
input_size: usize,
input_buffer: &[u8]) {
if EnsureInitialized(s) == 0 {
return;
}
RingBufferWrite(&mut s.m8, input_buffer, input_size, &mut s.ringbuffer_);
if !(0i32 == 0) {
return;
}
(*s).input_pos_ = (*s).input_pos_.wrapping_add(input_size as u64);
if (s.ringbuffer_).pos_ <= (s.ringbuffer_).mask_ {
let start = ((s.ringbuffer_).buffer_index.wrapping_add((s.ringbuffer_).pos_ as (usize)) as
(usize));
for item in (s.ringbuffer_).data_mo.slice_mut()[start..(start + 7)].iter_mut() {
*item = 0;
}
}
}
fn ChooseHasher(params: &mut BrotliEncoderParams) {
let hparams = &mut params.hasher;
if (*params).quality >= 10 && !params.q9_5{
(*hparams).type_ = 10;
} else if (*params).quality == 10 { // we are using quality 10 as a proxy for "9.5"
(*hparams).type_ = 9;
(*hparams).num_last_distances_to_check = H9_NUM_LAST_DISTANCES_TO_CHECK as i32;
(*hparams).block_bits = H9_BLOCK_BITS as i32;
(*hparams).bucket_bits = H9_BUCKET_BITS as i32;
(*hparams).hash_len = 4;
} else if (*params).quality == 9 {
(*hparams).type_ = 9;
(*hparams).num_last_distances_to_check = H9_NUM_LAST_DISTANCES_TO_CHECK as i32;
(*hparams).block_bits = H9_BLOCK_BITS as i32;
(*hparams).bucket_bits = H9_BUCKET_BITS as i32;
(*hparams).hash_len = 4;
} else if (*params).quality == 4 && ((*params).size_hint >= (1i32 << 20i32) as (usize)) {
(*hparams).type_ = 54i32;
} else if (*params).quality < 5 {
(*hparams).type_ = (*params).quality;
} else if (*params).lgwin <= 16 {
(*hparams).type_ = if (*params).quality < 7 {
40i32
} else if (*params).quality < 9 {
41i32
} else {
42i32
};
} else if ((params.q9_5 && (*params).size_hint > (1usize << 20i32))
|| (*params).size_hint > (1usize << 22i32)) && ((*params).lgwin >= 19i32) {
(*hparams).type_ = 6i32;
(*hparams).block_bits = core::cmp::min((*params).quality - 1, 9);
(*hparams).bucket_bits = 15i32;
(*hparams).hash_len = 5i32;
(*hparams).num_last_distances_to_check = if (*params).quality < 7 {
4i32
} else if (*params).quality < 9 {
10i32
} else {
16i32
};
} else {
(*hparams).type_ = 5i32;
(*hparams).block_bits = core::cmp::min((*params).quality - 1, 9);
(*hparams).bucket_bits = if (*params).quality < 7 && (*params).size_hint <= (1usize << 20i32) {
14i32
} else {
15i32
};
(*hparams).num_last_distances_to_check = if (*params).quality < 7 {
4i32
} else if (*params).quality < 9 {
10i32
} else {
16i32
};
}
}
fn InitializeH2<AllocU32:alloc::Allocator<u32>>(m32: &mut AllocU32, params : &BrotliEncoderParams) -> BasicHasher<H2Sub<AllocU32>> {
BasicHasher {
GetHasherCommon:Struct1{
params:params.hasher,
is_prepared_:1,
dict_num_lookups:0,
dict_num_matches:0,
},
buckets_:H2Sub{buckets_:m32.alloc_cell(65537 + 8)},
h9_opts: super::backward_references::H9Opts::new(¶ms.hasher),
}
}
fn InitializeH3<AllocU32:alloc::Allocator<u32>>(m32: &mut AllocU32, params : &BrotliEncoderParams) -> BasicHasher<H3Sub<AllocU32>> {
BasicHasher {
GetHasherCommon:Struct1{
params:params.hasher,
is_prepared_:1,
dict_num_lookups:0,
dict_num_matches:0,
},
buckets_:H3Sub{buckets_:m32.alloc_cell(65538 + 8)},
h9_opts: super::backward_references::H9Opts::new(¶ms.hasher),
}
}
fn InitializeH4<AllocU32:alloc::Allocator<u32>>(m32: &mut AllocU32, params : &BrotliEncoderParams) -> BasicHasher<H4Sub<AllocU32>> {
BasicHasher {
GetHasherCommon:Struct1{
params:params.hasher,
is_prepared_:1,
dict_num_lookups:0,
dict_num_matches:0,
},
buckets_:H4Sub{buckets_:m32.alloc_cell(131072 + 8)},
h9_opts: super::backward_references::H9Opts::new(¶ms.hasher),
}
}
fn InitializeH54<AllocU32:alloc::Allocator<u32>>(m32: &mut AllocU32, params : &BrotliEncoderParams) -> BasicHasher<H54Sub<AllocU32>> {
BasicHasher {
GetHasherCommon:Struct1{
params:params.hasher,
is_prepared_:1,
dict_num_lookups:0,
dict_num_matches:0,
},
buckets_:H54Sub{buckets_:m32.alloc_cell(1048580 + 8)},
h9_opts: super::backward_references::H9Opts::new(¶ms.hasher),