77
88#include < cassert>
99#include < cstddef>
10+ #include < cstdint>
1011
1112namespace ROOT {
1213namespace Experimental {
@@ -20,21 +21,25 @@ Objects of this type should be passed by value.
2021Feedback is welcome!
2122*/
2223class RBinIndex final {
23- static constexpr std::size_t UnderflowIndex = -3 ;
24- static constexpr std::size_t OverflowIndex = -2 ;
25- static constexpr std::size_t InvalidIndex = -1 ;
24+ static constexpr std::uint64_t UnderflowIndex = -3 ;
25+ static constexpr std::uint64_t OverflowIndex = -2 ;
26+ static constexpr std::uint64_t InvalidIndex = -1 ;
2627
27- std::size_t fIndex = InvalidIndex;
28+ // We use std::uint64_t instead of std::size_t for the index because for sparse histograms, not all bins have to be
29+ // allocated in memory. However, we require that the index has at least that size.
30+ static_assert (sizeof (std::uint64_t ) >= sizeof (std::size_t ), " index type not large enough to address all bins" );
31+
32+ std::uint64_t fIndex = InvalidIndex;
2833
2934public:
3035 // / Construct an invalid bin index.
3136 RBinIndex () = default ;
3237
3338 // / Construct a bin index for a normal bin.
34- RBinIndex (std::size_t index) : fIndex (index) { assert (IsNormal ()); }
39+ RBinIndex (std::uint64_t index) : fIndex (index) { assert (IsNormal ()); }
3540
3641 // / Return the index for a normal bin.
37- std::size_t GetIndex () const
42+ std::uint64_t GetIndex () const
3843 {
3944 assert (IsNormal ());
4045 return fIndex ;
@@ -48,13 +53,13 @@ public:
4853 bool IsOverflow () const { return fIndex == OverflowIndex; }
4954 bool IsInvalid () const { return fIndex == InvalidIndex; }
5055
51- RBinIndex &operator +=(std::size_t a)
56+ RBinIndex &operator +=(std::uint64_t a)
5257 {
5358 if (!IsNormal ()) {
5459 // Arithmetic operations on special values go to InvalidIndex.
5560 fIndex = InvalidIndex;
5661 } else {
57- std::size_t old = fIndex ;
62+ std::uint64_t old = fIndex ;
5863 fIndex += a;
5964 if (fIndex < old || !IsNormal ()) {
6065 // The addition wrapped around, go to InvalidIndex.
@@ -64,7 +69,7 @@ public:
6469 return *this ;
6570 }
6671
67- RBinIndex operator +(std::size_t a) const
72+ RBinIndex operator +(std::uint64_t a) const
6873 {
6974 RBinIndex ret = *this ;
7075 ret += a;
@@ -84,7 +89,7 @@ public:
8489 return old;
8590 }
8691
87- RBinIndex &operator -=(std::size_t a)
92+ RBinIndex &operator -=(std::uint64_t a)
8893 {
8994 if (!IsNormal ()) {
9095 // Arithmetic operations on special values go to InvalidIndex.
@@ -98,7 +103,7 @@ public:
98103 return *this ;
99104 }
100105
101- RBinIndex operator -(std::size_t a) const
106+ RBinIndex operator -(std::uint64_t a) const
102107 {
103108 RBinIndex ret = *this ;
104109 ret -= a;
0 commit comments