[SOLVED] Data Structure - QList<QString> vs other type
I would like to keep a list of item that have been marked as "done"
Real use case : When a workout is done, I would add it's name (unique) into a QList.
The user interface would then show a different color for this workout (inside a QTableView with custom delegate).
I was wondering if storing this inside a QList is a good idea? Does the method .contains(QString other) of QList takes a long time to return true or false? is it O(1)? The List will become large and I want to make sure to use the best data type possible.
QList::contains(QString other) has a linear complexity, which is O(n).
I don't know any other way to find out if an item is in a list except to compare the items.
i guess each element is unique ? so maybe using a QSet<QString> is nice, as the search for an element is fast.
I was looking for a QHash that only has the key, this is exactly it.
Thank you very much for the help guys.
Yes each workout name is unique, I guess QHash<QString, bool> is the same thing as QSet?
Here is a concrete example of the "workout list":
Now, another question if you guys had experience with this...
I'm thinking of the best way to save the QHash in memory too keep the list persistent. I was thinking maybe a field in the database where I save all the name separated by a delimiter ("workout1;workout2;...). The downside I can see is it will become a big list, so saving and loading this field each session would be long.
Another option: Save it with QSettings locally but then if you change computer you would loose your list. Not sure if this idea is crazy or not: could saving the QSettings file as .ini in the database be a possible solution? Instead of saving it locally it would be portable and you would keep all your settings on multiple computers. Just food for thoughts..
Thanks for all the help!
Seems like storing a QList to a Text column in MySQL is a bad idea
So I'm considering a table "Workout_Done" with columns : "id_user" and "name_workout"