QHash< Key, T > Class Template Reference

#include <qhash.h>

Inheritance diagram for QHash< Key, T >:

Inheritance graph
[legend]
Collaboration diagram for QHash< Key, T >:

Collaboration graph
[legend]
List of all members.

Detailed Description

template<class Key, class T>
class QHash< Key, T >

The QHash class is a template class that provides a hash-table-based dictionary.

QHash<Key, T> is one of Qt's generic {container classes}. It stores (key, value) pairs and provides very fast lookup of the value associated with a key.

QHash provides very similar functionality to QMap. The differences are:

QHash provides faster lookups than QMap. (See {Algorithmic Complexity} for details.) When iterating over a QMap, the items are always sorted by key. With QHash, the items are arbitrarily ordered. The key type of a QMap must provide operator<(). The key type of a QHash must provide operator==() and a global {qHash()}{qHash}(Key) function.

Here's an example QHash with QString keys and int values:

        QHash<QString, int> hash;

To insert a (key, value) pair into the hash, you can use operator[]():

        hash["one"] = 1;
        hash["three"] = 3;
        hash["seven"] = 7;

This inserts the following three (key, value) pairs into the QHash: ("one", 1), ("three", 3), and ("seven", 7). Another way to insert items into the hash is to use insert():

        hash.insert("twelve", 12);

To look up a value, use operator[]() or value():

        int num1 = hash["thirteen"];
        int num2 = hash.value("thirteen");

If there is no item with the specified key in the hash, these functions return a {default-constructed value}.

If you want to check whether the hash contains a particular key, use contains():

        int timeout = 30;
        if (hash.contains("TIMEOUT"))
            timeout = hash.value("TIMEOUT");

There is also a value() overload that uses its second argument as a default value if there is no item with the specified key:

        int timeout = hash.value("TIMEOUT", 30);

In general, we recommend that you use contains() and value() rather than operator[]() for looking up a key in a hash. The reason is that operator[]() silently inserts an item into the hash if no item exists with the same key (unless the hash is const). For example, the following code snippet will create 1000 items in memory:

        // WRONG
        QHash<int, QWidget *> hash;
        ...
        for (int i = 0; i < 1000; ++i) {
            if (hash[i] == okButton)
                cout << "Found button at index " << i << endl;
        }

To avoid this problem, replace hash[i] with hash.value(i) in the code above.

If you want to navigate through all the (key, value) pairs stored in a QHash, you can use an iterator. QHash provides both {Java-style iterators} (QHashIterator and QMutableHashIterator) and {STL-style iterators} (QHash::const_iterator and QHash::iterator). Here's how to iterate over a QHash<QString, int> using a Java-style iterator:

        QHashIterator<QString, int> i(hash);
        while (i.hasNext()) {
            i.next();
            cout << i.key() << ": " << i.value() << endl;
        }

Here's the same code, but using an STL-style iterator:

        QHash<QString, int>::const_iterator i = hash.constBegin();
        while (i != hash.constEnd()) {
            cout << i.key() << ": " << i.value() << endl;
            ++i;
        }

QHash is unordered, so an iterator's sequence cannot be assumed to be predictable. If ordering by key is required, use a QMap.

Normally, a QHash allows only one value per key. If you call insert() with a key that already exists in the QHash, the previous value is erased. For example:

        hash.insert("plenty", 100);
        hash.insert("plenty", 2000);
        // hash.value("plenty") == 2000

However, you can store multiple values per key by using insertMulti() instead of insert() (or using the convenience subclass QMultiHash). If you want to retrieve all the values for a single key, you can use values(const Key &key), which returns a QList<T>:

        QList<int> values = hash.values("plenty");
        for (int i = 0; i < values.size(); ++i)
            cout << values.at(i) << endl;

The items that share the same key are available from most recently to least recently inserted. A more efficient approach is to call find() to get the iterator for the first item with a key and iterate from there:

        QHash<QString, int>::iterator i = hash.find("plenty");
        while (i != hash.end() && i.key() == "plenty") {
            cout << i.value() << endl;
            ++i;
        }

If you only need to extract the values from a hash (not the keys), you can also use {foreach}:

        QHash<QString, int> hash;
        ...
        foreach (int value, hash)
            cout << value << endl;

Items can be removed from the hash in several ways. One way is to call remove(); this will remove any item with the given key. Another way is to use QMutableHashIterator::remove(). In addition, you can clear the entire hash using clear().

QHash's key and value data types must be {assignable data types}. You cannot, for example, store a QWidget as a value; instead, store a QWidget *. In addition, QHash's key type must provide operator==(), and there must also be a global qHash() function that returns a hash value for an argument of the key's type.

Here's a list of the C++ and Qt types that can serve as keys in a QHash: any integer type (char, unsigned long, etc.), any pointer type, QChar, QString, and QByteArray. For all of these, the <QHash> header defines a qHash() function that computes an adequate hash value. If you want to use other types as the key, make sure that you provide operator==() and a qHash() implementation.

Example:

        #ifndef EMPLOYEE_H
        #define EMPLOYEE_H

        class Employee
        {
        public:
            Employee() {}
            Employee(const QString &name, const QDate &dateOfBirth);
            ...

        private:
            QString myName;
            QDate myDateOfBirth;
        };

        inline bool operator==(const Employee &e1, const Employee &e2)
        {
            return e1.name() == e2.name()
                   && e1.dateOfBirth() == e2.dateOfBirth();
        }

        inline uint qHash(const Employee &key)
        {
            return qHash(key.name()) ^ key.dateOfBirth().day();
        }

        #endif // EMPLOYEE_H

The qHash() function computes a numeric value based on a key. It can use any algorithm imaginable, as long as it always returns the same value if given the same argument. In other words, if {e1 == e2}, then {qHash(e1) == qHash(e2)} must hold as well. However, to obtain good performance, the qHash() function should attempt to return different hash values for different keys to the largest extent possible.

In the example above, we've relied on Qt's global qHash(const QString &) to give us a hash value for the employee's name, and XOR'ed this with the day they were born to help produce unique hashes for people with the same name.

Internally, QHash uses a hash table to perform lookups. Unlike Qt 3's QDict class, which needed to be initialized with a prime number, QHash's hash table automatically grows and shrinks to provide fast lookups without wasting too much memory. You can still control the size of the hash table by calling reserve() if you already know approximately how many items the QHash will contain, but this isn't necessary to obtain good performance. You can also call capacity() to retrieve the hash table's size.

See also:
QHashIterator, QMutableHashIterator, QMap, QSet

Definition at line 209 of file qhash.h.

Public Types

typedef iterator Iterator
typedef const_iterator ConstIterator
typedef T mapped_type
typedef Key key_type
typedef ptrdiff_t difference_type
typedef int size_type

Public Member Functions

 QHash ()
 QHash (const QHash< Key, T > &other)
 ~QHash ()
QHash< Key, T > & operator= (const QHash< Key, T > &other)
bool operator== (const QHash< Key, T > &other) const
bool operator!= (const QHash< Key, T > &other) const
int size () const
bool isEmpty () const
int capacity () const
void reserve (int size)
void squeeze ()
void detach ()
bool isDetached () const
void setSharable (bool sharable)
void clear ()
int remove (const Key &key)
take (const Key &key)
bool contains (const Key &key) const
const Key key (const T &value) const
const T value (const Key &key) const
const T value (const Key &key, const T &defaultValue) const
T & operator[] (const Key &key)
const T operator[] (const Key &key) const
QList< Key > uniqueKeys () const
QList< Key > keys () const
QList< Key > keys (const T &value) const
QList< T > values () const
QList< T > values (const Key &key) const
int count (const Key &key) const
iterator begin ()
const_iterator begin () const
const_iterator constBegin () const
iterator end ()
const_iterator end () const
const_iterator constEnd () const
iterator erase (iterator it)
int count () const
iterator find (const Key &key)
const_iterator find (const Key &key) const
const_iterator constFind (const Key &key) const
iterator insert (const Key &key, const T &value)
iterator insertMulti (const Key &key, const T &value)
QHash< Key, T > & unite (const QHash< Key, T > &other)
bool empty () const

Private Types

typedef QHashDummyNode< Key,
T > 
DummyNode
typedef QHashNode< Key, T > Node

Private Member Functions

void detach_helper ()
void freeData (QHashData *d)
Node ** findNode (const Key &key, uint *hp=0) const
NodecreateNode (uint h, const Key &key, const T &value, Node **nextNode)
void deleteNode (Node *node)

Static Private Member Functions

static Nodeconcrete (QHashData::Node *node)
static void duplicateNode (QHashData::Node *originalNode, void *newNode)

Private Attributes

union {
   QHashData *   d
   QHashNode< Key, T > *   e
}; 

Friends

class iterator
class const_iterator

Related Functions

(Note that these are not member functions.)

uint qHash (char key)
uint qHash (uchar key)
uint qHash (signed char key)
uint qHash (ushort key)
uint qHash (short key)
uint qHash (uint key)
uint qHash (int key)
uint qHash (ulong key)
uint qHash (long key)
uint qHash (quint64 key)
uint qHash (qint64 key)
uint qHash (QChar key)
uint qHash (const QByteArray &key)
uint qHash (const QString &key)
uint qHash (const T *key)
QDataStreamoperator<< (QDataStream &out, const QHash< Key, T > &hash)
QDataStreamoperator>> (QDataStream &in, QHash< Key, T > &hash)

