16#ifndef TRACKINGITSU_INCLUDE_CAPACITYESTIMATOR_H_
17#define TRACKINGITSU_INCLUDE_CAPACITYESTIMATOR_H_
39constexpr const char*
const SlabSiteNames[
SlabSite::NSlabSite]{
"Tracklets",
"Cells",
"Neighbours",
"RoadCandidates",
"Roads",
"TrackSeeds",
"TracksExtended",
"Tracks"};
68 return (
static_cast<KeyType>(site) << 56) |
69 (
static_cast<KeyType>(iteration & 0xFF) << 48) |
70 (
static_cast<KeyType>(variant & 0xFFFF) << 32) |
71 static_cast<KeyType>(
static_cast<uint32_t
>(slot));
78 .iteration =
static_cast<int>((
key >> 48) & 0xFF),
79 .variant =
static_cast<int>((
key >> 32) & 0xFFFF),
80 .slot =
static_cast<int>(
static_cast<uint32_t
>(
key & 0xFFFFFFFF))};
85 return ((high & 0xFF) << 8) | (low & 0xFF);
90 return (variant >> 8) & 0xFF;
95 return variant & 0xFF;
108 void update(uint64_t
key,
double scale,
size_t emitted,
size_t capacityUsed,
bool overflowed,
bool memoryLimited);
113 std::unique_ptr<Impl> mImpl;
116template <
typename Emit>
119 const auto toInt = [](
const size_t v) {
return static_cast<int>(std::min(
v,
static_cast<size_t>(std::numeric_limits<int>::max()))); };
120 const int initialCapacity = toInt(estimator.
capacity(
key, scale));
121 int capacity = std::max(initialCapacity, toInt(floorCapacity));
123 bool overflowed =
false;
124 bool needsRetry =
false;
126 const int attemptCapacity = capacity;
127 emitted = emit(attemptCapacity);
128 needsRetry = emitted > attemptCapacity;
129 overflowed |= needsRetry;
131 }
while (needsRetry);
132 estimator.
update(
key, scale, emitted, initialCapacity, overflowed,
false);
static constexpr int getVariantLow(int variant) noexcept
size_t capacity(uint64_t key, double scale) const
void update(uint64_t key, double scale, size_t emitted, size_t capacityUsed, bool overflowed, bool memoryLimited)
static constexpr int makeVariant(int high, int low) noexcept
static constexpr KeyType makeKey(SlabSite site, int iteration, int variant, int slot) noexcept
CapacityEstimator & operator=(const CapacityEstimator &)=delete
size_t peakCapacity(uint64_t key) const
static constexpr Decoded decodeKey(KeyType key) noexcept
CapacityEstimator(const CapacityEstimator &)=delete
static constexpr int getVariantHigh(int variant) noexcept
GLfloat GLfloat GLfloat alpha
constexpr const char *const SlabSiteNames[SlabSite::NSlabSite]
int runOnSlab(CapacityEstimator &estimator, const CapacityEstimator::KeyType key, const double scale, Emit &&emit, const size_t floorCapacity=0)
float marginOverflowSlack
std::map< std::string, ID > expected