Class AdaptingIntegerArray

Class Documentation

class AdaptingIntegerArray

An integer array that automatically expands its memory consumption (via copy/allocation) when reaching limits. This assumes counts remain low, to lower memory overhead.

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

Instances start by attempting to store one-byte per-cell in the integer array. As values grow, this will automatically instantiate the next-size integer array (uint8_t -> uint16_t -> uint32_t -> uint64_t) and copy over values into the larger array. This class expects most usage to remain within the uint8_t boundary (e.g. cell values < 256).

Public Functions

inline explicit AdaptingIntegerArray(size_t size)
AdaptingIntegerArray(const AdaptingIntegerArray &other) = default
AdaptingIntegerArray(AdaptingIntegerArray &&other) = default
AdaptingIntegerArray &operator=(const AdaptingIntegerArray &other) = default
AdaptingIntegerArray &operator=(AdaptingIntegerArray &&other) = default
void Increment(size_t index, uint64_t count)

Increments the value at the specified index by the given count in the array.

Parameters
  • index – The index of the value to increment.

  • count – The count by which to increment the value.

uint64_t Get(size_t index) const

Returns the value at the specified index from the array.

Parameters

index – The index of the value to retrieve.

Returns

The value at the specified index.

size_t Size() const

Returns the size of the array.

Returns

The size of the array.

void Clear()

Clears the array, resetting all values to zero.