Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. What is the time complexity of QVector::toList() method?

What is the time complexity of QVector::toList() method?

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 400 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    InverseTransform
    wrote on last edited by InverseTransform
    #1

    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.?

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      QVector()::toList(), QList::toVector and the fromList/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#_ZNK7QVector6toListEv

      QVector::toStdVector can leverage the fact that they both use contiguous memory and it boils down to little more than a memcpy

      Some methods/classes declare their complexity in the description but I would say it's the exception rather than the norm

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      4

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved