I am trying to maintain a sorted list.
Hence, when the key (not unique) of en element has changed, I will need to move an element at one location in std::deque to another location within the same std::deque.
I wonder what the most efficient way is. The simplest way is to do 1 binary search + 1 insert + 1 erase, which might involve memory allocation and deallocation.
Another way is to just call std::sort each time (after the key has changed) as it will do std::swap underneath. But it is a bit heavy O(n log n) (vs O(1) with 1 binary search + 1 insert + 1 erase = O(log n)).
Any suggestion is welcome.
Thanks!
std::dequeis not the appropriate container for your needs. Something likestd::setorstd::priority_queueorstd::listmay be more appropriate, depending. If you want to get useful help, you'll need to describe your actual use case. - Snefteltimerfdand alike. I have a specific environment that I can't use any OS based timer. - HCSFstd::multisetis a natural choice. Tho,std::map,std::multiset, andstd::sethave some latency spikes when tree rebalancing happens (I measured). - HCSF