<commit_before>/*
 * author: <NAME> <<EMAIL>>
 */

#ifndef PROGRESS_HXX
#define PROGRESS_HXX

#include <algorithm>

#include <stdio.h>

/**
 * An interface to Workshop job progress reporting.
 */
class WorkshopProgress {
    unsigned min = 0, max = 0;

public:
    WorkshopProgress() = default;

    constexpr WorkshopProgress(unsigned _min, unsigned _max)
        :min(_min), max(_max) {}

    constexpr WorkshopProgress(WorkshopProgress parent,
                               unsigned _min, unsigned _max)
        :min(parent.Scale(_min)), max(parent.Scale(_max)) {}

    bool IsEnabled() const {
        return min < max;
    }

    void operator()(int value) {
        if (IsEnabled())
            printf("%u\n", Scale(Clamp(value)));
    }

private:
    static constexpr unsigned Clamp(int x) {
        return std::min(100u, (unsigned)std::max(0, x));
    }

    constexpr unsigned Scale(unsigned x) const {
        return (min * (100u - x) + max * x) / 100u;
    }
};

/**
 * A simple wrapper for #WorkshopProgress which counts up to a
 * predefined number of steps.
 */
class StepProgress {
    WorkshopProgress parent;

    const unsigned n;

    unsigned i = 0;

public:
    StepProgress(WorkshopProgress _parent, unsigned _n)
        :parent(_parent), n(_n) {}

    void operator()() {
        ++i;
        parent(i * 100u / n);
    }
};
<commit_msg>certdb/Progress: no "constexpr" for Clamp() on GCC 4.9<commit_after>/*
 * author: <NAME> <<EMAIL>>
 */

#ifndef PROGRESS_HXX
#define PROGRESS_HXX

#include <inline/compiler.h>

#include <algorithm>

#include <stdio.h>

/**
 * An interface to Workshop job progress reporting.
 */
class WorkshopProgress {
    unsigned min = 0, max = 0;

public:
    WorkshopProgress() = default;

    constexpr WorkshopProgress(unsigned _min, unsigned _max)
        :min(_min), max(_max) {}

    constexpr WorkshopProgress(WorkshopProgress parent,
                               unsigned _min, unsigned _max)
        :min(parent.Scale(_min)), max(parent.Scale(_max)) {}

    bool IsEnabled() const {
        return min < max;
    }

    void operator()(int value) {
        if (IsEnabled())
            printf("%u\n", Scale(Clamp(value)));
    }

private:
#if !GCC_OLDER_THAN(5,0)
    constexpr
#endif
    static unsigned Clamp(int x) {
        return std::min(100u, (unsigned)std::max(0, x));
    }

    constexpr unsigned Scale(unsigned x) const {
        return (min * (100u - x) + max * x) / 100u;
    }
};

/**
 * A simple wrapper for #WorkshopProgress which counts up to a
 * predefined number of steps.
 */
class StepProgress {
    WorkshopProgress parent;

    const unsigned n;

    unsigned i = 0;

public:
    StepProgress(WorkshopProgress _parent, unsigned _n)
        :parent(_parent), n(_n) {}

    void operator()() {
        ++i;
        parent(i * 100u / n);
    }
};

{'fraction_non_alphanumeric': 0.12946586487442518, 'fraction_numerical': 0.012734347364697559, 'mean_word_length': 2.6163682864450126, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7023129', 'n_tokens_mistral': 942, 'n_tokens_neox': 879, 'n_words': 246}