I'm looking for a std::map
-esque data structure optimised for fast lookup .
One approach would be to implement map's interface utilising a sorted std::vector
as the underlying storage - this will offer fast binary_search
thanks to random-access iterators and cache locality.
However, this sounds like reinvention of the wheel. Surely something like this already exists?
Is there an open-source ordered associative data structure which uses a std::vector for storage?
Edit:
In response to the comments suggesting just use std::map - please read here: http://lafstern.org/matt/col1.pdf
The Boost.Containers library has an ordered map container whose storage is backed by a contiguous array called boost::flat_map
. Note however that the asymptotic, theoretic complexity is the same as for the standard map
(logarithmic), and the choice which is better depends on many details of the use case: insertions vs. lookups, iterations, iterator invalidation requirements.
Since the interfaces are very similar, it should be possible to literally replace one by the other via a typedef and profile the relative performances, which is something you absolutely must do.
Is there an open-source ordered associative data structure which uses a std::vector for storage?
How about maintaining a sorted vector
? That way look-up can be fast (binary search, without pointer traversal).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.