Qt 4.8: Look for pairs into QHash/QMap<QString,int> using QRegExp
I'm looking for a way to efficiently search for a set of pairs inside a hashmap of QString,int using regular expressions.
In particular I want all the pairs which keys start with a particular string.
Why do you want to do that?
You want an "efficient" way for this, but also want to use QHash/QMap. But to solve what you want you have to iterate over all items anyway and check them. Thus you could accomplish the same thing with an ordinary QList/QVector/...
But if you need to use a QHash you can use "QHash::keys()":http://qt-project.org/doc/qt-4.8/qhash.html#keys and iterate through all keys and do your regex on them.
Ok, so basically it cannot exist a way to do this in less than O(n)?
no... since the hash is generated of the whole key.