StaticIndexMap.hpp

A fast version of IndexMap where weights cannot individually change.

This file is part of Empirical, https://github.com/devosoft/Empirical Copyright (C) 2025 Michigan State University MIT Software license; see doc/LICENSE.md

Note

Status: BETA

Defines

INCLUDE_EMP_DATASTRUCTS_STATIC_INDEX_MAP_HPP_GUARD
template<size_t MAX_BINS = 1000>
class StaticIndexMap
#include <StaticIndexMap.hpp>

A map of indices with fixed weights. If a random index is selected, the probability of an index being returned is directly proportional to its weight.

Public Functions

inline StaticIndexMap()

Default constructor; set up with no weights.

inline StaticIndexMap(const UnorderedIndexMap &in_map)

Construct an StaticIndexMap where num_items is the maximum number of items that can be placed into the data structure. All item weights default to zero.

inline StaticIndexMap(const vector<double> &in_weights)

Construct an StaticIndexMap with a specified initial set of weights.

StaticIndexMap(const StaticIndexMap&) = default
StaticIndexMap(StaticIndexMap&&) = default
~StaticIndexMap() = default
StaticIndexMap &operator=(const StaticIndexMap&) = default
StaticIndexMap &operator=(StaticIndexMap&&) = default
inline void Reset()
inline void Set(const UnorderedIndexMap &in_map)

Set the whole distribution.

inline void Set(const vector<double> &in_weights)
inline size_t GetSize() const

How many indices are in this map?

inline double GetWeight() const

Get the total weight of all indices in this map.

inline double GetWeight(size_t id) const

Get the weight of a specified index in this map.

inline size_t Index(double index) const

Determine the ID at the specified index position.

inline size_t CalcBinCount(double bin_weight) const

Calculate how many bins would be used for a given bin weight.

inline double OptimizeBinWeight() const

Determine how big bins should be for optimal coverage.

inline void Optimize()

Scan through the probabilities and bin them as much as possible.

Private Members

double bin_weight = 0.0
double total_bin_weight = 0.0
array<size_t, MAX_BINS> bins = {}
UnorderedIndexMap index_map
vector<double> weights