What is the time complexity of QVector::toList() method?
-
Does
QVector()::toList()
produce a new QList in O(n) by iterating and copying elements, or is this perhaps an O(1) operation? My testing indicates that this is a linear time conversion. Am I correct?In general, is there documentation available regarding complexities for other related conversion operations, like
fromList()
,toStdVector()
etc.? -
QVector()::toList()
,QList::toVector
and thefromList/Vector()
methods are all copy element by element of one to the other. It's trivial to check: https://code.woboq.org/qt5/include/qt/QtCore/qvector.h.html#_ZNK7QVector6toListEvQVector::toStdVector
can leverage the fact that they both use contiguous memory and it boils down to little more than amemcpy
Some methods/classes declare their complexity in the description but I would say it's the exception rather than the norm