Fastest Data-structure maybe from STL or Boost ..!!

All, I wish to record 1000 real time data which need to be in sorted order. I used STL MAP which sorts using KEYS and than sorted the value using STL VECTOR, the complete scenario give me almost 6ms of time analysis. The TARGET is to achieve almost 1.5 - 2.0 ms. Also, once this data structure is completely filled I want to delete the first data and replace it with the new data. Can I have the fastest data structure (STL or BOOST) techniques for the same. ~ Thanks!!

Did you take a look at Boost.Container? There is boost::container::flat_map that is basically a vector with a map interface. Performance also depends on the size of your data type by the way, so it's a lot dependent on your context, you'll have to test different approaches yourself.

Rahul Mathur wrote:
I wish to record 1000 real time data which need to be in sorted order.
I used STL MAP which sorts using KEYS and than sorted the value using STL VECTOR, the complete scenario give me almost 6ms of time analysis. The TARGET is to achieve almost 1.5 - 2.0 ms.
Also, once this data structure is completely filled I want to delete the first data and replace it with the new data.
For mere 1k records, recommend multi_index with freshness measure as one index, and second index on extracted key. Don't recommend optimizing for the non-bottleneck, either. Can be replaced with something more involved once it's known to be the limiting case. -sh

On 09.10.2013 8:37, Rahul Mathur wrote: > I wish to record 1000 real time data which need to be in sorted order. > > I used STL MAP which sorts using KEYS and than sorted the value using STL > VECTOR, the complete scenario give me almost 6ms of time analysis. The > TARGET is to achieve almost 1.5 - 2.0 ms. It seems that you: 1. Posted to the wrong newsgroup. This newsgroup is about developing the boost library itself. 2. Used the stl containers in a wrong way. Why do you need to sort your data twice? > Also, once this data structure is completely filled I want to delete the > first data and replace it with the new data. It is not easy to understand from your short description what exactly do you need. Do you need to keep the sorted list of last 1000 data items received? In this case, you could: 1. Insert new data to the end of the std::list. 2. Delete old data from the beginning of the std::list if necessary. 3. Use the boost::intrusive::multiset as a sorting interface to the data in the list (note that intrusive containers do not own the data). > Can I have the fastest data structure (STL or BOOST) techniques for the > same. There is no such thing as the fastest data structure. You should not expect any magic from external libraries. You should find the algorithm that processes your data in the fastest way and then try to find the library that implements this algorithm. -- Sergey Cheban

On Wed, Oct 9, 2013 at 6:29 PM, Sergey Cheban
Also, once this data structure is completely filled I want to delete the
first data and replace it with the new data.
It's seems you need 2-dimensional sorting, one dimension for data, one for time. I have a library that is written for this kind of real-time analysis in multi-dimension, it has k-d tree containers that are self re-balancing, with insertion in fractional amortized time. You can check it out here: http://spatial.sourceforge.net/
I've been wanting to propose it for review on boost, but never got around to do it, cause I believe the documentation is sub-par. Your data set being small, 1000 (items), with a simple unsorted std::deque<> and using the std::nth_element() functor, may actually be faster. You need to try it. Good luck. Sylvain
participants (5)
-
Klaim - Joël Lamotte
-
Rahul Mathur
-
Sergey Cheban
-
Stanisław Halik
-
Sylvain Bougerel