Template Class BitmapRange

Class Documentation

template<class T, class Diff = DiffFunction<T>, uint32_t NBITS = 256>
class BitmapRange

Template class to hold a range of items using a custom bitmap.

Template Parameters
  • T – Type of the elements in the range. Should have >= operator and T + uint32_t returning T.

  • Diff – Functor calculating the difference of two T. The result should be assignable to a uint32_t.

  • NBITS – Size in bits of the bitmap. Range of items will be [base, base + NBITS - 1].

Public Types

using bitmap_type = std::array<uint32_t, NITEMS>

Public Functions

inline BitmapRange() noexcept

Default constructor. Constructs an empty range with default base.

inline explicit BitmapRange(T base) noexcept

Base-specific constructor. Constructs an empty range with specified base.

Parameters

base – Specific base value for the created range.

inline BitmapRange(T base, uint32_t max_bits) noexcept

Range specific constructor. Constructs an empty range with specified base and maximum bits.

Parameters
  • base – Specific base value for the created range.

  • max_bits – Specific maximum number of bits.

inline T base() const noexcept

Get base of the range.

Returns

a copy of the range base.

inline void base(T base) noexcept

Set a new base for the range. This method resets the range and sets a new value for its base.

Parameters

base – New base value to set.

inline void base(T base, uint32_t max_bits) noexcept

Set a new base and maximum bits for the range. This method resets the range and sets a new value for its base, as long as a maximum number of bits.

Parameters
  • base – New base value to set.

  • max_bits – New maximum number of bits.

inline void base_update(T base) noexcept

Set a new base for the range, keeping old values where possible. This method implements a sliding window mechanism for changing the base of the range.

Parameters

base – New base value to set.

inline bool empty() const noexcept

Returns whether the range is empty (i.e. has all bits unset).

Returns

true if the range is empty, false otherwise.

inline T max() const noexcept

Returns the highest value set in the range.

Returns

the highest value set in the range. If the range is empty, the result is undetermined.

inline T min() const noexcept

Returns the lowest value set in the range.

Returns

the lowest value set in the range. If the range is empty, the result is undetermined.

inline bool is_set(const T &item) const noexcept

Checks if an element is present in the bitmap.

Parameters

item – Value to be checked.

Returns

true if the item is present in the bitmap, false otherwise.

inline bool add(const T &item) noexcept

Adds an element to the range. Adds an element to the bitmap if it is in the allowed range.

Parameters

item – Value to be added.

Returns

true if the item has been added (i.e. is in the allowed range), false otherwise.

inline void add_range(const T &from, const T &to)

Adds a range of elements to the range.

Add all elements in [from, to) to the range. Equivalent to for(T i = from; i < to; i++) add(i);

Parameters
  • from – Starting value of the range to add.

  • to – Ending value of the range to add.

inline void remove(const T &item) noexcept

Removes an element from the range. Removes an element from the bitmap.

Parameters

item – Value to be removed.

inline void bitmap_get(uint32_t &num_bits, bitmap_type &bitmap, uint32_t &num_longs_used) const noexcept

Gets the current value of the bitmap. This method is designed to be used when performing serialization of a bitmap range.

Parameters
  • num_bits – Upon return, it will contain the number of significant bits in the bitmap.

  • bitmap – Upon return, it will contain the current value of the bitmap.

  • num_longs_used – Upon return, it will contain the number of valid elements on the returned bitmap.

inline void bitmap_set(uint32_t num_bits, const uint32_t *bitmap) noexcept

Sets the current value of the bitmap. This method is designed to be used when performing deserialization of a bitmap range.

Parameters
  • num_bits – Number of significant bits in the input bitmap.

  • bitmap – Points to the beginning of a uint32_t array holding the input bitmap.

template<class UnaryFunc>
inline void for_each(UnaryFunc f) const

Apply a function on every item on the range.

Parameters

f – Function to apply on each item.

Protected Attributes

T base_

Holds base value of the range.

T range_max_

Holds maximum allowed value of the range.

bitmap_type bitmap_

Holds the bitmap values.

uint32_t num_bits_

Holds the highest bit set in the bitmap.