[Qt-interest] New container class needed in Qt

Scott Aron Bloom Scott.Bloom at onshorecs.com
Tue Oct 18 13:57:54 CEST 2011


I would (and have) created a new class

QOrderedMap< T1,T2 > that contains two containers, a map for lookup and
a list for iteration...

Pretty straight forward...

Scott

-----Original Message-----
From: qt-interest-bounces+scott.bloom=onshorecs.com at qt.nokia.com
[mailto:qt-interest-bounces+scott.bloom=onshorecs.com at qt.nokia.com] On
Behalf Of Mandeep Sandhu
Sent: Tuesday, October 18, 2011 1:34 AM
To: qt-interest at qt.nokia.com
Subject: [Qt-interest] New container class needed in Qt

Hi All,

I have a requirement where I want a Map/Hash like container on which I
can do key based lookups but also have the items stored in the order in
which they were inserted.

To elaborate, I'll detail my requirement with a simple example.

Consider that we have received a list of items from some external
source. The list contains strings in a particular order, eg: ["D", "B",
"A" , "C"].

I want to however, store some associated values along with each item of
the list. eg:
A - "Apple"
B - "Ball"
C - "Cat"
D - "Donkey" :)

I want to store this in a dictionary like structure because I would want
to later 'lookup' the associated values with a given key (A/B/C..).

If I simply store it in a QMap, I can do lookups, but then the items
would get sorted alphabetically (A,B,C,D). However I want to preserve
the order of the keys. So using a QHash or QMap won't work.

A way of achieving the require behavior is to use a List, so that the
order of keys is preserved. But then there's no easy way to lookup any
arbitrary value (apart from iterating the list).
I don't want to maintain 2 structures (a list for keeping track of key
order and a map for value lookup).

Any suggestions about how existing container classes can be used to
achieve this?

Thanks,
-mandeep
_______________________________________________
Qt-interest mailing list
Qt-interest at qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-interest



More information about the Qt-interest-old mailing list