[KPhotoAlbum] Using STL-containers in kphotoalbum code ?

Henner Zeller h.zeller at acm.org
Tue May 1 10:26:32 CEST 2007


Hi,

I haven't seen any use of STL containers in the kphotoalbum code, so I
was wondering if it was 'allowed' ? Are there reasons only to use the
QT-containers ?
(Yes, STL really is available everywhere!)

The reasons why I am asking is because I need a set of elements, but
don't want to store the values (unecessary call to the copy
constructor), but only the pointers to it; the way you would do this
using the STL would be to write a comparator that takes the pointers
but compares the instances:

struct FooPtrLessThan
{
  bool operator()(const Foo* a, const Foo *b) const
  {
    return *a < *b;
  }
};

I don't see a way to do this with QMap or other containers in QT.
Disclaimer: I haven't done any QT/KDE programming since KDE 1.1 so I
might have missed something and happy to learn how this can be done
using the existing containers.

Reason for this all: There is a check in
ImageManager::RequestQueue::addRequest() that looks if an ImageRequest
to be added is already in the pending list. Since this is a linear
search, adding n elements is an O(n^2) operation - which makes showing
thumbnails on a big screen _very_ slow. Having the pending elements in
a set with the values being compared would help a lot here.

-henner


More information about the KPhotoAlbum mailing list