Classes

class  const_iterator
 The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash. More...
class  iterator
 The QHash::iterator class provides an STL-style non-const iterator for QHash and QMultiHash. More...


Member Typedef Documentation

template<class Key, class T>
typedef QHashDummyNode<Key, T> QHash< Key, T >::DummyNode [private]

Definition at line 211 of file qhash.h.

template<class Key, class T>
typedef QHashNode<Key, T> QHash< Key, T >::Node [private]

Definition at line 212 of file qhash.h.

template<class Key, class T>
QHash< Key, T >::Iterator

Qt-style synonym for QHash::iterator.

Definition at line 407 of file qhash.h.

template<class Key, class T>
QHash< Key, T >::ConstIterator

Qt-style synonym for QHash::const_iterator.

Definition at line 408 of file qhash.h.

template<class Key, class T>
QHash< Key, T >::mapped_type

Typedef for T. Provided for STL compatibility.

Definition at line 418 of file qhash.h.

template<class Key, class T>
QHash< Key, T >::key_type

Typedef for Key. Provided for STL compatibility.

Definition at line 419 of file qhash.h.

template<class Key, class T>
QHash< Key, T >::difference_type

Typedef for ptrdiff_t. Provided for STL compatibility.

Definition at line 420 of file qhash.h.

template<class Key, class T>
QHash< Key, T >::size_type

Typedef for int. Provided for STL compatibility.

Definition at line 421 of file qhash.h.


Constructor & Destructor Documentation

template<class Key, class T>
QHash< Key, T >::QHash (  )  [inline]

Constructs an empty hash.

See also:
clear()

Definition at line 224 of file qhash.h.

00224 : d(&QHashData::shared_null) { d->ref.ref(); }

template<class Key, class T>
QHash< Key, T >::QHash ( const QHash< Key, T > &  other  )  [inline]

Constructs a copy of other.

This operation occurs in {constant time}, because QHash is {implicitly shared}. This makes returning a QHash from a function very fast. If a shared instance is modified, it will be copied (copy-on-write), and this takes {linear time}.

See also:
operator=()

Definition at line 225 of file qhash.h.

00225 : d(other.d) { d->ref.ref(); if (!d->sharable) detach(); }

template<class Key, class T>
QHash< Key, T >::~QHash (  )  [inline]

Destroys the hash. References to the values in the hash and all iterators of this hash become invalid.

Definition at line 226 of file qhash.h.

00226 { if (!d->ref.deref()) freeData(d); }


Member Function Documentation

template<class Key, class T>
static Node* QHash< Key, T >::concrete ( QHashData::Node node  )  [inline, static, private]

Definition at line 219 of file qhash.h.

Referenced by QHash< Key, T >::duplicateNode(), QHash< Key, T >::iterator::key(), QHash< Key, T >::const_iterator::key(), QHash< Key, T >::iterator::operator *(), QHash< Key, T >::const_iterator::operator *(), QHash< Key, T >::iterator::operator Node *(), QHash< Key, T >::const_iterator::operator Node *(), QHash< Key, T >::const_iterator::operator->(), QHash< Key, T >::iterator::operator->(), QHash< Key, T >::iterator::value(), and QHash< Key, T >::const_iterator::value().

00219                                                       {
00220         return reinterpret_cast<Node *>(node);
00221     }

template<class Key, class T>
Q_INLINE_TEMPLATE QHash< Key, T > & QHash< Key, T >::operator= ( const QHash< Key, T > &  other  ) 

Assigns other to this hash and returns a reference to this hash.

Definition at line 529 of file qhash.h.

References QHash< Key, T >::d, QHash< Key, T >::detach_helper(), QHash< Key, T >::freeData(), qAtomicSetPtr(), QHashData::sharable, and x.

00530 {
00531     if (d != other.d) {
00532         QHashData *x = other.d;
00533         x->ref.ref();
00534         x = qAtomicSetPtr(&d, x);
00535         if (!x->ref.deref())
00536             freeData(x);
00537         if (!d->sharable)
00538             detach_helper();
00539     }
00540     return *this;
00541 }

Here is the call graph for this function:

template<class Key, class T>
Q_OUTOFLINE_TEMPLATE bool QHash< Key, T >::operator== ( const QHash< Key, T > &  other  )  const

Returns true if other is equal to this hash; otherwise returns false.

Two hashes are considered equal if they contain the same (key, value) pairs.

This function requires the value type to implement operator==().

See also:
operator!=()

Definition at line 819 of file qhash.h.

References QHash< Key, T >::begin(), QHash< Key, T >::d, QHash< Key, T >::end(), QHash< Key, T >::find(), QHash< Key, T >::const_iterator::key(), QHash< Key, T >::size(), and QHash< Key, T >::const_iterator::value().

00820 {
00821     if (size() != other.size())
00822         return false;
00823     if (d == other.d)
00824         return true;
00825 
00826     const_iterator it = begin();
00827 
00828     while (it != end()) {
00829         const Key &akey = it.key();
00830 
00831         const_iterator it2 = other.find(akey);
00832         do {
00833             if (it2 == other.end() || !(it2.key() == akey))
00834                 return false;
00835             if (!QTypeInfo<T>::isDummy && !(it.value() == it2.value()))
00836                 return false;
00837             ++it;
00838             ++it2;
00839         } while (it != end() && it.key() == akey);
00840     }
00841     return true;
00842 }

Here is the call graph for this function:

template<class Key, class T>
bool QHash< Key, T >::operator!= ( const QHash< Key, T > &  other  )  const [inline]

Returns true if other is not equal to this hash; otherwise returns false.

Two hashes are considered equal if they contain the same (key, value) pairs.

This function requires the value type to implement operator==().

See also:
operator==()

Definition at line 231 of file qhash.h.

00231 { return !(*this == other); }

template<class Key, class T>
int QHash< Key, T >::size (  )  const [inline]

Returns the number of items in the hash.

See also:
isEmpty(), count()

Definition at line 233 of file qhash.h.

Referenced by QGradientCache::addCacheElement(), QCache< int, QPixmap >::count(), QApplication::font(), QFreetypeFace::getFace(), QHash< Key, T >::operator==(), QApplication::palette(), qPRCleanup(), QApplication::setFont(), QApplicationPrivate::setPalette_helper(), QCache< int, QPixmap >::size(), and RCCFileInfo::writeDataInfo().

00233 { return d->size; }

template<class Key, class T>
bool QHash< Key, T >::isEmpty (  )  const [inline]

Returns true if the hash contains no items; otherwise returns false.

See also:
size()

Definition at line 235 of file qhash.h.

Referenced by QSqlResult::bindValue(), qdesigner_internal::Layout::breakLayout(), QHash< QString, QTranslator * >::empty(), FtpWindow::ftpCommandFinished(), PortingRules::getClassLibraryList(), QFreetypeFace::getFace(), PortingRules::getNeededHeaders(), getPath(), QSqlResult::hasOutValues(), QSvgSwitch::init(), initFontSubst(), QCache< int, QPixmap >::isEmpty(), QKqueueFileSystemWatcherEngine::removePaths(), QPollingFileSystemWatcherEngine::removePaths(), resolveColor(), QSocks5BindStore::retrieve(), QDomElementPrivate::save(), qdesigner_internal::QDesignerResource::saveCustomWidgets(), QDesignerWorkbench::switchToDockedMode(), and Q3TextFormatCollection::updateKeys().

00235 { return d->size == 0; }

template<class Key, class T>
int QHash< Key, T >::capacity (  )  const [inline]

Returns the number of buckets in the QHash's internal hash table.

The sole purpose of this function is to provide a means of fine tuning QHash's memory usage. In general, you will rarely ever need to call this function. If you want to know how many items are in the hash, call size().

See also:
reserve(), squeeze()

Definition at line 237 of file qhash.h.

00237 { return d->numBuckets; }

template<class Key, class T>
Q_INLINE_TEMPLATE void QHash< Key, T >::reserve ( int  size  ) 

Ensures that the QHash's internal hash table consists of at least size buckets.

This function is useful for code that needs to build a huge hash and wants to avoid repeated reallocation. For example:

        QHash<QString, int> hash;
        hash.reserve(20000);
        for (int i = 0; i < 20000; ++i)
            hash.insert(keys[i], values[i]);

Ideally, size should be slightly more than the maximum number of items expected in the hash. size doesn't have to be prime, because QHash will use a prime number internally anyway. If size is an underestimate, the worst that will happen is that the QHash will be a bit slower.

In general, you will rarely ever need to call this function. QHash's internal hash table automatically shrinks or grows to provide good performance without wasting too much memory.

See also:
squeeze(), capacity()

Definition at line 767 of file qhash.h.

References QHash< Key, T >::d, QHash< Key, T >::detach(), qMax(), and QHashData::rehash().

Referenced by QSet< T >::reserve(), and QHash< QString, QTranslator * >::squeeze().

