Thanks everybody for reviewing my code. I rewrote almost everything to condense the code and conform to stylistic D usage. My problem is the cast to integral type (line 80), downgrading performances of circa 50%. Is there any possibility to avoid it? Next step will be to implement the range interface as suggested by monarch_dodra.