proxygen
Counters Class Reference

Public Member Functions

 Counters (size_t numCounters)
 
void increment (int64_t obj_id)
 
int64_t getValue (int64_t obj_id)
 
string toString ()
 

Private Attributes

AtomicHashMap< int64_t, int64_tahm
 

Detailed Description

Definition at line 266 of file AtomicHashMapTest.cpp.

Constructor & Destructor Documentation

Counters::Counters ( size_t  numCounters)
inlineexplicit

Definition at line 274 of file AtomicHashMapTest.cpp.

274 : ahm(numCounters) {}
AtomicHashMap< int64_t, int64_t > ahm

Member Function Documentation

int64_t Counters::getValue ( int64_t  obj_id)
inline

Definition at line 284 of file AtomicHashMapTest.cpp.

References folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::end(), and folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::find().

Referenced by TEST().

284  {
285  auto ret = ahm.find(obj_id);
286  return ret != ahm.end() ? ret->second : 0;
287  }
iterator find(LookupKeyT k)
AtomicHashMap< int64_t, int64_t > ahm
void Counters::increment ( int64_t  obj_id)
inline

Definition at line 276 of file AtomicHashMapTest.cpp.

References folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::insert().

Referenced by TEST().

276  {
277  auto ret = ahm.insert(std::make_pair(obj_id, 1));
278  if (!ret.second) {
279  // obj_id already exists, increment count
280  __sync_fetch_and_add(&ret.first->second, 1);
281  }
282  }
AtomicHashMap< int64_t, int64_t > ahm
std::pair< iterator, bool > insert(const value_type &r)
string Counters::toString ( )
inline

Definition at line 290 of file AtomicHashMapTest.cpp.

References folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::size().

Referenced by TEST().

290  {
291  string ret = "{\n";
292  ret.reserve(ahm.size() * 32);
293  for (const auto& e : ahm) {
294  ret += folly::to<string>(" [", e.first, ":", e.second, "]\n");
295  }
296  ret += "}\n";
297  return ret;
298  }
AtomicHashMap< int64_t, int64_t > ahm

Member Data Documentation

AtomicHashMap<int64_t, int64_t> Counters::ahm
private

Definition at line 271 of file AtomicHashMapTest.cpp.


The documentation for this class was generated from the following file: