Histogram query: be more efficient

Equivalent, but much more efficient, algorithm.
Merge pull request #609 from uwescience/dhalperi-improve-profiler

Histogram query: be more efficient