00768 {
00769     detach();
00770     d->rehash(-qMax(asize, 1));
00771 }

Here is the call graph for this function:

template<class Key, class T>
void QHash< Key, T >::squeeze (  )  [inline]

Reduces the size of the QHash's internal hash table to save memory.

The sole purpose of this function is to provide a means of fine tuning QHash's memory usage. In general, you will rarely ever need to call this function.

See also:
reserve(), capacity()

Definition at line 239 of file qhash.h.

00239 { reserve(1); }

template<class Key, class T>
void QHash< Key, T >::detach (  )  [inline]

Definition at line 241 of file qhash.h.

Referenced by QHash< QString, QTranslator * >::begin(), QHash< QString, QTranslator * >::end(), QHash< Key, T >::find(), QHash< Key, T >::insert(), QHash< Key, T >::insertMulti(), QHash< Key, T >::operator[](), QHash< QString, QTranslator * >::QHash(), QHash< Key, T >::remove(), QHash< Key, T >::reserve(), QHash< QString, QTranslator * >::setSharable(), and QHash< Key, T >::take().

00241 { if (d->ref != 1) detach_helper(); }

template<class Key, class T>
bool QHash< Key, T >::isDetached (  )  const [inline]

Definition at line 242 of file qhash.h.

00242 { return d->ref == 1; }

template<class Key, class T>
void QHash< Key, T >::setSharable ( bool  sharable  )  [inline]

Definition at line 243 of file qhash.h.

00243 { if (!sharable) detach(); d->sharable = sharable; }

template<class Key, class T>
Q_INLINE_TEMPLATE void QHash< Key, T >::clear (  ) 

Removes all items from the hash.

See also:
remove()

Definition at line 513 of file qhash.h.

Referenced by CPP::WriteInitialization::acceptUI(), QDBusConnectionPrivate::bindToApplication(), FtpWindow::cdToParent(), QGLGlyphCache::cleanCache(), QSqlDatabasePrivate::cleanConnections(), cleanup_cmaps(), QFileInfoPrivate::Data::clear(), FeatureTreeModel::clear(), QHeaderViewPrivate::clear(), QHeaderViewPrivate::clearCascadingSections(), QSqlResultPrivate::clearIndex(), QDomNamedNodeMapPrivate::clearMap(), FtpWindow::connectOrDisconnect(), Q3IconView::contentsMousePressEventEx(), Q3IconView::contentsMouseReleaseEvent(), qdesigner_internal::QDesignerResource::copy(), QDesignerWorkbench::initialize(), qdesigner_internal::LinePropertySheet::LinePropertySheet(), operator>>(), FtpWindow::processItem(), qdesigner_internal::QLayoutWidgetPropertySheet::QLayoutWidgetPropertySheet(), QAbstractFormBuilder::reset(), Driver::reset(), QAbstractFormBuilder::save(), QApplication::setFont(), QApplicationPrivate::setPalette_helper(), qdesigner_internal::SpacerPropertySheet::SpacerPropertySheet(), QDesignerWorkbench::switchToNeutralMode(), Q3TextFormatCollection::updateKeys(), TrWindow::updatePhraseDict(), QPdfEnginePrivate::writeFonts(), and QDBusConnectionManager::~QDBusConnectionManager().

00514 {
00515     *this = QHash<Key,T>();
00516 }

template<class Key, class T>
Q_OUTOFLINE_TEMPLATE int QHash< Key, T >::remove ( const Key &  key  ) 

Removes all the items that have the key key from the hash. Returns the number of items removed which is usually 1 but will be 0 if the key isn't in the hash, or greater than 1 if insertMulti() has been used with the key.

See also:
clear(), take()

Definition at line 709 of file qhash.h.

References QHash< Key, T >::d, QHash< Key, T >::deleteNode(), QHash< Key, T >::detach(), QHash< Key, T >::e, QHash< Key, T >::findNode(), QHashData::hasShrunk(), next, and QHashData::size.

Referenced by QHeaderViewPrivate::_q_sectionsRemoved(), QGradientCache::addCacheElement(), DocumentShape::animate(), PanelShape::animate(), ImageShape::animate(), TitleShape::animate(), QHeaderViewPrivate::cascadingResize(), QDesignerMenu::createRealMenuAction(), QDBusConnectionPrivate::disconnectSignal(), QString::free(), main(), QExtensionFactory::objectDestroyed(), Preprocessor::preprocess(), qPRCleanup(), qt_x11_set_fallback_font_family(), QInotifyFileSystemWatcherEngine::readFromInotify(), QString::realloc(), Q3SqlForm::remove(), QPMCache::remove(), QDomDocumentTypePrivate::removeChild(), Client::removeConnection(), QView3DPlugin::removeFormWindow(), DisplayShape::removeMetaData(), QPollingFileSystemWatcherEngine::removePaths(), QFont::removeSubstitution(), QDomDocumentTypePrivate::replaceChild(), QKqueueFileSystemWatcherEngine::run(), QAuServerNAS::setDone(), QDesktopServices::setUrlHandler(), QWidgetPrivate::setWinId(), qdesigner_internal::MetaDataBase::slotDestroyed(), QAuServerNAS::soundDestroyed(), QCache< int, QPixmap >::unlink(), QExtensionManager::unregisterExtensions(), and qdesigner_internal::Layout::widgetDestroyed().

00710 {
00711     detach();
00712 
00713     int oldSize = d->size;
00714     Node **node = findNode(akey);
00715     if (*node != e) {
00716         bool deleteNext = true;
00717         do {
00718             Node *next = (*node)->next;
00719             deleteNext = (next != e && next->key == (*node)->key);
00720             deleteNode(*node);
00721             *node = next;
00722             --d->size;
00723         } while (deleteNext);
00724         d->hasShrunk();
00725     }
00726     return oldSize - d->size;
00727 }

Here is the call graph for this function:

template<class Key, class T>
Q_OUTOFLINE_TEMPLATE T QHash< Key, T >::take ( const Key &  key  ) 

Removes the item with the key key from the hash and returns the value associated with it.

If the item does not exist in the hash, the function simply returns a {default-constructed value}. If there are multiple items for key in the hash, only the most recently inserted one is removed.

If you don't use the return value, remove() is more efficient.

See also:
remove()

Definition at line 730 of file qhash.h.

References QHash< Key, T >::d, QHash< Key, T >::deleteNode(), QHash< Key, T >::detach(), QHash< Key, T >::e, QHash< Key, T >::findNode(), QHashData::hasShrunk(), next, QHashData::size, T, and t.

Referenced by QSqlDatabasePrivate::addDatabase(), QGLGlyphCache::cleanupContext(), QGLGlyphCache::fontEngineDestroyed(), Q3TextFormatCollection::remove(), QDBusConnectionManager::removeConnection(), QSqlDatabasePrivate::removeDatabase(), QKqueueFileSystemWatcherEngine::removePaths(), QInotifyFileSystemWatcherEngine::removePaths(), and QSocks5BindStore::retrieve().

00731 {
00732     detach();
00733 
00734     Node **node = findNode(akey);
00735     if (*node != e) {
00736         T t = (*node)->value;
00737         Node *next = (*node)->next;
00738         deleteNode(*node);
00739         *node = next;
00740         --d->size;
00741         d->hasShrunk();
00742         return t;
00743     }
00744     return T();
00745 }

Here is the call graph for this function:

template<class Key, class T>
Q_INLINE_TEMPLATE bool QHash< Key, T >::contains ( const Key &  key  )  const

Returns true if the hash contains an item with key key; otherwise returns false.

See also:
count()

Definition at line 793 of file qhash.h.

References QHash< Key, T >::e, and QHash< Key, T >::findNode().

Referenced by CPP::WriteInitialization::acceptTabStops(), CPP::WriteInitialization::acceptUI(), CPP::WriteInitialization::acceptWidget(), QSocks5BindStore::add(), QSqlDatabasePrivate::addDatabase(), RCCResourceLibrary::addFile(), QView3DPlugin::addFormWindow(), QPollingFileSystemWatcherEngine::addPaths(), TrPreviewTool::addTranslator(), DocumentShape::animate(), PanelShape::animate(), ImageShape::animate(), TitleShape::animate(), callback(), QHeaderViewPrivate::cascadingResize(), DomItem::child(), QSocks5BindStore::contains(), DisplayShape::contains(), QCache< int, QPixmap >::contains(), Driver::containsPixmap(), PreprocessorCache::containsSourceTokens(), PreprocessorCache::containsSourceTree(), qdesigner_internal::QDesignerResource::createDom(), QAbstractFormBuilder::createDom(), TrWindow::danger(), Q3IconView::doAutoScroll(), QSvgSwitch::draw(), QSvgFont::draw(), QExtensionFactory::extension(), Driver::findOrInsertAction(), Driver::findOrInsertActionGroup(), Driver::findOrInsertLayout(), Driver::findOrInsertSpacer(), Driver::findOrInsertWidget(), QFileInfoPrivate::getFileName(), TrWindow::getPhrases(), Client::hasConnection(), Driver::hasName(), QRenderRule::hasStyleHint(), QTextHtmlParser::importStyleSheet(), FeatureTreeModel::index(), QDesignerPropertySheet::isAdditionalProperty(), QDesignerPropertySheet::isFakeProperty(), CPP::WriteInitialization::isValidObject(), MessageModel::load(), TrPreviewTool::loadTranslation(), QErrorMessagePrivate::nextPending(), TrPreviewTool::openForm(), FeatureTreeModel::parent(), Q3TextEdit::pickSpecial(), Preprocessor::preprocess(), PreprocessorController::readFile(), QExtensionManager::registerExtensions(), Client::removeConnection(), QSqlDatabasePrivate::removeDatabase(), QView3DPlugin::removeFormWindow(), QStyleSheetStyle::renderRule(), resolveColor(), QSocks5BindStore::retrieve(), QHeaderViewPrivate::saveCascadingSectionSize(), qdesigner_internal::MetaDataBase::slotDestroyed(), PreprocessorCache::sourceTokens(), PreprocessorCache::sourceTree(), Preprocessor::substituteUntilNewline(), Driver::unique(), QExtensionManager::unregisterExtensions(), TrWindow::updatePhraseDict(), and RCCResourceLibrary::writeDataNames().

