So I have this, relatively easy, problem and wondering if the solution for it already exists.
I have to convert a value from one range to another. If there was just one range, like this:
{-30.0, 30.0} -> {25.0, 50.0}
that would have been easy. But I have a set of ranges:
{-30.0, -20.0} -> {25.0, 30.0}
{-20.0, 0.0} -> {30.0, 40.0}
{ 0.0, 30.0} -> {40.0, 50.0}
One solution is to do a linear search on each access. Another solution is to make the ranges to have equivalent length so that the input value could be directly mapped.
Does anyone know a better than linear search solution? Or if a container that performs this kind of conversion already exist?
Thanks so much.
Aucun commentaire:
Enregistrer un commentaire