| 673 | /// as it eliminates the conditional `Iterator::next` |
| 674 | #[inline] |
| 675 | pub fn collect_bool<F: FnMut(usize) -> bool>(len: usize, mut f: F) -> Self { |
| 676 | let mut buffer: Vec<u64> = Vec::with_capacity(bit_util::ceil(len, 64)); |
| 677 | |
| 678 | let chunks = len / 64; |
| 679 | let remainder = len % 64; |
| 680 | buffer.extend((0..chunks).map(|chunk| { |
| 681 | let mut packed = 0; |
| 682 | for bit_idx in 0..64 { |
| 683 | let i = bit_idx + chunk * 64; |
| 684 | packed |= (f(i) as u64) << bit_idx; |
| 685 | } |
| 686 | |
| 687 | packed |
| 688 | })); |
| 689 | |
| 690 | if remainder != 0 { |
| 691 | let mut packed = 0; |
| 692 | for bit_idx in 0..remainder { |
| 693 | let i = bit_idx + chunks * 64; |
| 694 | packed |= (f(i) as u64) << bit_idx; |
| 695 | } |
| 696 | |
| 697 | buffer.push(packed) |
| 698 | } |
| 699 | |
| 700 | let mut buffer: MutableBuffer = buffer.into(); |
| 701 | buffer.truncate(bit_util::ceil(len, 8)); |
| 702 | buffer |
| 703 | } |
| 704 | |
| 705 | /// Extends this buffer with boolean values. |
| 706 | /// |