6.0.0-rc4Source

QMultiHash Class

template <typename K, typename V> class QMultiHash

The QMultiHash class is a template class that provides a hash-table-based multi-valued dictionary. More…

Header#include <QMultiHash>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes
InheritsQtPrivate::AssocContainer

List of all members, including inherited members

Public Functions

QMultiHash()
voidreserve(qsizetype n)
qsizetypecapacity() const
voidsqueeze()
std::size_tbucket_count() const
std::size_tmax_bucket_count() const
floatload_factor() const
floatmax_load_factor() const
QList<K>uniqueKeys() const

Detailed Description

QMultiHash<Key, T> is like QHash, but insert() always adds a new item, so several values can be stored under the same key. values(key) returns all values stored under a key, and count(key) returns how many there are.

QMultiHash<QString, int> hash;
hash.insert("a", 1);
hash.insert("a", 2);
qsizetype n = hash.count("a"); // 2

See also QHash and QMultiMap.

Differences from Qt

QMultiHash is implemented on top of std::unordered_multimap and is not implicitly shared. The order of values stored under one key is not specified.

Member Function Documentation

QMultiHash::QMultiHash()

Constructs an empty multi-hash.

std::size_t QMultiHash::bucket_count() const

Returns the number of buckets in the hash table. Provided for compatibility with the standard library.

See also capacity() and load_factor().

qsizetype QMultiHash::capacity() const

Returns the number of buckets in the hash table.

See also reserve() and squeeze().

float QMultiHash::load_factor() const

Returns the average number of items per bucket.

See also max_load_factor() and bucket_count().

std::size_t QMultiHash::max_bucket_count() const

Returns the largest number of buckets the hash table can have.

See also bucket_count().

float QMultiHash::max_load_factor() const

Returns the load factor above which the hash table grows.

See also load_factor().

void QMultiHash::reserve(qsizetype n)

Prepares the hash for holding at least n items without rehashing.

void QMultiHash::squeeze()

Shrinks the hash table to the smallest size that holds the items.

See also capacity().

QList<K> QMultiHash::uniqueKeys() const

Returns the keys of the hash, each key listed once even if it has several values. The order of the keys is unspecified.