@@ -65,7 +65,7 @@ impl BitPacker {
65
65
66
66
#[ derive( Clone , Debug , Default , Copy ) ]
67
67
pub struct BitUnpacker {
68
- num_bits : u32 ,
68
+ num_bits : usize ,
69
69
mask : u64 ,
70
70
}
71
71
@@ -83,7 +83,7 @@ impl BitUnpacker {
83
83
( 1u64 << num_bits) - 1u64
84
84
} ;
85
85
BitUnpacker {
86
- num_bits : u32 :: from ( num_bits) ,
86
+ num_bits : usize :: from ( num_bits) ,
87
87
mask,
88
88
}
89
89
}
@@ -94,7 +94,7 @@ impl BitUnpacker {
94
94
95
95
#[ inline]
96
96
pub fn get ( & self , idx : u32 , data : & [ u8 ] ) -> u64 {
97
- let addr_in_bits = idx as usize * self . num_bits as usize ;
97
+ let addr_in_bits = idx as usize * self . num_bits ;
98
98
let addr = addr_in_bits >> 3 ;
99
99
if addr + 8 > data. len ( ) {
100
100
if self . num_bits == 0 {
@@ -129,24 +129,25 @@ impl BitUnpacker {
129
129
//
130
130
// This methods panics if `num_bits` is > 32.
131
131
fn get_batch_u32s ( & self , start_idx : u32 , data : & [ u8 ] , output : & mut [ u32 ] ) {
132
+ let start_idx = start_idx as usize ;
132
133
assert ! (
133
134
self . bit_width( ) <= 32 ,
134
135
"Bitwidth must be <= 32 to use this method."
135
136
) ;
136
137
137
- let end_idx = start_idx + output. len ( ) as u32 ;
138
+ let end_idx = start_idx + output. len ( ) ;
138
139
139
140
let end_bit_read = end_idx * self . num_bits ;
140
141
let end_byte_read = ( end_bit_read + 7 ) / 8 ;
141
142
assert ! (
142
- end_byte_read as usize <= data. len( ) ,
143
+ end_byte_read <= data. len( ) ,
143
144
"Requested index is out of bounds."
144
145
) ;
145
146
146
147
// Simple slow implementation of get_batch_u32s, to deal with our ramps.
147
- let get_batch_ramp = |start_idx : u32 , output : & mut [ u32 ] | {
148
+ let get_batch_ramp = |start_idx : usize , output : & mut [ u32 ] | {
148
149
for ( out, idx) in output. iter_mut ( ) . zip ( start_idx..) {
149
- * out = self . get ( idx, data) as u32 ;
150
+ * out = self . get ( idx as u32 , data) as u32 ;
150
151
}
151
152
} ;
152
153
@@ -161,23 +162,23 @@ impl BitUnpacker {
161
162
// so highway start is the closest multiple of 8 that is >= start_idx.
162
163
let entrance_ramp_len = 8 - ( start_idx % 8 ) % 8 ;
163
164
164
- let highway_start: u32 = start_idx + entrance_ramp_len;
165
+ let highway_start: usize = start_idx + entrance_ramp_len;
165
166
166
- if highway_start + BitPacker1x :: BLOCK_LEN as u32 > end_idx {
167
+ if highway_start + BitPacker1x :: BLOCK_LEN > end_idx {
167
168
// We don't have enough values to have even a single block of highway.
168
169
// Let's just supply the values the simple way.
169
170
get_batch_ramp ( start_idx, output) ;
170
171
return ;
171
172
}
172
173
173
- let num_blocks: u32 = ( end_idx - highway_start) / BitPacker1x :: BLOCK_LEN as u32 ;
174
+ let num_blocks: usize = ( end_idx - highway_start) / BitPacker1x :: BLOCK_LEN ;
174
175
175
176
// Entrance ramp
176
- get_batch_ramp ( start_idx, & mut output[ ..entrance_ramp_len as usize ] ) ;
177
+ get_batch_ramp ( start_idx, & mut output[ ..entrance_ramp_len] ) ;
177
178
178
179
// Highway
179
- let mut offset = ( highway_start * self . num_bits ) as usize / 8 ;
180
- let mut output_cursor = ( highway_start - start_idx) as usize ;
180
+ let mut offset = ( highway_start * self . num_bits ) / 8 ;
181
+ let mut output_cursor = highway_start - start_idx;
181
182
for _ in 0 ..num_blocks {
182
183
offset += BitPacker1x . decompress (
183
184
& data[ offset..] ,
@@ -188,7 +189,7 @@ impl BitUnpacker {
188
189
}
189
190
190
191
// Exit ramp
191
- let highway_end = highway_start + num_blocks * BitPacker1x :: BLOCK_LEN as u32 ;
192
+ let highway_end = highway_start + num_blocks * BitPacker1x :: BLOCK_LEN ;
192
193
get_batch_ramp ( highway_end, & mut output[ output_cursor..] ) ;
193
194
}
194
195
0 commit comments