vectors vs. lists

Waldo Bastian bastian at kde.org
Thu Feb 19 12:17:29 GMT 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thu February 19 2004 10:46, Marc Mutz wrote:
> It's really funny how STL-trained people default to std::vector<> in all
> their code, and you see std::list<> only very rarely, but you see
> QValueList used as a default in KDE/Qt, and in ways that involve
> indexing (O(n)! vs. O(1) in QVV). This loop, btw,:
>
> for ( int i = 0 ; i < list.count() ; ++i )
>    doSomethingWith( list[i] );
>
> is O(n^2).

No, it is O(n) as well, see the implementation of 
QGList::locate( uint index )

Which brings me to my next point: 
* Don't optimize without profiling / benchmarking, there is a real risk that 
you make matters worse, not better.

Cheers,
Waldo
- -- 
bastian at kde.org -=|[ SUSE, The Linux Desktop Experts ]|=- bastian at suse.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQFANKlZN4pvrENfboIRApO/AJ9Lf7fBNqO593voXreqx+9GTDc93gCePGow
UsdNWe3WNvVDRl2m7SWfpcg=
=T9fr
-----END PGP SIGNATURE-----




More information about the kde-core-devel mailing list