refactor: Refactor by integer matching levels in C++
Description
Slightly slower for small factors, three times faster for one hundred million
elements with two million new levels. Three times faster for any n > 1e6.
With NA values, margin is smaller, but still beats base factor.