Logo ROOT  
Reference Guide
RConcurrentHashColl.hxx
Go to the documentation of this file.
1 // Author: Danilo Piparo May 2018
2 
3 /*************************************************************************
4  * Copyright (C) 1995-2018, Rene Brun and Fons Rademakers. *
5  * All rights reserved. *
6  * *
7  * For the licensing terms see $ROOTSYS/LICENSE. *
8  * For the list of contributors see $ROOTSYS/README/CREDITS. *
9  *************************************************************************/
10 
11 #ifndef ROOT_RConcurrentHashColl
12 #define ROOT_RConcurrentHashColl
13 
14 #include <memory>
15 #include "Rtypes.h"
16 
17 namespace ROOT {
18 
19 class TRWSpinLock;
20 
21 namespace Internal {
22 
23 struct RHashSet;
24 
25 /// This class is a TS set of unsigned set
26 class RConcurrentHashColl {
27 private:
28  mutable std::unique_ptr<RHashSet> fHashSet;
29  mutable std::unique_ptr<ROOT::TRWSpinLock> fRWLock;
30 
31 public:
32  class HashValue {
33  friend std::ostream &operator<<(std::ostream &os, const RConcurrentHashColl::HashValue &h);
34  private:
35  ULong64_t fDigest[4] = {0, 0, 0, 0};
36 
37  public:
38  HashValue() = default;
39  HashValue(const char *data, int len);
40  ULong64_t const *Get() const { return fDigest; }
41  };
42 
45 
46  /// Return true if the hash is already in already there
47  bool Find(const HashValue &hash) const;
48 
49  /// If the hash is there, return false. Otherwise, insert the hash and return true;
50  bool Insert(char *buf, int len) const;
51 
52  /// If the hash is there, return false. Otherwise, insert the hash and return true;
53  bool Insert(const HashValue &hash) const;
54 
55  /// Return the hash object corresponding to the buffer.
56  static HashValue Hash(char *buf, int len);
57 };
58 
60 {
61  auto l = lhs.Get();
62  auto r = rhs.Get();
63  return l[0] == r[0] && l[1] == r[1] && l[2] == r[2] && l[3] == r[3];
64 }
65 
66 } // End NS Internal
67 } // End NS ROOT
68 
69 namespace std {
70 template <>
71 struct less<ROOT::Internal::RConcurrentHashColl::HashValue> {
73  {
74  /// Check piece by piece the 4 64 bits ints which make up the hash.
75  auto l = lhs.Get();
76  auto r = rhs.Get();
77  // clang-format off
78  return l[0] < r[0] ? true :
79  l[0] > r[0] ? false :
80  l[1] < r[1] ? true :
81  l[1] > r[1] ? false :
82  l[2] < r[2] ? true :
83  l[2] > r[2] ? false :
84  l[3] < r[3] ? true : false;
85  // clang-format on
86  }
87 };
88 } // End NS std
89 
90 #endif
l
auto * l
Definition: textangle.C:4
ROOT::Internal::RConcurrentHashColl::fRWLock
std::unique_ptr< ROOT::TRWSpinLock > fRWLock
Definition: RConcurrentHashColl.hxx:35
ROOT::Internal::RConcurrentHashColl::HashValue::fDigest
ULong64_t fDigest[4]
Definition: RConcurrentHashColl.hxx:41
ROOT::Internal::RConcurrentHashColl::fHashSet
std::unique_ptr< RHashSet > fHashSet
Definition: RConcurrentHashColl.hxx:34
r
ROOT::R::TRInterface & r
Definition: Object.C:4
ROOT::Internal::RConcurrentHashColl::Hash
static HashValue Hash(char *buf, int len)
Return the hash object corresponding to the buffer.
Definition: RConcurrentHashColl.cxx:43
operator()
TRObject operator()(const T1 &t1) const
Definition: TRFunctionImport__oprtr.h:14
h
#define h(i)
Definition: RSha256.hxx:124
ROOT::Internal::RConcurrentHashColl::HashValue::HashValue
HashValue()=default
ROOT::Internal::RConcurrentHashColl::Find
bool Find(const HashValue &hash) const
Return true if the hash is already in already there.
Definition: RConcurrentHashColl.cxx:36
ROOT::Internal::RConcurrentHashColl::~RConcurrentHashColl
~RConcurrentHashColl()
ULong64_t
unsigned long long ULong64_t
Definition: RtypesCore.h:74
ROOT::Internal::RConcurrentHashColl::Insert
bool Insert(char *buf, int len) const
If the hash is there, return false. Otherwise, insert the hash and return true;.
Definition: RConcurrentHashColl.cxx:49
ROOT::Internal::operator==
bool operator==(const RConcurrentHashColl::HashValue &lhs, const RConcurrentHashColl::HashValue &rhs)
Definition: RConcurrentHashColl.hxx:65
ROOT::Internal::RConcurrentHashColl::RConcurrentHashColl
RConcurrentHashColl()
Definition: RConcurrentHashColl.cxx:30
ROOT::Internal::RConcurrentHashColl::HashValue::operator<<
friend std::ostream & operator<<(std::ostream &os, const RConcurrentHashColl::HashValue &h)
Definition: RConcurrentHashColl.cxx:13
ROOT::Internal::RConcurrentHashColl::HashValue::Get
const ULong64_t * Get() const
Definition: RConcurrentHashColl.hxx:46
Rtypes.h
ROOT
VSD Structures.
Definition: StringConv.hxx:21
ROOT::Internal::RConcurrentHashColl::HashValue
Definition: RConcurrentHashColl.hxx:38