Binned counts of data. More...
#include <FixedBins.h>
Public Types | |
using | Data_t = T |
Type on the bin axis. More... | |
using | Count_t = C |
Type on the bin content. More... | |
using | Interval_t = decltype(std::declval< T >()-std::declval< T >()) |
Type of interval in on the bin axis. More... | |
using | BinIndex_t = std::ptrdiff_t |
Type of bin index. More... | |
Public Member Functions | |
FixedBins (Interval_t width, Data_t offset=Data_t{}) noexcept | |
Constructor: initializes the binning. More... | |
Content modification | |
BinIndex_t | add (Data_t value) |
Increases by a unit the count at the bin including value . More... | |
void | clear () noexcept |
Resets all counts to 0 . More... | |
Query interface | |
std::size_t | nBins () const noexcept |
Returns how many bins currently have storage. More... | |
bool | empty () const noexcept |
Returns whether there is no storage at all. More... | |
Interval_t | binWidth () const noexcept |
Returns the width of the bins. More... | |
Data_t | offset () const noexcept |
Returns the alignment offset of the bins. More... | |
Data_t | lowerEdge (BinIndex_t index) const noexcept |
Data_t | upperEdge (BinIndex_t index) const noexcept |
BinIndex_t | binWith (Data_t value) const noexcept |
Returns the index of the bin including the specified value . More... | |
Interval_t | range () const noexcept |
BinIndex_t | minBin () const noexcept |
BinIndex_t | maxBin () const noexcept |
Data_t | min () const noexcept |
Data_t | max () const noexcept |
Count_t | count (BinIndex_t index) const noexcept |
Returns the count of the bin with the specified index . More... | |
Count_t | countFor (Data_t value) const noexcept |
Returns the count of the bin including the specified value . More... | |
Count_t | operator[] (BinIndex_t index) const noexcept |
Returns the count of the bin with the specified index . More... | |
std::size_t | size () const noexcept |
Returns the number of bins with storage. More... | |
auto | cbegin () const noexcept |
Returns an iterator pointing to the content of the first bin with storage. More... | |
auto | begin () const noexcept |
Returns an iterator pointing to the content of the first bin with storage. More... | |
auto | cend () const noexcept |
Returns an iterator pointing to the content of the first bin with storage. More... | |
auto | end () const noexcept |
Returns an iterator pointing to the content of the first bin with storage. More... | |
Private Types | |
using | Storage_t = std::vector< Count_t > |
Type of storage for bin counts. More... | |
Private Member Functions | |
std::ptrdiff_t | storageIndex (BinIndex_t index) const noexcept |
Returns the index in the data storage corresponding to bin index . More... | |
bool | hasStorageIndex (std::ptrdiff_t stIndex) const noexcept |
Returns whether the specified stotage index is available. More... | |
BinIndex_t | relativeBinIndex (Data_t value, Data_t ref) const noexcept |
Returns the number of bins passing from ref to value . More... | |
std::size_t | initializeWith (Data_t value) |
std::size_t | allocateBin (BinIndex_t index) |
Private Attributes | |
Data_t | fWidth |
Bin width. More... | |
Data_t | fOffset |
Bin offset from 0 . More... | |
Storage_t | fCounters |
Bin counters. More... | |
Data_t | fMin |
The lower edge of the bin with storage index 0. More... | |
BinIndex_t | fMinBin |
The index of bin fCounters[0] . More... | |
Static Private Attributes | |
static constexpr Count_t | CountZero = 0 |
Starting value of a counter, and ending value of a trilogy. More... | |
Binned counts of data.
T | type of data on the binning axis |
C | (default: unsigned int ) data type for the bin count |
A FixedBin
object holds binned counts with a binning of a fixed size and alignment. For example, an object set to have 2
-wide bins aligned to -1
will hold counts with bins -3
to -1
, -1
to 1
, 1
to 3` etc. The lower edge of the bin is included in it, while the upper edge is not.
The lowest and highest limits of the binning are not fixed. As data isadd()
-ed to the object, new bins are allocated if needed, and the storage of counts is contiguous. For example, in the example above if the first added datum is +2
, the bin 1
to 3
is allocated and given a count of 1
. At this point there is only one bin with storage. If 6
is added next, the storage is extended to cover also bins 3
to 5
and 5
to 7
, and they will be assigned counts of 0
and 1
respectively. At this point, there is storage for three bins, one of them being empty.
The query interface does report which is the first bin with storage (supposedly the first non-empty bin) and which is the last one. Bin content can be asked for any value and any bin.
Currently the modification interface is very limited: the only way to add entries to the bins is one by one by value (add()
), and the only other supported modifying action is to empty all the content (clear()
).
The bin index is of type ptrdiff_t
.
FixedBins
itself (binWith()
, minBin()
, etc.), since its specific value is an implementation detail that may change. Definition at line 25 of file FixedBins.h.
using icarus::ns::util::FixedBins< T, C >::BinIndex_t = std::ptrdiff_t |
Type of bin index.
Definition at line 91 of file FixedBins.h.
using icarus::ns::util::FixedBins< T, C >::Count_t = C |
Type on the bin content.
Definition at line 86 of file FixedBins.h.
using icarus::ns::util::FixedBins< T, C >::Data_t = T |
Type on the bin axis.
Definition at line 84 of file FixedBins.h.
using icarus::ns::util::FixedBins< T, C >::Interval_t = decltype(std::declval<T>() - std::declval<T>()) |
Type of interval in on the bin axis.
Definition at line 89 of file FixedBins.h.
|
private |
Type of storage for bin counts.
Definition at line 269 of file FixedBins.h.
|
explicitnoexcept |
Constructor: initializes the binning.
width | the bin width |
offset | (default: 0) the border of one of the bins |
This constructor prepares the object to host counts in bins of the specified width
. Optionally, the bins are aligned to the offset
value instead than to 0
(or, more precisely, the value of a default-constructed Data_t
).
No memory is allocated just yet.
Definition at line 329 of file FixedBins.h.
auto icarus::ns::util::FixedBins< T, C >::add | ( | Data_t | value | ) |
Increases by a unit the count at the bin including value
.
value | the value to be accounted for |
value
. Definition at line 338 of file FixedBins.h.
|
private |
Ensures the bin with the specified index
exists and returns its storage index. Requires some storage to exist already.
Definition at line 522 of file FixedBins.h.
|
noexcept |
Returns an iterator pointing to the content of the first bin with storage.
Definition at line 464 of file FixedBins.h.
|
noexcept |
|
noexcept |
Returns the index of the bin including the specified value
.
value | the value that the queried bin must contain |
count()
, countFor()
Definition at line 392 of file FixedBins.h.
|
noexcept |
Returns an iterator pointing to the content of the first bin with storage.
Definition at line 458 of file FixedBins.h.
|
noexcept |
Returns an iterator pointing to the content of the first bin with storage.
Definition at line 470 of file FixedBins.h.
|
noexcept |
Resets all counts to 0
.
All the storage is removed from the object (although depending on the STL implementation its memory might still be allocated).
Definition at line 349 of file FixedBins.h.
|
noexcept |
Returns the count of the bin with the specified index
.
index | the index of the bin to be queried |
index
operator[]()
, countFor()
If the specified bin has no storage, the returned count is 0
.
Definition at line 428 of file FixedBins.h.
|
noexcept |
Returns the count of the bin including the specified value
.
value | the value that the queried bin must contain |
operator[]()
, count()
, binWith()
If the bin with the specified value has no storage, the returned count is 0
.
Definition at line 438 of file FixedBins.h.
|
noexcept |
|
noexcept |
Returns an iterator pointing to the content of the first bin with storage.
Definition at line 476 of file FixedBins.h.
|
privatenoexcept |
Returns whether the specified stotage index is available.
Definition at line 490 of file FixedBins.h.
|
private |
Initializes the storage to host a single bin including value
.
0
) Definition at line 509 of file FixedBins.h.
|
noexcept |
index
This value always belongs to the bin index
.
Definition at line 379 of file FixedBins.h.
|
noexcept |
The return value is undefined if empty()
is true
(i.e. if no storage is allocated yet).
Definition at line 422 of file FixedBins.h.
|
noexcept |
This value can be the same as minBin()
if only one bin is stored.
The return value is undefined if empty()
is true
(i.e. if no storage is allocated yet).
Definition at line 410 of file FixedBins.h.
|
noexcept |
The return value is undefined if empty()
is true
(i.e. if no storage is allocated yet).
Definition at line 416 of file FixedBins.h.
|
noexcept |
The return value is undefined if empty()
is true
(i.e. if no storage is allocated yet).
Definition at line 405 of file FixedBins.h.
|
noexcept |
|
noexcept |
Returns the alignment offset of the bins.
One bin is guaranteed to have its lowerEdge()
at the value returned by offset()
.
Definition at line 372 of file FixedBins.h.
|
noexcept |
Returns the count of the bin with the specified index
.
index | the index of the bin to be queried |
index
count()
If the specified bin has no storage, the returned count is 0
.
Definition at line 446 of file FixedBins.h.
|
noexcept |
Equivalent to max() - min()
and nBins() * binWidth()
.
Definition at line 399 of file FixedBins.h.
|
privatenoexcept |
Returns the number of bins passing from ref
to value
.
Definition at line 500 of file FixedBins.h.
|
noexcept |
Returns the number of bins with storage.
Definition at line 452 of file FixedBins.h.
|
privatenoexcept |
Returns the index in the data storage corresponding to bin index
.
Definition at line 483 of file FixedBins.h.
|
noexcept |
index
Note that this value always belongs to the bin index + 1
.
Definition at line 386 of file FixedBins.h.
|
staticprivate |
Starting value of a counter, and ending value of a trilogy.
Definition at line 272 of file FixedBins.h.
|
private |
Bin counters.
Definition at line 278 of file FixedBins.h.
|
private |
The lower edge of the bin with storage index 0.
Definition at line 279 of file FixedBins.h.
|
private |
The index of bin fCounters[0]
.
Definition at line 280 of file FixedBins.h.
|
private |
Bin offset from 0
.
Definition at line 276 of file FixedBins.h.
|
private |
Bin width.
Definition at line 275 of file FixedBins.h.