00794 {
00795     return *findNode(akey) != e;
00796 }

Here is the call graph for this function:

template<class Key, class T>
Q_OUTOFLINE_TEMPLATE const Key QHash< Key, T >::key ( const T &  value  )  const

Returns the first key with value value.

If the hash contains no item with value value, the function returns a value} default-constructed key .

This function can be slow ({linear time}), because QHash's internal data structure is optimized for fast lookup by key, not by value.

See also:
value(), values()

Definition at line 610 of file qhash.h.

References QHash< Key, T >::begin(), QHash< Key, T >::end(), and i.

Referenced by Driver::actionByName(), Driver::actionGroupByName(), QSqlResultPrivate::holderAt(), Driver::layoutByName(), operator<<(), QDesignerPropertySheet::propertyName(), QDesignerMenu::safeMenuAction(), Driver::spacerByName(), and Driver::widgetByName().

00611 {
00612     const_iterator i = begin();
00613     while (i != end()) {
00614         if (i.value() == avalue)
00615             return i.key();
00616         ++i;
00617     }
00618 
00619     return Key();
00620 }

Here is the call graph for this function:

template<class Key, class T>
Q_INLINE_TEMPLATE const T QHash< Key, T >::value ( const Key &  key  )  const

Returns the value associated with the key key.

If the hash contains no item with key key, the function returns a {default-constructed value}. If there are multiple items for key in the hash, the value of the most recently inserted one is returned.

See also:
key(), values(), contains(), operator[]()

Definition at line 544 of file qhash.h.

References QHash< Key, T >::e, QHash< Key, T >::findNode(), T, and QHashNode< Key, T >::value.

Referenced by CPP::WriteInitialization::acceptWidget(), qdesigner_internal::MetaDataBase::add(), QAbstractFormBuilder::addItem(), QDesignerWorkbench::adjustFormPositions(), DocumentShape::animate(), PanelShape::animate(), ImageShape::animate(), TitleShape::animate(), QSqlResult::bindValueType(), QMenuPrivate::calcActionRects(), QHeaderViewPrivate::cascadingResize(), QGLGlyphCache::cleanCache(), cleanup_cmaps(), QDBusConnectionManager::connection(), convertWithPalette(), QAbstractFormBuilder::create(), qdesigner_internal::QDesignerResource::create(), qdesigner_internal::QDesignerResource::createDom(), QItemEditorFactory::createEditor(), QDBusMetaObject::createMetaObject(), TrWindow::danger(), QSqlDatabasePrivate::database(), QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(), QPdfBaseEnginePrivate::drawTextItem(), FtpWindow::enableDownloadButton(), PreprocessReplace::evaluateIncludeDirective(), QExtensionManager::extension(), QWidget::find(), CPP::WriteInitialization::findImage(), QDBusConnectionPrivate::findMetaObject(), QDesignerMenu::findOrCreateSubMenu(), Driver::findOrInsertAction(), Driver::findOrInsertActionGroup(), Driver::findOrInsertLayout(), Driver::findOrInsertSpacer(), Driver::findOrInsertWidget(), QGLGlyphCache::fontEngineDestroyed(), Q3TextFormatCollection::format(), QConfFile::fromName(), QFileInfoPrivate::getFileName(), getPath(), TrWindow::getPhrases(), QComboMenuDelegate::getStyleOption(), QSqlResult::hasOutValues(), FilePorter::includeAnalyse(), FeatureTreeModel::index(), QDesignerPropertySheet::indexOf(), Q3StyleSheet::item(), qdesigner_internal::MetaDataBase::item(), MessageModel::load(), DisplayShape::metaData(), QPMCache::object(), TrPreviewTool::openForm(), operator<<(), QHash< Key, T >::operator[](), FeatureTreeModel::parent(), parseBrushValue(), FtpWindow::processItem(), QDesignerPropertySheet::property(), qdesigner_internal::MetaDataBaseItem::propertyComment(), qPRFindWidget(), qt_fallback_font_family(), PreprocessorController::readFile(), QInotifyFileSystemWatcherEngine::readFromInotify(), QItemEditorFactory::registerEditor(), QDockWidgetPrivate::relayout(), TrPreviewTool::reloadTranslations(), Q3TextFormatCollection::remove(), QPMCache::remove(), qdesigner_internal::MetaDataBase::remove(), QView3DPlugin::removeFormWindow(), QSqlRelationalTableModelPrivate::revertCachedRow(), QKqueueFileSystemWatcherEngine::run(), QMenuPrivate::setCurrentAction(), qdesigner_internal::MetaDataBase::slotDestroyed(), PreprocessorCache::sourceTokens(), PreprocessorCache::sourceTree(), QDialogButtonBox::standardButtons(), Q3CheckListItem::storedState(), QRenderRule::styleHint(), Preprocessor::substituteMacro(), QFont::substitutes(), QDesignerWorkbench::switchToDockedMode(), QDesignerWorkbench::switchToTopLevelMode(), Q3SqlForm::sync(), QPMCache::timerEvent(), QDBusConnectionPrivate::timerEvent(), TrPreviewTool::translationSelected(), XbelTree::updateDomElement(), QItemEditorFactory::valuePropertyName(), qdesigner_internal::WidgetBoxTreeView::widgetToItem(), RCCResourceLibrary::writeDataNames(), Q3StyleSheet::~Q3StyleSheet(), and Q3TextFormatCollection::~Q3TextFormatCollection().

00545 {
00546     Node *node = *findNode(akey);
00547     if (node == e) {
00548         return T();
00549     } else {
00550         return node->value;
00551     }
00552 }

Here is the call graph for this function:

