Timeline for More efficient way of counting the number of values within an interval?
Current License: CC BY-SA 3.0
9 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
May 23, 2017 at 12:40 | history | edited | CommunityBot |
replaced http://stackoverflow.com/ with https://stackoverflow.com/
|
|
Jan 10, 2014 at 4:10 | comment | added | Jamal | @MichaelUrman: I didn't that floating-point as key values could be problematic, especially with the STL. I'll keep my answer as-is until I can find more information on this. | |
Jan 10, 2014 at 4:00 | comment | added | Michael Urman |
I'm not 100% sure. It's nice to get logarithmic time. Perhaps using map::lower_bound would be enough to not set off alarms, as that will at least avoid creating extra buckets. The advantage over the elegant mathematical approach is you can more easily specify non-uniform ranges.
|
|
Jan 10, 2014 at 3:39 | comment | added | Jamal | @MichaelUrman: I see. Should I make any corrections here, or just remove the parts about the map? | |
Jan 10, 2014 at 3:37 | comment | added | Michael Urman |
std::map<float, int> is setting off all sorts of alarms. Floats are not well-suited to typical equality comparisons. I think the use you show (always literals) is relatively safe, but it's not far from one that calculates the bound through some sort of rounding, and falls prey to floating point inaccuracy. Consider whether 0.1 * 3 == 0.3 .
|
|
Jan 9, 2014 at 19:12 | history | edited | Jamal | CC BY-SA 3.0 |
added 239 characters in body
|
Jan 9, 2014 at 19:06 | comment | added | Jamal | @amon: True. I'm showing this as an example using these loops. Feel free to add an answer about that. | |
Jan 9, 2014 at 19:00 | comment | added | amon |
The next step would then be to create a vector of upper limits for each bin and iterate over that instead of manually unrolling the loop into this endless if...else if cascade.
|
|
Jan 9, 2014 at 18:23 | history | answered | Jamal | CC BY-SA 3.0 |