-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoarseGrainedHashSet.h
45 lines (36 loc) · 1.01 KB
/
CoarseGrainedHashSet.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//
// Created by mguzek on 6/2/20.
//
#ifndef HASHSETHTM_COARSEGRAINEDHASHSET_H
#define HASHSETHTM_COARSEGRAINEDHASHSET_H
#include "HashSet.h"
class CoarseGrainedHashSet : public HashSet {
protected:
void resize() override {
rmutex.lock();
HashSet::resize(); //will resize twice if someone beats us to it, but it's not a big issue
rmutex.unlock();
}
public:
explicit CoarseGrainedHashSet(size_t initCapacity = 11) : HashSet{initCapacity} {
}
bool add(int item) override {
rmutex.lock();
bool returnVal = HashSet::add(item);
rmutex.unlock();
return returnVal;
}
bool remove(int item) override {
rmutex.lock();
bool returnVal = HashSet::remove(item);
rmutex.unlock();
return returnVal;
}
bool contains(int item) override {
rmutex.lock();
bool returnVal = HashSet::contains(item);
rmutex.unlock();
return returnVal;
}
};
#endif //HASHSETHTM_COARSEGRAINEDHASHSET_H