[SOLVED] Data Structure - QList<QString> vs other type
-
Hey,
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.
Thank you!
-
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. -
Hi,
i guess each element is unique ? so maybe using a QSet<QString> is nice, as the search for an element is fast.
Sincerely -
QSet, Perfect!
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":
"https://www.dropbox.com/s/1s922cma69jae33/workoutlst.png?dl=0":https://www.dropbox.com/s/1s922cma69jae33/workoutlst.png?dl=0Now, 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!Update :
Seems like storing a QList to a Text column in MySQL is a bad idea
"http://stackoverflow.com/questions/3653462/is-storing-a-delimited-list-in-a-database-column-really-that-bad":http://stackoverflow.com/questions/3653462/is-storing-a-delimited-list-in-a-database-column-really-that-badSo I'm considering a table "Workout_Done" with columns : "id_user" and "name_workout"