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 "Rtypes.h"
17
18namespace ROOT {
19
20class TRWSpinLock;
21
22namespace Internal {
23
24struct RHashMap;
25using RUidColl = std::vector<Int_t>;
26
27/// This class is a thread-safe associative collection connecting
28/// a 256 bits digest/hash to a collection of uid (integer)
29/// This is used in the handling of the StreamerInfo record in TFile.
31private:
32 mutable std::unique_ptr<RHashMap> fHashMap;
33 mutable std::unique_ptr<ROOT::TRWSpinLock> fRWLock;
34
35public:
36 class HashValue {
37 friend std::ostream &operator<<(std::ostream &os, const RConcurrentHashColl::HashValue &h);
38 private:
39 ULong64_t fDigest[4] = {0, 0, 0, 0};
40
41 public:
42 HashValue() = default;
43 HashValue(const char *data, int len);
44 ULong64_t const *Get() const { return fDigest; }
45
46 /// Return the hash value for this object
47 size_t Hash() const noexcept {
48 std::hash<ULong64_t> hasher;
49 return hasher(fDigest[0]) ^ hasher(fDigest[1])
50 ^ hasher(fDigest[2]) ^ hasher(fDigest[3]);
51 }
52 };
53
56
57 /// Return true if the hash is already in already there
58 const RUidColl *Find(const HashValue &hash) const;
59
60 /// If the hash is there, return false. Otherwise, insert the hash and return true;
61 bool Insert(const HashValue &hash, RUidColl &&coll) const;
62
63 /// Return the hash object corresponding to the buffer.
64 static HashValue Hash(char *buf, int len);
65};
66
68{
69 auto l = lhs.Get();
70 auto r = rhs.Get();
71 return l[0] == r[0] && l[1] == r[1] && l[2] == r[2] && l[3] == r[3];
72}
73
74} // End NS Internal
75} // End NS ROOT
76
77namespace std {
78template <>
79struct less<ROOT::Internal::RConcurrentHashColl::HashValue> {
81 {
82 /// Check piece by piece the 4 64 bits ints which make up the hash.
83 auto l = lhs.Get();
84 auto r = rhs.Get();
85 // clang-format off
86 return l[0] < r[0] ? true :
87 l[0] > r[0] ? false :
88 l[1] < r[1] ? true :
89 l[1] > r[1] ? false :
90 l[2] < r[2] ? true :
91 l[2] > r[2] ? false :
92 l[3] < r[3] ? true : false;
93 // clang-format on
94 }
95};
96} // End NS std
97
98#endif
#define h(i)
Definition RSha256.hxx:106
unsigned long long ULong64_t
Definition RtypesCore.h:81
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. Otherwise, insert the hash and return true;.
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 true if the hash is already in already there.
An implementation of a read-write lock with an internal spin lock.
bool operator==(const RConcurrentHashColl::HashValue &lhs, const RConcurrentHashColl::HashValue &rhs)
std::vector< Int_t > RUidColl
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
TLine l
Definition textangle.C:4