finding "best relating key" given pivotal sorted stl container
problem
i have timestamped data, i need hunt formed timestamp method existent timestamp matches quarrel timestamp closest.
preferably should solved stl. boost::* stl::tr1::* (from vs9 featurepack) also possible.
example timestamped data:
struct stimestampeddata
{
time_t m_timestamp; // classification criterion
cdata m_data; // payload
}
approach stl::vector, sort() equal_range()
since map set wholly allows me accurate matches, i don't any offer controlling these.
so i have vector i insert information opening in. before poison i <algorithm>'s sort() supply tradition comparison function.
after i <algorithm>'s equal_range() twin neighbors specified value x.
from twin values i check closest x following i have best match.
while too complex, i awe there some-more glorious solutions this.
maybe stl already an algorithm does accurately i'm re-inventing something here?
update: linear vs. binary search
i forgot plead i have definitely lot information hoop i don't wish have hunt linearly.
the reason i am classification settlement sort() since futile opening iterators box map. controlling map grant equal_range() hunt twice logarithmic complexity.
am i correct?
Comments
Post a Comment