File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -3,20 +3,22 @@ pub type Packed = u8;
3
3
const PACKED_SIZE : usize = Packed :: BITS as usize ;
4
4
5
5
pub const KEYS_COUNT : usize = 374 ;
6
- const PACKED_LEN : usize = {
7
- if KEYS_COUNT % PACKED_SIZE == 0 {
8
- KEYS_COUNT / PACKED_SIZE
6
+ const PACKED_LEN : usize = packed_len ( KEYS_COUNT ) ;
7
+
8
+ const fn packed_len ( bools : usize ) -> usize {
9
+ if bools % PACKED_SIZE == 0 {
10
+ bools / PACKED_SIZE
9
11
} else {
10
- KEYS_COUNT / PACKED_SIZE + 1
12
+ bools / PACKED_SIZE + 1
11
13
}
12
- } ;
14
+ }
13
15
14
16
pub fn empty ( ) -> Vec < Packed > {
15
17
( 0 ..PACKED_LEN ) . map ( |_| 0 ) . collect ( )
16
18
}
17
19
18
20
pub fn pack_bools ( bools : & [ bool ] ) -> Vec < Packed > {
19
- let mut bytes = Vec :: with_capacity ( bools. len ( ) / PACKED_SIZE + 1 ) ;
21
+ let mut bytes = Vec :: with_capacity ( packed_len ( bools. len ( ) ) ) ;
20
22
for chunk in bools. chunks ( PACKED_SIZE ) {
21
23
let mut byte = 0 ;
22
24
for ( i, b) in chunk. iter ( ) . enumerate ( ) {
You can’t perform that action at this time.
0 commit comments