This might be faster as an explicit loop where the outgoing character is modulo'd off the accumulated index, the index is multiplied by 26, then the incoming character is added in.
|
char_indices.windows(n) |
|
.map(|w| w.iter().fold(0, |acc, x| 26 * acc + x)) |
|
.map(|i| ngrams[i]) |
|
.sum() |
This might be faster as an explicit loop where the outgoing character is modulo'd off the accumulated index, the index is multiplied by 26, then the incoming character is added in.
ultra/src/fitness.rs
Lines 66 to 69 in 5ac5ef0