I'm writing a C++ Qt 6.2 application and need a queue that will contain a large number of items (in the tens of thousands). I need enqueuing and dequeuing to be fast operations, so preferably better than linear time. It would also be quite convenient (though not necessary) to be able to index into the list at an arbitrary index without requiring a linear search, which is why I'm not immediately jumping to a linked list like std::list
or QLinkedList
.
I'm considering QList
, but in Qt 6 it's now explicitly implemented as an array of items. It's not clear to me which operations will run in linear time. Qt's documentation states:
With the exception of append(), prepend() and replace(), these functions can be slow (linear time) for large lists, because they require moving many items in the list by one position in memory. If you want a container class that provides fast insertion/removal in the middle, use std::list instead.
The confusing bit here is that it says "fast insertion/removal in the middle" implying that removal from the beginning or end may not be linear, but it's not explicit about it.
There's also QQueue
which is specifically designed from removing from the front and appending to the back. But again the documentation does not make it clear if front-removal is optimized and not a linear-time operation for large lists.
Can anyone shed some light on this? Or should I just fall back on using a linked list?