/ rust-bio Public
fix: One Simple Trick to significantly improve the speed and memory usage of Occ #448
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge.
Occ wastes a lot of memory because it reserves memory for all alphabets up to the one with the max rank. Without compression, rank is based on the ASCII value, so this means that a small alphabet like DNA nucleotides would take ~10x more memory than necessary. The FMD index also does not support compressed alphabets, so there is no easy way to sidestep this issue. The fix is simple: transpose the Occ vector so that the first dimension is the alphabet and the second dimension is the sampled Occ values. Then, for characters not in the alphabet, the second dimension can simply be empty, and no space would be wasted. This should massively improve speed and memory usage.
This will need to be rebased after #447 is merged.