Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
2472 Discussions

Concurrent hash map. Problems with accessor and iterator

Adri_C__S_
Beginner
878 Views
Hi,
I was trying to make a class HashArray, which will act as an "envelope" for the tbb::concurrent_hash_map.

However, I have problems with the accessor and the iterators of the concurrent map.
It seems that the accessors in DoSomething() are not recognised, as well as the iterator in GatherStats().
Here's the code:

[cpp]#ifndef TBB_HashArray_h
#define TBB_HashArray_h

#include "tbb/concurrent_hash_map.h"
#include

namespace mcl {

template
struct HashCompare {
static size_t hash( const K& key ) {
return tbb::tbb_hasher(key);
}

static bool equal( const K& key1, const K& key2 ) {
return ( key1 == key2 );
}
};

template
class HashArray {
private:
static unsigned int initial_hash_size;
tbb::concurrent_hash_map > h;

HashArray(const HashArray& S);
const HashArray& operator=(const HashArray& S);
public:
HashArray(): h(initial_hash_size) {}
~HashArray() {}
bool DoSomething(const K& key) {
tbb::concurrent_hash_map >::accessor a;
h.insert(a,key);
return true;
}
const bool DoSomething (const K& key) const {
tbb::concurrent_hash_map >::const_accessor a;
h.insert(a,key);
return true;
}
bool IsDefined(const K key) const { return h.count(key)!=0; }
void UnDefine(const K key) { h.erase(key); }
void GatherStats() const {
tbb::concurrent_hash_map >::const_iterator it = h.begin();
while ( it != h.end() ) {
//std::cout << ((*it).second).size() << std::endl;
++it;
}
}
void Clear(void) { h.clear(); }
void Resize(void) { h.clear(); }
};

template
unsigned int HashArray::initial_hash_size=1000;
}

#endif[/cpp]

Thanks!
0 Kudos
3 Replies
Adri_C__S_
Beginner
878 Views
Hi again,

it seems that the problem is the use of templates. If I use
tbb::concurrent_hash_map>::accessor a
when compiling I get an error:
error: expected `;' before a

However, if for example I write
tbb::concurrent_hash_map<:STRING>>::accessor a

when compiling that error disappears.

But I need to use templates... any idea? I'm in blank.

Thanks!
0 Kudos
Ilnar
Beginner
878 Views
try to write:
tbb::template concurrent_hash_map>::const_accessora;
or
tbb::template concurrent_hash_map>::const_accessora;
or
typename tbb::template concurrent_hash_map>::const_accessora;
or
typename tbb::template concurrent_hash_map>::const_accessora;
0 Kudos
Adri_C__S_
Beginner
878 Views
Yes. It worked well with typename.

Thanks ilnarb.
0 Kudos
Reply