8 #ifndef Sawyer_Container_Tracker_H
9 #define Sawyer_Container_Tracker_H
11 #include <Sawyer/Set.h>
12 #include <Sawyer/Synchronization.h>
28 bool exists(
const Key &key)
const {
29 return set.exists(key);
31 bool insert(
const Key &key) {
32 return set.insert(key);
42 std::vector<bool> bvec;
47 bool exists(
const Key &key)
const {
48 return key < bvec.size() && bvec[key];
50 bool insert(
const Key &key) {
51 bool retval = !exists(key);
52 if (key >= bvec.size())
53 bvec.resize(key+1,
false);
65 boost::unordered_set<Key> set;
70 bool exists(
const Key &key)
const {
71 return set.find(key) != set.end();
73 bool insert(
const Key &key) {
74 return set.insert(key).second;
164 template<
class T,
class K = T,
class Traits = TrackerTraits<K> >
176 mutable SAWYER_THREAD_TRAITS::Mutex mutex_;
177 typename Traits::Index index_;
184 SAWYER_THREAD_TRAITS::LockGuard lock(mutex_);
195 SAWYER_THREAD_TRAITS::LockGuard lock(mutex_);
196 return !index_.insert(key);
211 SAWYER_THREAD_TRAITS::LockGuard lock(mutex_);
212 return index_.exists(key);
247 for (
size_t i = 0; i < vector.size(); ++i) {
249 vector[nSaved++] = vector[i];
251 vector.resize(nSaved);
bool insert(const Value &value)
Cause this tracker to see a value.
void clear()
Make this tracker forget everything it has seen.
bool operator()(const Value &value)
Unary operator is the same as testAndSet.
Set-based index referenced by TrackerTraits.
bool testAndSet(const Value &value)
Test and then insert the value.
T Value
Type of values represented by the tracker.
bool wasSeen(const Value &value) const
Test whether a value has been encountered previously.
Tracks whether something has been seen before.
Name space for the entire library.
void removeIfSeen(std::vector< Value > &vector)
Remove and track items from a vector.
Hash-based index referenced by TrackerTraits.
K Key
Key type for the values represented by the tracker.
Vector-based index referenced by TrackerTraits.
TrackerSetIndex< Key > Index
Type of index for storing member keys.