Would it be worthwhile to use a direct lookup if the array is sufficiently dense? I.e., base it on the ratio between (max(value) - min(value) + 1) and count(values).