template<class Key, class T>
Q_INLINE_TEMPLATE const T QHash< Key, T >::value ( const Key &  key,
const T &  defaultValue 
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. If the hash contains no item with the given key, the function returns defaultValue.

Definition at line 555 of file qhash.h.

References QHash< Key, T >::e, QHash< Key, T >::findNode(), and QHashNode< Key, T >::value.

00556 {
00557     Node *node = *findNode(akey);
00558     if (node == e) {
00559         return adefaultValue;
00560     } else {
00561         return node->value;
00562     }
00563 }

Here is the call graph for this function:

template<class Key, class T>
Q_INLINE_TEMPLATE T & QHash< Key, T >::operator[] ( const Key &  key  ) 

Returns the value associated with the key key as a modifiable reference.

If the hash contains no item with key key, the function inserts a {default-constructed value} into the hash with key key, and returns a reference to it. If the hash contains multiple items with key key, this function returns a reference to the most recently inserted value.

See also:
insert(), value()

Definition at line 667 of file qhash.h.

References QHash< Key, T >::createNode(), QHash< Key, T >::d, QHash< Key, T >::detach(), QHash< Key, T >::e, QHash< Key, T >::findNode(), h, QHashData::mightGrow(), T, and QHashNode< Key, T >::value.

00668 {
00669     detach();
00670     d->mightGrow();
00671 
00672     uint h;
00673     Node **node = findNode(akey, &h);
00674     if (*node == e)
00675         return createNode(h, akey, T(), node)->value;
00676     return (*node)->value;
00677 }

Here is the call graph for this function:

template<class Key, class T>
Q_INLINE_TEMPLATE const T QHash< Key, T >::operator[] ( const Key &  key  )  const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Same as value().

Definition at line 661 of file qhash.h.

References QHash< Key, T >::value().

00662 {
00663     return value(akey);
00664 }

Here is the call graph for this function:

template<class Key, class T>
Q_OUTOFLINE_TEMPLATE QList< Key > QHash< Key, T >::uniqueKeys (  )  const

Since:
4.2
Returns a list containing all the keys in the map in ascending order. Keys that occur multiple times in the map (because items were inserted with insertMulti(), or unite() was used) occur only once in the returned list.

See also:
keys(), values()

Definition at line 566 of file qhash.h.

References QList< T >::append(), QHash< Key, T >::begin(), QHash< Key, T >::end(), and i.

00567 {
00568     QList<Key> res;
00569     const_iterator i = begin();
00570     if (i != end()) {
00571         for (;;) {
00572             const Key &aKey = i.key();
00573             res.append(aKey);
00574             do {
00575                 if (++i == end())
00576                     goto break_out_of_outer_loop;
00577             } while (aKey == i.key());
00578         }
00579     }
00580 break_out_of_outer_loop:
00581     return res;
00582 }

Here is the call graph for this function:

template<class Key, class T>
Q_OUTOFLINE_TEMPLATE QList< Key > QHash< Key, T >::keys (  )  const

Returns a list containing all the keys in the hash, in an arbitrary order. Keys that occur multiple times in the hash (because items were inserted with insertMulti(), or unite() was used) also occur multiple times in the list.

To obtain a list of unique keys, where each key from the map only occurs once, use uniqueKeys().

The order is guaranteed to be the same as that used by values().

See also:
uniqueKeys(), values(), key()

Definition at line 585 of file qhash.h.

References QList< T >::append(), QHash< Key, T >::begin(), QHash< Key, T >::end(), and i.

Referenced by QGradientCache::addCacheElement(), QGLGlyphCache::cacheGlyphs(), QGLGlyphCache::cleanCache(), QGLGlyphCache::cleanupContext(), QGLGlyphCache::fontEngineDestroyed(), QCache< int, QPixmap >::keys(), TrPreviewTool::reloadTranslations(), and qdesigner_internal::QDesignerResource::saveCustomWidgets().

00586 {
00587     QList<Key> res;
00588     const_iterator i = begin();
00589     while (i != end()) {
00590         res.append(i.key());
00591         ++i;
00592     }
00593     return res;
00594 }

Here is the call graph for this function:

template<class Key, class T>
Q_OUTOFLINE_TEMPLATE QList< Key > QHash< Key, T >::keys ( const T &  value  )  const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns a list containing all the keys associated with value value, in an arbitrary order.

This function can be slow ({linear time}), because QHash's internal data structure is optimized for fast lookup by key, not by value.

Definition at line 597 of file qhash.h.

References QList< T >::append(), QHash< Key, T >::begin(), QHash< Key, T >::end(), and i.

00598 {
00599     QList<Key> res;
00600     const_iterator i = begin();
00601     while (i != end()) {
00602         if (i.value() == avalue)
00603             res.append(i.key());
00604         ++i;
00605     }
00606     return res;
00607 }

Here is the call graph for this function:

template<class Key, class T>
Q_OUTOFLINE_TEMPLATE QList< T > QHash< Key, T >::values (  )  const

Returns a list containing all the values in the hash, in an arbitrary order. If a key is associated multiple values, all of its values will be in the list, and not just the most recently inserted one.

The order is guaranteed to be the same as that used by keys().

See also:
keys()

Definition at line 623 of file qhash.h.

References QList< T >::append(), QHash< Key, T >::begin(), QHash< Key, T >::end(), and i.

Referenced by QApplication::allWidgets(), QTextHtmlParser::declarationsForNode(), Client::hasConnection(), Client::sendMessage(), RCCResourceLibrary::writeDataStructure(), QInotifyFileSystemWatcherEngine::~QInotifyFileSystemWatcherEngine(), and QKqueueFileSystemWatcherEngine::~QKqueueFileSystemWatcherEngine().

00624 {
00625     QList<T> res;
00626     const_iterator i = begin();
00627     while (i != end()) {
00628         res.append(i.value());
00629         ++i;
00630     }
00631     return res;
00632 }

Here is the call graph for this function:

template<class Key, class T>
Q_OUTOFLINE_TEMPLATE QList< T > QHash< Key, T >::values ( const Key &  key  )  const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns a list of all the values associated with key key, from the most recently inserted to the least recently inserted.

See also:
count(), insertMulti()

Definition at line 635 of file qhash.h.

References QList< T >::append(), QHash< Key, T >::e, QHash< Key, T >::findNode(), QHashNode< Key, T >::key, QHashNode< Key, T >::next, and QHashNode< Key, T >::value.

00636 {
00637     QList<T> res;
00638     Node *node = *findNode(akey);
00639     if (node != e) {
00640         do {
00641             res.append(node->value);
00642         } while ((node = node->next) != e && node->key == akey);
00643     }
00644     return res;
00645 }

Here is the call graph for this function:

template<class Key, class T>
Q_OUTOFLINE_TEMPLATE int QHash< Key, T >::count ( const Key &  key  )  const

Returns the number of items associated with key key.

See also:
contains(), insertMulti()

Definition at line 648 of file qhash.h.

References QHash< Key, T >::e, QHash< Key, T >::findNode(), QHashNode< Key, T >::key, and QHashNode< Key, T >::next.

Referenced by QHeaderViewPrivate::adjustedVisualIndex(), QDesignerPropertySheet::count(), and Q3TextFormatCollection::updateKeys().

00649 {
00650     int cnt = 0;
00651     Node *node = *findNode(akey);
00652     if (node != e) {
00653         do {
00654             ++cnt;
00655         } while ((node = node->next) != e && node->key == akey);
00656     }
00657     return cnt;
00658 }

Here is the call graph for this function:

template<class Key, class T>
QHash::iterator QHash< Key, T >::begin (  )  [inline]

Returns an {STL-style iterator} pointing to the first item in the hash.

See also:
constBegin(), end()

Definition at line 398 of file qhash.h.

Referenced by QAbstractTextDocumentLayoutPrivate::_q_handlerDestroyed(), QGLGlyphCache::cacheGlyphs(), QSqlDatabasePrivate::cleanConnections(), QHash< Key, T >::key(), QHash< Key, T >::keys(), QDBusConnectionPrivate::objectDestroyed(), qdesigner_internal::MetaDataBase::objects(), QHash< Key, T >::operator==(), Q3TextFormatCollection::setPaintDevice(), QPMCache::timerEvent(), QHash< Key, T >::uniqueKeys(), Q3TextFormatCollection::updateDefaultFormat(), Q3TextFormatCollection::updateKeys(), QHash< Key, T >::values(), QPdfEnginePrivate::writeFonts(), Q3StyleSheet::~Q3StyleSheet(), and QApplication::~QApplication().

00398 { detach(); return iterator(d->firstNode()); }

template<class Key, class T>
QHash::const_iterator QHash< Key, T >::begin (  )  const [inline]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 399 of file qhash.h.

00399 { return const_iterator(d->firstNode()); }

template<class Key, class T>
QHash::const_iterator QHash< Key, T >::constBegin (  )  const [inline]

Returns a const {STL-style iterator} pointing to the first item in the hash.

See also:
begin(), constEnd()

Definition at line 400 of file qhash.h.

Referenced by QDBusConnectionManager::bindToApplication(), QGLGlyphCache::cleanCache(), cleanup_cmaps(), QPSPrintEnginePrivate::emitPages(), QPSPrintEnginePrivate::flushPage(), QApplication::font(), QSqlResult::hasOutValues(), operator<<(), QApplication::palette(), Semantic::parseFunctionDefinition(), CodeModelAttributes::parseFunctionMember(), CodeModelWalker::parseScope(), qPRCleanup(), QDomElementPrivate::save(), QDomDocumentTypePrivate::save(), Semantic::selectFunction(), QFont::substitutions(), QMenuPrivate::updateActions(), Q3TextFormatCollection::~Q3TextFormatCollection(), and QDBusConnectionManager::~QDBusConnectionManager().

00400 { return const_iterator(d->firstNode()); }

template<class Key, class T>
QHash::iterator QHash< Key, T >::end (  )  [inline]

Returns an {STL-style iterator} pointing to the imaginary item after the last item in the hash.

See also:
begin(), constEnd()

Definition at line 401 of file qhash.h.

Referenced by QAbstractTextDocumentLayoutPrivate::_q_handlerDestroyed(), QGLGlyphCache::cacheGlyphs(), callback(), QMetaObject::changeGuard(), QSqlDatabasePrivate::cleanConnections(), QObjectPrivate::clearGuards(), QDBusConnectionPrivate::disconnectRelay(), QHash< Key, T >::key(), QHash< Key, T >::keys(), QDBusConnectionPrivate::objectDestroyed(), qdesigner_internal::MetaDataBase::objects(), QHash< Key, T >::operator==(), QConnectionList::remove(), QConnectionList::removeConnection(), QMetaObject::removeGuard(), Q3TextFormatCollection::setPaintDevice(), Q3CheckListItem::storedState(), QPMCache::timerEvent(), QHash< Key, T >::uniqueKeys(), Q3TextFormatCollection::updateDefaultFormat(), Q3TextFormatCollection::updateKeys(), QHash< Key, T >::values(), QPdfEnginePrivate::writeFonts(), Q3StyleSheet::~Q3StyleSheet(), and QApplication::~QApplication().

00401 { detach(); return iterator(e); }

template<class Key, class T>
QHash::const_iterator QHash< Key, T >::end (  )  const [inline]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 402 of file qhash.h.

00402 { return const_iterator(e); }

template<class Key, class T>
QHash::const_iterator QHash< Key, T >::constEnd (  )  const [inline]

Returns a const {STL-style iterator} pointing to the imaginary item after the last item in the hash.

See also:
constBegin(), end()

Definition at line 403 of file qhash.h.

Referenced by QDBusConnectionManager::bindToApplication(), QGLGlyphCache::cacheGlyphs(), choose_cmap(), QGLGlyphCache::cleanCache(), cleanup_cmaps(), QDomNamedNodeMapPrivate::clearMap(), QDomNamedNodeMapPrivate::clone(), QDBusConnectionPrivate::connectRelay(), QPSPrintEnginePrivate::emitPages(), QPSPrintEnginePrivate::flushPage(), QApplication::font(), QGradientCache::getBuffer(), QDBusConnectionPrivate::handleSignal(), QSqlResult::hasOutValues(), QGLGlyphCache::lookup(), QDomNamedNodeMapPrivate::namedItemNS(), QDesktopServices::openUrl(), operator<<(), QApplication::palette(), Semantic::parseFunctionDefinition(), CodeModelAttributes::parseFunctionMember(), CodeModelWalker::parseScope(), qPRCleanup(), QCache< int, QPixmap >::relink(), QDomElementPrivate::save(), QDomDocumentTypePrivate::save(), Semantic::selectFunction(), QFont::substitute(), QFont::substitutions(), QMenuPrivate::updateActions(), Q3TextFormatCollection::~Q3TextFormatCollection(), and QDBusConnectionManager::~QDBusConnectionManager().

00403 { return const_iterator(e); }

template<class Key, class T>
Q_OUTOFLINE_TEMPLATE QHash< Key, T >::iterator QHash< Key, T >::erase ( iterator  pos  ) 

Removes the (key, value) pair associated with the iterator pos from the hash, and returns an iterator to the next item in the hash.

Unlike remove() and take(), this function never causes QHash to rehash its internal data structure. This means that it can safely be called while iterating, and won't affect the order of items in the hash. For example:

        QHash<QObject *, int> objectHash;
        ...
        QHash<QObject *, int>::iterator i = objectHash.find(obj);
        while (i != objectHash.end() && i.key() == obj) {
            if (i.value() == 0) {
                i = objectHash.erase(i);
            } else {
                ++i;
            }
        }

See also:
remove(), take(), find()

Definition at line 748 of file qhash.h.

References QHashData::buckets, QHash< Key, T >::d, QHash< Key, T >::deleteNode(), QHash< Key, T >::e, QHashNode< Key, T >::h, QHash< Key, T >::iterator, QHashNode< Key, T >::next, QHashData::numBuckets, and QHashData::size.

Referenced by QAbstractTextDocumentLayoutPrivate::_q_handlerDestroyed(), QMetaObject::changeGuard(), QObjectPrivate::clearGuards(), QDBusConnectionPrivate::disconnectRelay(), QDBusConnectionPrivate::objectDestroyed(), QConnectionList::remove(), QConnectionList::removeConnection(), QMetaObject::removeGuard(), and QPMCache::timerEvent().

00749 {
00750     if (it == iterator(e))
00751         return it;
00752 
00753     iterator ret = it;
00754     ++ret;
00755 
00756     Node *node = it;
00757     Node **node_ptr = reinterpret_cast<Node **>(&d->buckets[node->h % d->numBuckets]);
00758     while (*node_ptr != node)
00759         node_ptr = &(*node_ptr)->next;
00760     *node_ptr = node->next;
00761     deleteNode(node);
00762     --d->size;
00763     return ret;
00764 }

Here is the call graph for this function:

template<class Key, class T>
int QHash< Key, T >::count (  )  const [inline]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Same as size().

Definition at line 409 of file qhash.h.

00409 { return d->size; }

template<class Key, class T>
Q_INLINE_TEMPLATE QHash< Key, T >::iterator QHash< Key, T >::find ( const Key &  key  ) 

Returns an iterator pointing to the item with key key in the hash.

If the hash contains no item with key key, the function returns end().

If the hash contains multiple items with key key, this function returns an iterator that points to the most recently inserted value. The other values are accessible by incrementing the iterator. For example, here's some code that iterates over all the items with the same key:

        QHash<QString, int> hash;
        ...
        QHash<QString, int>::const_iterator i = hash.find("HDR");
        while (i != hash.end() && i.key() == "HDR") {
            cout << i.value() << endl;
            ++i;
        }

See also:
value(), values()

Definition at line 786 of file qhash.h.

References QHash< Key, T >::detach(), QHash< Key, T >::findNode(), and QHash< Key, T >::iterator.

Referenced by callback(), QMetaObject::changeGuard(), QObjectPrivate::clearGuards(), QDBusConnectionPrivate::connectRelay(), QDBusConnectionPrivate::disconnectRelay(), QDBusConnectionPrivate::handleSignal(), QHash< Key, T >::operator==(), QCache< int, QPixmap >::relink(), QConnectionList::remove(), QConnectionList::removeConnection(), QMetaObject::removeGuard(), and Q3CheckListItem::storedState().

00787 {
00788     detach();
00789     return iterator(*findNode(akey));
00790 }

Here is the call graph for this function:

template<class Key, class T>
Q_INLINE_TEMPLATE QHash< Key, T >::const_iterator QHash< Key, T >::find ( const Key &  key  )  const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 774 of file qhash.h.

References QHash< Key, T >::const_iterator, and QHash< Key, T >::findNode().

00775 {
00776     return const_iterator(*findNode(akey));
00777 }

Here is the call graph for this function:

template<class Key, class T>
Q_INLINE_TEMPLATE QHash< Key, T >::const_iterator QHash< Key, T >::constFind ( const Key &  key  )  const

Since:
4.1
Returns an iterator pointing to the item with key key in the hash.

If the hash contains no item with key key, the function returns constEnd().

See also:
find()

Definition at line 780 of file qhash.h.

References QHash< Key, T >::const_iterator, and QHash< Key, T >::findNode().

Referenced by QGLGlyphCache::cacheGlyphs(), choose_cmap(), QApplication::font(), QGradientCache::getBuffer(), QGLGlyphCache::lookup(), QDesktopServices::openUrl(), QApplication::palette(), and QFont::substitute().

00781 {
00782     return const_iterator(*findNode(akey));
00783 }

Here is the call graph for this function:

template<class Key, class T>
Q_INLINE_TEMPLATE QHash< Key, T >::iterator QHash< Key, T >::insert ( const Key &  key,
const T &  value 
)

Inserts a new item with the key key and a value of value.

If there is already an item with the key key, that item's value is replaced with value.

If there are multiple items with the key key, the most recently inserted item's value is replaced with value.

See also:
insertMulti()

Definition at line 680 of file qhash.h.

References QHash< Key, T >::createNode(), QHash< Key, T >::d, QHash< Key, T >::detach(), QHash< Key, T >::e, QHash< Key, T >::findNode(), h, QHash< Key, T >::iterator, and QHashData::mightGrow().

Referenced by CPP::WriteInitialization::acceptAction(), CPP::WriteInitialization::acceptImage(), CPP::WriteInitialization::acceptUI(), CPP::WriteInitialization::acceptWidget(), qdesigner_internal::MetaDataBase::add(), QSocks5BindStore::add(), QSvgStructureNode::addChild(), QSqlDatabasePrivate::addDatabase(), RCCResourceLibrary::addFile(), QSvgFont::addGlyph(), QPollingFileSystemWatcherEngine::addPaths(), QInotifyFileSystemWatcherEngine::addPaths(), QKqueueFileSystemWatcherEngine::addPaths(), QSvgTinyDocument::addSvgFont(), TrPreviewTool::addTranslator(), QSvgNode::appendStyleProperty(), qdesigner_internal::Layout::breakLayout(), QGLGlyphCache::cacheGlyphs(), Q3IconView::contentsMousePressEventEx(), convertWithPalette(), QAbstractFormBuilder::createAction(), QAbstractFormBuilder::createActionGroup(), QDialogButtonBoxPrivate::createButton(), qdesigner_internal::QDesignerResource::createDom(), QAbstractFormBuilder::createDom(), QDesignerPropertySheet::createFakeProperty(), XbelTree::createItem(), QDBusMetaObject::createMetaObject(), QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(), QPdfBaseEnginePrivate::drawTextItem(), QExtensionFactory::extension(), QDesignerMenu::findOrCreateSubMenu(), Driver::findOrInsertAction(), Driver::findOrInsertActionGroup(), Driver::findOrInsertLayout(), Driver::findOrInsertSpacer(), Driver::findOrInsertWidget(), Q3TextFormatCollection::format(), QConfFile::fromName(), QFileInfoPrivate::getFileName(), getPath(), QTextHtmlParser::importStyleSheet(), QSvgSwitch::init(), QPMCache::insert(), Q3StyleSheet::insert(), Q3SqlForm::insert(), Driver::insertPixmap(), MessageModel::load(), qdesigner_internal::WidgetBoxTreeView::loadCustomCategoryList(), TrPreviewTool::loadTranslation(), main(), TrPreviewTool::openForm(), PortingRules::parseXml(), Q3TextEdit::pickSpecial(), QAuServerNAS::play(), Preprocessor::preprocess(), propertyMap(), QAbstractFormBuilder::propertyMap(), qdesigner_internal::QDesignerResource::QDesignerResource(), qPRCreate(), qt_x11_set_fallback_font_family(), QExtensionManager::registerExtensions(), TrPreviewTool::reloadTranslations(), QDesignerMenu::removeRealMenu(), QMultiHash< Key, T >::replace(), resolveColor(), QHeaderViewPrivate::saveCascadingSectionSize(), QApplication::setFont(), QApplicationPrivate::setPalette_helper(), QSettings::setPath(), qdesigner_internal::MetaDataBaseItem::setPropertyComment(), qdesigner_internal::Layout::setup(), QDesktopServices::setUrlHandler(), QWidgetPrivate::setWinId(), PreprocessorCache::sourceTokens(), PreprocessorCache::sourceTree(), QDesignerWorkbench::switchToNeutralMode(), Driver::unique(), Q3TextFormatCollection::updateKeys(), TrWindow::updatePhraseDict(), and RCCResourceLibrary::writeDataNames().

00682 {
00683     detach();
00684     d->mightGrow();
00685 
00686     uint h;
00687     Node **node = findNode(akey, &h);
00688     if (*node == e)
00689         return iterator(createNode(h, akey, avalue, node));
00690 
00691     if (!QTypeInfo<T>::isDummy)
00692         (*node)->value = avalue;
00693     return iterator(*node);
00694 }

Here is the call graph for this function:

template<class Key, class T>
Q_INLINE_TEMPLATE QHash< Key, T >::iterator QHash< Key, T >::insertMulti ( const Key &  key,
const T &  value 
)

Inserts a new item with the key key and a value of value.

If there is already an item with the same key in the hash, this function will simply create a new one. (This behavior is different from insert(), which overwrites the value of an existing item.)

See also:
insert(), values()

Definition at line 697 of file qhash.h.

References QHash< Key, T >::createNode(), QHash< Key, T >::d, QHash< Key, T >::detach(), QHash< Key, T >::findNode(), h, QHash< Key, T >::iterator, and QHashData::mightGrow().

Referenced by RCCResourceLibrary::addFile(), QDBusConnectionPrivate::bindToApplication(), QDBusConnectionPrivate::connectSignal(), QMultiHash< Key, T >::insert(), QDomDocumentTypePrivate::insertAfter(), QDomDocumentTypePrivate::insertBefore(), operator>>(), QDomDocumentTypePrivate::QDomDocumentTypePrivate(), QDomDocumentTypePrivate::replaceChild(), and QHash< Key, T >::unite().

00699 {
00700     detach();
00701     d->mightGrow();
00702 
00703     uint h;
00704     Node **nextNode = findNode(akey, &h);
00705     return iterator(createNode(h, akey, avalue, nextNode));
00706 }

Here is the call graph for this function:

template<class Key, class T>
Q_INLINE_TEMPLATE QHash< Key, T > & QHash< Key, T >::unite ( const QHash< Key, T > &  other  ) 

Inserts all the items in the other hash into this hash. If a key is common to both hashes, the resulting hash will contain the key multiple times.

See also:
insertMulti()

Definition at line 484 of file qhash.h.

References TokenEngine::copy(), QHash< Key, T >::insertMulti(), QHash< Key, T >::const_iterator::key(), and QHash< Key, T >::const_iterator::value().

Referenced by QMultiHash< QHostAddress, Connection * >::operator+=(), and PreprocessorController::PreprocessorController().

00485 {
00486     QHash<Key, T> copy(other);
00487     const_iterator it = copy.constEnd();
00488     while (it != copy.constBegin()) {
00489         --it;
00490         insertMulti(it.key(), it.value());
00491     }
00492     return *this;
00493 }

Here is the call graph for this function:

template<class Key, class T>
bool QHash< Key, T >::empty (  )  const [inline]

This function is provided for STL compatibility. It is equivalent to isEmpty(), returning true if the hash is empty; otherwise returns false.

Definition at line 423 of file qhash.h.

00423 { return isEmpty(); }

template<class Key, class T>
Q_OUTOFLINE_TEMPLATE void QHash< Key, T >::detach_helper (  )  [private]

Definition at line 519 of file qhash.h.

References QHash< Key, T >::d, QHashData::detach_helper(), QHash< Key, T >::duplicateNode(), QHash< Key, T >::freeData(), qAtomicSetPtr(), and x.

Referenced by QHash< QString, QTranslator * >::detach(), and QHash< Key, T >::operator=().

00520 {
00521     QHashData *x = d->detach_helper(duplicateNode,
00522         QTypeInfo<T>::isDummy ? sizeof(DummyNode) : sizeof(Node));
00523     x = qAtomicSetPtr(&d, x);
00524     if (!x->ref.deref())
00525         freeData(x);
00526 }

Here is the call graph for this function:

template<class Key, class T>
Q_OUTOFLINE_TEMPLATE void QHash< Key, T >::freeData ( QHashData d  )  [private]

Definition at line 496 of file qhash.h.

References QHash< Key, T >::deleteNode(), n, QHashNode< Key, T >::next, next, and x.

Referenced by QHash< Key, T >::detach_helper(), QHash< Key, T >::operator=(), and QHash< QString, QTranslator * >::~QHash().

00497 {
00498     Node *e_for_x = reinterpret_cast<Node *>(x);
00499     Node **bucket = reinterpret_cast<Node **>(x->buckets);
00500     int n = x->numBuckets;
00501     while (n--) {
00502         Node *cur = *bucket++;
00503         while (cur != e_for_x) {
00504             Node *next = cur->next;
00505             deleteNode(cur);
00506             cur = next;
00507         }
00508     }
00509     x->destroyAndFree();
00510 }

Here is the call graph for this function:

template<class Key, class T>
Q_OUTOFLINE_TEMPLATE QHash< Key, T >::Node ** QHash< Key, T >::findNode ( const Key &  key,
uint *  hp = 0 
) const [private]

Definition at line 799 of file qhash.h.

References QHashData::buckets, QHash< Key, T >::d, QHash< Key, T >::e, h, QHashNode< Key, T >::next, QHashData::numBuckets, and QHash< Key, T >::qHash().

Referenced by QHash< Key, T >::constFind(), QHash< Key, T >::contains(), QHash< Key, T >::count(), QHash< Key, T >::find(), QHash< Key, T >::insert(), QHash< Key, T >::insertMulti(), QHash< Key, T >::operator[](), QHash< Key, T >::remove(), QHash< Key, T >::take(), QHash< Key, T >::value(), and QHash< Key, T >::values().

00801 {
00802     Node **node;
00803     uint h = qHash(akey);
00804 
00805     if (d->numBuckets) {
00806         node = reinterpret_cast<Node **>(&d->buckets[h % d->numBuckets]);
00807         Q_ASSERT(*node == e || (*node)->next);
00808         while (*node != e && !(*node)->same_key(h, akey))
00809             node = &(*node)->next;
00810     } else {
00811         node = const_cast<Node **>(reinterpret_cast<const Node * const *>(&e));
00812     }
00813     if (ahp)
00814         *ahp = h;
00815     return node;
00816 }

Here is the call graph for this function:

template<class Key, class T>
Q_INLINE_TEMPLATE QHash< Key, T >::Node * QHash< Key, T >::createNode ( uint  h,
const Key &  key,
const T &  value,
Node **  nextNode 
) [private]

Definition at line 466 of file qhash.h.

References QHashData::allocateNode(), QHash< Key, T >::d, QHashNode< Key, T >::h, QHashNode< Key, T >::next, and QHashData::size.

Referenced by QHash< Key, T >::insert(), QHash< Key, T >::insertMulti(), and QHash< Key, T >::operator[]().

00467 {
00468     Node *node;
00469 
00470     if (QTypeInfo<T>::isDummy) {
00471         node = reinterpret_cast<Node *>(new (d->allocateNode()) DummyNode(akey));
00472     } else {
00473         node = new (d->allocateNode()) Node(akey, avalue);
00474     }
00475 
00476     node->h = ah;
00477     node->next = *anextNode;
00478     *anextNode = node;
00479     ++d->size;
00480     return node;
00481 }

Here is the call graph for this function:

template<class Key, class T>
Q_INLINE_TEMPLATE void QHash< Key, T >::deleteNode ( Node node  )  [private]

Definition at line 441 of file qhash.h.

References QHash< Key, T >::d, QHashData::freeNode(), and T.

Referenced by QHash< Key, T >::erase(), QHash< Key, T >::freeData(), QHash< Key, T >::remove(), and QHash< Key, T >::take().

00442 {
00443 #ifdef Q_CC_BOR
00444     node->~QHashNode<Key, T>();
00445 #elif defined(QT_NO_PARTIAL_TEMPLATE_SPECIALIZATION)
00446     node->~QHashNode();
00447 #else
00448     node->~Node();
00449 #endif
00450     d->freeNode(node);
00451 }

Here is the call graph for this function:

template<class Key, class T>
Q_INLINE_TEMPLATE void QHash< Key, T >::duplicateNode ( QHashData::Node originalNode,
void *  newNode 
) [static, private]

Definition at line 454 of file qhash.h.

References QHash< Key, T >::concrete(), QHashNode< Key, T >::key, and QHashNode< Key, T >::value.

Referenced by QHash< Key, T >::detach_helper().

00455 {
00456     Node *concreteNode = concrete(node);
00457     if (QTypeInfo<T>::isDummy) {
00458         (void) new (newNode) DummyNode(concreteNode->key);
00459     } else {
00460         (void) new (newNode) Node(concreteNode->key, concreteNode->value);
00461     }
00462 }

Here is the call graph for this function:


Friends And Related Function Documentation

template<class Key, class T>
friend class iterator [friend]

Definition at line 328 of file qhash.h.

Referenced by QHash< QString, QTranslator * >::begin(), QMetaObject::changeGuard(), QObjectPrivate::clearGuards(), QHash< QString, QTranslator * >::end(), QHash< Key, T >::erase(), QHash< Key, T >::find(), QHash< Key, T >::insert(), QHash< Key, T >::insertMulti(), QDBusConnectionPrivate::objectDestroyed(), qDBusRemoveWatch(), qDBusToggleWatch(), QConnectionList::removeConnection(), QMetaObject::removeGuard(), and QGLShareRegister::removeShare().

template<class Key, class T>
friend class const_iterator [friend]

Definition at line 395 of file qhash.h.

Referenced by QMetaObject::activate(), QHash< QString, QTranslator * >::begin(), QHash< QString, QTranslator * >::constBegin(), QHash< QString, QTranslator * >::constEnd(), QHash< Key, T >::constFind(), QHash< QString, QTranslator * >::end(), QHash< Key, T >::find(), QGradientCache::getBuffer(), QDBusConnectionPrivate::handleSignal(), QObjectPrivate::isSender(), QObjectPrivate::receiverList(), QObject::sender(), and QObjectPrivate::senderList().

template<class Key, class T>
uint qHash ( char  key  )  [related]

Returns the hash value for key.

Definition at line 40 of file qhash.h.

Referenced by QHash< Key, T >::findNode(), getLock(), qHash(), qt_rcc_compare_hash(), and variantHash().

00040 { return uint(key); }

template<class Key, class T>
uint qHash ( uchar  key  )  [related]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns the hash value for key.

Definition at line 41 of file qhash.h.

00041 { return uint(key); }

template<class Key, class T>
uint qHash ( signed char  key  )  [related]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns the hash value for key.

Definition at line 42 of file qhash.h.

00042 { return uint(key); }

template<class Key, class T>
uint qHash ( ushort  key  )  [related]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns the hash value for key.

Definition at line 43 of file qhash.h.

00043 { return uint(key); }

template<class Key, class T>
uint qHash ( short  key  )  [related]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns the hash value for key.

Definition at line 44 of file qhash.h.

00044 { return uint(key); }

template<class Key, class T>
uint qHash ( uint  key  )  [related]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns the hash value for key.

Definition at line 45 of file qhash.h.

00045 { return key; }

template<class Key, class T>
uint qHash ( int  key  )  [related]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns the hash value for key.

Definition at line 46 of file qhash.h.

00046 { return uint(key); }

template<class Key, class T>
uint qHash ( ulong  key  )  [related]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns the hash value for key.

Definition at line 47 of file qhash.h.

00048 {
00049     if (sizeof(ulong) > sizeof(uint)) {
00050         return uint((key >> (8 * sizeof(uint) - 1)) ^ key);
00051     } else {
00052         return uint(key);
00053     }
00054 }

template<class Key, class T>
uint qHash ( long  key  )  [related]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns the hash value for key.

Definition at line 55 of file qhash.h.

00055 { return qHash(ulong(key)); }

template<class Key, class T>
uint qHash ( quint64  key  )  [related]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns the hash value for key.

Definition at line 56 of file qhash.h.

00057 {
00058     if (sizeof(quint64) > sizeof(uint)) {
00059         return uint((key >> (8 * sizeof(uint) - 1)) ^ key);
00060     } else {
00061         return uint(key);
00062     }
00063 }

template<class Key, class T>
uint qHash ( qint64  key  )  [related]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns the hash value for key.

Definition at line 64 of file qhash.h.

00064 { return qHash(quint64(key)); }

template<class Key, class T>
uint qHash ( QChar  key  )  [related]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns the hash value for key.

Definition at line 65 of file qhash.h.

00065 { return qHash(key.unicode()); }

template<class Key, class T>
uint qHash ( const QByteArray key  )  [related]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns the hash value for key.

Definition at line 41 of file qhash.cpp.

00042 {
00043     const uchar *p = reinterpret_cast<const uchar *>(key.data());
00044     int n = key.size();
00045     uint h = 0;
00046     uint g;
00047 
00048     while (n--) {
00049         h = (h << 4) + *p++;
00050         if ((g = (h & 0xf0000000)) != 0)
00051             h ^= g >> 23;
00052         h &= ~g;
00053     }
00054     return h;
00055 }

template<class Key, class T>
uint qHash ( const QString key  )  [related]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns the hash value for key.

Definition at line 57 of file qhash.cpp.

00058 {
00059     const QChar *p = key.unicode();
00060     int n = key.size();
00061     uint h = 0;
00062     uint g;
00063 
00064     while (n--) {
00065         h = (h << 4) + (*p++).unicode();
00066         if ((g = (h & 0xf0000000)) != 0)
00067             h ^= g >> 23;
00068         h &= ~g;
00069     }
00070     return h;
00071 }

template<class Key, class T>
uint qHash ( const T *  key  )  [related]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns the hash value for key.

Definition at line 73 of file qhash.h.

00074 {
00075     if (sizeof(const T *) > sizeof(uint))
00076         return qHash(reinterpret_cast<quint64>(key));
00077     else
00078         return uint(reinterpret_cast<ulong>(key));
00079 }

template<class Key, class T>
QDataStream & operator<< ( QDataStream out,
const QHash< Key, T > &  hash 
) [related]

Writes the hash hash to stream out.

This function requires the key and value types to implement operator<<().

See also:
{Format of the QDataStream operators}

Definition at line 339 of file qdatastream.h.

00340 {
00341     out << quint32(hash.size());
00342     typename QHash<Key, T>::ConstIterator it = hash.end();
00343     typename QHash<Key, T>::ConstIterator begin = hash.begin();
00344     while (it != begin) {
00345         --it;
00346         out << it.key() << it.value();
00347     }
00348     return out;
00349 }

template<class Key, class T>
QDataStream & operator>> ( QDataStream in,
QHash< Key, T > &  hash 
) [related]

Reads a hash from stream in into hash.

This function requires the key and value types to implement operator>>().

See also:
{Format of the QDataStream operators}

Definition at line 312 of file qdatastream.h.

00313 {
00314     QDataStream::Status oldStatus = in.status();
00315     in.resetStatus();
00316     hash.clear();
00317 
00318     quint32 n;
00319     in >> n;
00320 
00321     for (quint32 i = 0; i < n; ++i) {
00322         if (in.status() != QDataStream::Ok)
00323             break;
00324 
00325         Key k;
00326         T t;
00327         in >> k >> t;
00328         hash.insertMulti(k, t);
00329     }
00330 
00331     if (in.status() != QDataStream::Ok)
00332         hash.clear();
00333     if (oldStatus != QDataStream::Ok)
00334         in.setStatus(oldStatus);
00335     return in;
00336 }


Member Data Documentation

template<class Key, class T>
QHashData* QHash< Key, T >::d [private]

Definition at line 215 of file qhash.h.

Referenced by QHash< QString, QTranslator * >::begin(), QHash< QString, QTranslator * >::capacity(), QHash< QString, QTranslator * >::constBegin(), QHash< QString, QTranslator * >::count(), QHash< Key, T >::createNode(), QHash< Key, T >::deleteNode(), QHash< QString, QTranslator * >::detach(), QHash< Key, T >::detach_helper(), QHash< Key, T >::erase(), QHash< Key, T >::findNode(), QHash< Key, T >::insert(), QHash< Key, T >::insertMulti(), QHash< QString, QTranslator * >::isDetached(), QHash< QString, QTranslator * >::isEmpty(), QHash< Key, T >::operator=(), QHash< Key, T >::operator==(), QHash< Key, T >::operator[](), QHash< QString, QTranslator * >::QHash(), QHash< Key, T >::remove(), QHash< Key, T >::reserve(), QHash< QString, QTranslator * >::setSharable(), QHash< QString, QTranslator * >::size(), QHash< Key, T >::take(), and QHash< QString, QTranslator * >::~QHash().

template<class Key, class T>
QHashNode<Key, T>* QHash< Key, T >::e [private]

Definition at line 216 of file qhash.h.

Referenced by QHash< QString, QTranslator * >::constEnd(), QHash< Key, T >::contains(), QHash< Key, T >::count(), QHash< QString, QTranslator * >::end(), QHash< Key, T >::erase(), QHash< Key, T >::findNode(), QHash< Key, T >::insert(), QHash< Key, T >::operator[](), QHash< Key, T >::remove(), QHash< Key, T >::take(), QHash< Key, T >::value(), and QHash< Key, T >::values().

union { ... } [private]


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 17:56:21 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1