Class AdaptingCircularBufferCounter

Class Documentation

class AdaptingCircularBufferCounter

A circle-buffer-backed exponential counter.

The first recorded value becomes the ‘base_index’. Going backwards leads to start/stop index.

This expand start/end index as it sees values.

This class is NOT thread-safe. It is expected to be behind a synchronized incrementer.

Public Functions

inline explicit AdaptingCircularBufferCounter(size_t max_size)
AdaptingCircularBufferCounter(const AdaptingCircularBufferCounter &other) = default
AdaptingCircularBufferCounter(AdaptingCircularBufferCounter &&other) = default
AdaptingCircularBufferCounter &operator=(const AdaptingCircularBufferCounter &other) = default
AdaptingCircularBufferCounter &operator=(AdaptingCircularBufferCounter &&other) = default
inline int32_t StartIndex() const

The first index with a recording. May be negative.

Note: the returned value is not meaningful when Empty returns true.

Returns

the first index with a recording.

inline int32_t EndIndex() const

The last index with a recording. May be negative.

Note: the returned value is not meaningful when Empty returns true.

Returns

The last index with a recording.

inline bool Empty() const

Returns true if no recordings, false if at least one recording.

inline size_t MaxSize() const

Returns the maximum number of buckets allowed in this counter.

void Clear()

Resets all bucket counts to zero and resets index start/end tracking.

bool Increment(int32_t index, uint64_t delta)

Persist new data at index, incrementing by delta amount.

Parameters
  • index – The index of where to perform the incrementation.

  • delta – How much to increment the index by.

Returns

success status.

uint64_t Get(int32_t index)

Get the number of recordings for the given index.

Returns

the number of recordings for the index, or 0 if the index is out of bounds.