Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 <vector>
16#include <functional>
17#include "Rtypes.h"
18
19namespace ROOT {
20
21class TRWSpinLock;
22
23namespace Internal {
24
25struct RHashMap;
26using RUidColl = std::vector<Int_t>;
27
28/// This class is a thread-safe associative collection connecting
29/// a 256 bits digest/hash to a collection of uid (integer)
30/// This is used in the handling of the StreamerInfo record in TFile.
32private:
33 mutable std::unique_ptr<RHashMap> fHashMap;
34 mutable std::unique_ptr<ROOT::TRWSpinLock> fRWLock;
35
36public:
37 class HashValue {
38 friend std::ostream &operator<<(std::ostream &os, const RConcurrentHashColl::HashValue &h);
39 private:
40 ULong64_t fDigest[4] = {0, 0, 0, 0};
41
42 public:
43 HashValue() = default;
44 HashValue(const char *data, int len);
45 ULong64_t const *Get() const { return fDigest; }
46
47 /// Return the hash value for this object
48 size_t Hash() const noexcept {
49 std::hash<ULong64_t> hasher;
50 return hasher(fDigest[0]) ^ hasher(fDigest[1])
51 ^ hasher(fDigest[2]) ^ hasher(fDigest[3]);
52 }
53 };
54
57
58 /// Return the collection of UID corresponding to the hash if the hash has
59 /// already been seen or nullptr otherwise.
60 const RUidColl *Find(const HashValue &hash) const;
61
62 /// If the hash is there, return false. Otherwise, insert the hash and UID
63 /// collection and return true.
64 bool Insert(const HashValue &hash, RUidColl &&coll) const;
65
66 /// Return the hash object corresponding to the buffer.
67 static HashValue Hash(char *buf, int len);
68};
69
71{
72 auto l = lhs.Get();
73 auto r = rhs.Get();
74 return l[0] == r[0] && l[1] == r[1] && l[2] == r[2] && l[3] == r[3];
75}
76
77} // End NS Internal
78} // End NS ROOT
79
80namespace std {
81template <>
82struct less<ROOT::Internal::RConcurrentHashColl::HashValue> {
84 {
85 /// Check piece by piece the 4 64 bits ints which make up the hash.
86 auto l = lhs.Get();
87 auto r = rhs.Get();
88 // clang-format off
89 return l[0] < r[0] ? true :
90 l[0] > r[0] ? false :
91 l[1] < r[1] ? true :
92 l[1] > r[1] ? false :
93 l[2] < r[2] ? true :
94 l[2] > r[2] ? false :
95 l[3] < r[3] ? true : false;
96 // clang-format on
97 }
98};
99} // End NS std
100
101#endif
#define h(i)
Definition RSha256.hxx:106
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
TRObject operator()(const T1 &t1) const
friend std::ostream & operator<<(std::ostream &os, const RConcurrentHashColl::HashValue &h)
size_t Hash() const noexcept
Return the hash value for this object.
This class is a thread-safe associative collection connecting a 256 bits digest/hash to a collection ...
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...
An implementation of a read-write lock with an internal spin lock.
std::vector< Int_t > RUidColl
bool operator==(const RConcurrentHashColl::HashValue &lhs, const RConcurrentHashColl::HashValue &rhs)
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
TLine l
Definition textangle.C:4