Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
RConcurrentHashColl.cxx
Go to the documentation of this file.
3#include <ROOT/TSeq.hxx>
4#include <ROOT/RSha256.hxx>
5
6#include <memory>
7#include <set>
8#include <unordered_map>
9
10namespace std {
11template <>
12struct hash<ROOT::Internal::RConcurrentHashColl::HashValue> {
13 std::size_t operator()(const ROOT::Internal::RConcurrentHashColl::HashValue &key) const noexcept
14 {
15 return key.ShortHash();
16 }
17};
18} // namespace std
19namespace ROOT {
20namespace Internal {
21
22std::ostream &operator<<(std::ostream &os, const RConcurrentHashColl::HashValue &h)
23{
24 auto digest = h.Get();
25 os << digest[0] << "-" << digest[1] << "-" << digest[2] << "-" << digest[3];
26 return os;
27}
28
30{
31 // The cast here is because in the TBuffer ecosystem, the type used is char*
32 Sha256(reinterpret_cast<const unsigned char *>(data), len, fDigest);
33}
34
35struct RHashMap {
36 std::unordered_map<ROOT::Internal::RConcurrentHashColl::HashValue, RUidColl> fHashMap;
37};
38
40 : fHashMap(std::make_unique<RHashMap>()), fRWLock(std::make_unique<ROOT::TRWSpinLock>()){};
41
43
45{
47 auto iter = fHashMap->fHashMap.find(hash);
48 if (iter != fHashMap->fHashMap.end())
49 return &(iter->second);
50 else
51 return nullptr;
52}
53
55{
56 return HashValue(buffer, len);
57}
58
59bool RConcurrentHashColl::Insert(const HashValue &hash, RUidColl &&values) const
60{
62 auto ret = fHashMap->fHashMap.insert({hash, std::move(values)});
63 return ret.second;
64}
65
66} // namespace Internal
67} // namespace ROOT
#define h(i)
Definition RSha256.hxx:106
char * ret
Definition Rotated.cxx:221
TRObject operator()(const T1 &t1) const
bool Insert(const HashValue &hash, RUidColl &&coll) const
If the hash is there, return false.
static HashValue Hash(char *buf, int len)
Return the hash object corresponding to the buffer.
std::unique_ptr< ROOT::TRWSpinLock > fRWLock
const RUidColl * Find(const HashValue &hash) const
Return the collection of UID corresponding to the hash if the hash has already been seen or nullptr o...
std::vector< Int_t > RUidColl
std::ostream & operator<<(std::ostream &os, const RConcurrentHashColl::HashValue &h)
void Sha256(const unsigned char *data, int len, ULong64_t *fDigest)
Definition RSha256.hxx:267
std::unordered_map< ROOT::Internal::RConcurrentHashColl::HashValue, RUidColl > fHashMap