No, that is close. Btw, that seems like a really bad name for such a method, but that is my opinion.
Code: Select all
iterator find (const Key &key)
iterator findValue ((const Val &value)
I apologize if my request was unclear. I was tired. Now that I go back and look at it, the code snippet I stole from the documentation and quick-hacked (AGILE) was bad too.
The problem with
Code: Select all
const Key key (const Val &value, const Key &defaultKey=Key ()) const
is clear in the documentation.
const Key QMap< Key, Val, C >::key ( const Val & value,
const Key & defaultKey = Key()
) const
Returns the first key with value. If the map contains no item with value then defaultKey is returned.
This method can be slow (linear time), because the internal data structure is optimized for fast lookup by key, not by value.
To find a miss you have to have a known bogus key. The documentation is rather murky about what said "defaultKey" will have for a value. If it is an int will it give you -1 for an illegal subscript? If it is a QString key, what could it possibly give you to indicate a miss?
iterator QMap< Key, Val, C >::find ( const Key & key )
inline
Returns an iterator pointing to the item with the specified key. If the map contains no item with this key, the method returns end().
See also
constFind(), value(), values(), lowerBound(), upperBound()
No matter what the value is, end() tells us we didn't find it. More importantly,
Code: Select all
QMapIterator<QString, int> iter = findValue( "my value");
while ( iter.hasNext())
{
iter.next();
blah blah blah
}
should always work and though it is linear, we should find every key for every matching value. We don't have to translate bogus keys and trap for bogus values. We also don't have to worry about an accidental new empty item created for bogus key.