jpreprocess_dictionary/
word_data.rs1pub fn get_word_data<'a>(idx: &[u8], data: &'a [u8], word_id: Option<usize>) -> Option<&'a [u8]> {
2 let get_idx = |word_id: usize| -> Option<usize> {
3 if word_id * 4 + 4 > idx.len() {
4 return None;
5 }
6 Some(u32::from_le_bytes([
7 idx[word_id * 4],
8 idx[word_id * 4 + 1],
9 idx[word_id * 4 + 2],
10 idx[word_id * 4 + 3],
11 ]) as usize)
12 };
13
14 let start = get_idx(word_id.unwrap_or(0))?;
15 let end = get_idx(word_id.unwrap_or(0) + 1).unwrap_or(data.len());
16
17 let range = if word_id.is_some() {
18 start..end
19 } else {
20 0..start
21 };
22
23 if range.end <= data.len() {
24 Some(&data[range])
25 } else {
26 None
27 }
28}