mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
HashTable: Added C++11 initializer_list constructor
e.g.
HashTable<label, string> table1
{
{"kjhk", 10},
{"kjhk2", 12}
};
HashTable<label, label, Hash<label>> table2
{
{3, 10},
{5, 12},
{7, 16}
};
This commit is contained in:
@ -28,6 +28,7 @@ License
|
||||
|
||||
#include "HashTable.H"
|
||||
#include "List.H"
|
||||
#include "Tuple2.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
@ -54,27 +55,15 @@ Foam::HashTable<T, Key, Hash>::HashTable(const label size)
|
||||
template<class T, class Key, class Hash>
|
||||
Foam::HashTable<T, Key, Hash>::HashTable(const HashTable<T, Key, Hash>& ht)
|
||||
:
|
||||
HashTableCore(),
|
||||
nElmts_(0),
|
||||
tableSize_(ht.tableSize_),
|
||||
table_(nullptr)
|
||||
HashTable<T, Key, Hash>(ht.tableSize_)
|
||||
{
|
||||
if (tableSize_)
|
||||
for (const_iterator iter = ht.cbegin(); iter != ht.cend(); ++iter)
|
||||
{
|
||||
table_ = new hashedEntry*[tableSize_];
|
||||
|
||||
for (label hashIdx = 0; hashIdx < tableSize_; hashIdx++)
|
||||
{
|
||||
table_[hashIdx] = 0;
|
||||
}
|
||||
|
||||
for (const_iterator iter = ht.cbegin(); iter != ht.cend(); ++iter)
|
||||
{
|
||||
insert(iter.key(), *iter);
|
||||
}
|
||||
insert(iter.key(), *iter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Key, class Hash>
|
||||
Foam::HashTable<T, Key, Hash>::HashTable
|
||||
(
|
||||
@ -90,6 +79,21 @@ Foam::HashTable<T, Key, Hash>::HashTable
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Key, class Hash>
|
||||
Foam::HashTable<T, Key, Hash>::HashTable
|
||||
(
|
||||
std::initializer_list<Tuple2<Key, T>> lst
|
||||
)
|
||||
:
|
||||
HashTable<T, Key, Hash>(lst.size())
|
||||
{
|
||||
for (const Tuple2<Key, T>& pair : lst)
|
||||
{
|
||||
insert(pair.first(), pair.second());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class T, class Key, class Hash>
|
||||
|
||||
Reference in New Issue
Block a user