Results 1 to 2 of 2

Thread: Removing items from QPtrList efficiency issues

  1. #1
    Join Date
    Mar 2006
    Posts
    56
    Thanks
    7
    Thanked 3 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question Removing items from QPtrList efficiency issues

    Hi,

    I have a QPtrList<myClass> which is a queue.
    Each element of myClass has an id.

    Given the id of an element in the queue, I need to remove such element from the QPtrList in the most efficient way.

    In order to do this, I would like to use a map for ids of elements in the queue, and associate something to each id in the map, such that allows me to efficiently find the element in the queue and delete it ( ideally with complexity O(1) ).

    These are the information I thought I can associate to each id in the map in order to remove such element from the queue:

    - the Pointer "p" (reference) to the element in the queue (I would need to use the removeRef(p) function of the QPtrList)
    or
    - the index "i" of the element in the queue (I would need to use the remove(i) function of the QPtrList)

    Does anyone know which function is the most efficient between the removeRef(p) or the remove(i) of the QPtrList class?

    Is it possible to use some other information (i.e. a QPtrListIterator) to delete an element from the QPtrList in a more efficient way?

    Thanks in advance for your help!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Removing items from QPtrList efficiency issues

    The problem is you'll have to remove the item from two lists and one of them won't be sorted. The thing you could do is to cheat by changing the queue into a sorted list (insertions slower) and keeping pointers to elements of the list as your queue, so that you can quickly access "the first" element. I think my explanation is a bit unclear, so ask if you have doubts

Similar Threads

  1. Removing items properly from qtreewidget item
    By Djony in forum Qt Programming
    Replies: 6
    Last Post: 21st November 2006, 12:20

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.