/// Comparatively simple implementation that can be used as something to compare against in tests pubstruct Naive {
encode_table: [u8; 64],
decode_table: [u8; 256],
config: NaiveConfig,
}
// then leftovers if rem == 2 { let chunk = &input[input_index..input_index + 2];
// high six bits of chunk[0]
output[output_index] = self.encode_table[chunk[0].shr(2) as usize]; // bottom 2 bits of [0], high 4 bits of [1]
output[output_index + 1] = self.encode_table[(chunk[0].shl(4_u8).bitor(chunk[1].shr(4_u8)) as u32)
.bitand(LOW_SIX_BITS) as usize]; // bottom 4 bits of [1], with the 2 bottom bits as zero
output[output_index + 2] = self.encode_table[(chunk[1].shl(2_u8) as u32).bitand(LOW_SIX_BITS) as usize];
output_index += 3;
} elseif rem == 1 { let byte = input[input_index];
output[output_index] = self.encode_table[byte.shr(2) as usize];
output[output_index + 1] = self.encode_table[(byte.shl(4_u8) as u32).bitand(LOW_SIX_BITS) as usize];
output_index += 2;
}
// can only use the main loop on non-trailing chunks if input.len() > Self::DECODE_INPUT_CHUNK_SIZE { // skip the last chunk, whether it's partial or full, since it might // have padding, and start at the beginning of the chunk before that let last_complete_chunk_start_index = estimate.complete_chunk_len
- if estimate.rem == 0 { // Trailing chunk is also full chunk, so there must be at least 2 chunks, and // this won't underflow Self::DECODE_INPUT_CHUNK_SIZE * 2
} else { // Trailing chunk is partial, so it's already excluded in // complete_chunk_len Self::DECODE_INPUT_CHUNK_SIZE
};
pubstruct NaiveEstimate { /// remainder from dividing input by `Naive::DECODE_CHUNK_SIZE`
rem: usize, /// Length of input that is in complete `Naive::DECODE_CHUNK_SIZE`-length chunks
complete_chunk_len: usize,
}
impl NaiveEstimate { fn new(input_len: usize) -> Self { let rem = input_len % Naive::DECODE_INPUT_CHUNK_SIZE; let complete_chunk_len = input_len - rem;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.