diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-12-03 11:16:18 +0100 |
---|---|---|
committer | Mårten Nordheim <marten.nordheim@qt.io> | 2019-12-05 11:50:32 +0100 |
commit | 7b34da9ef12554025bb4a8f4750e5807cc37f38c (patch) | |
tree | a334544ede1f1946585300b60a50d242fffdf022 /src/corelib/tools/qhash.h | |
parent | 3359b29c99581f52acf033489ad35884a01ccac8 (diff) |
Add QHash::insert(const QHash &other)
As opposed to unite(), this inserts one hash into the other
without duplicating elements.
Change-Id: Ifc786c48f5dc3ab18c29782e73eac3c1a3ef8981
Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/tools/qhash.h')
-rw-r--r-- | src/corelib/tools/qhash.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index 42f8dbd155..89697b1fd1 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -526,6 +526,7 @@ public: const_iterator find(const Key &key) const; const_iterator constFind(const Key &key) const; iterator insert(const Key &key, const T &value); + void insert(const QHash &hash); iterator insertMulti(const Key &key, const T &value); QHash &unite(const QHash &other); @@ -841,6 +842,31 @@ Q_INLINE_TEMPLATE typename QHash<Key, T>::iterator QHash<Key, T>::insert(const K } template <class Key, class T> +Q_INLINE_TEMPLATE void QHash<Key, T>::insert(const QHash &hash) +{ + if (d == hash.d) + return; + + detach(); + + QHashData::Node *i = hash.d->firstNode(); + QHashData::Node *end = reinterpret_cast<QHashData::Node *>(hash.e); + while (i != end) { + Node *n = concrete(i); + Node **node = findNode(n->key, n->h); + if (*node == e) { + if (d->willGrow()) + node = findNode(n->key, n->h); + createNode(n->h, n->key, n->value, node); + } else { + if (!std::is_same<T, QHashDummyValue>::value) + (*node)->value = n->value; + } + i = QHashData::nextNode(i); + } +} + +template <class Key, class T> Q_INLINE_TEMPLATE typename QHash<Key, T>::iterator QHash<Key, T>::insertMulti(const Key &akey, const T &avalue) { |