19#ifndef TESSERACT_CCUTIL_SORTHELPER_H_
20#define TESSERACT_CCUTIL_SORTHELPER_H_
40 template <
typename PairT>
47 const auto *p1 =
static_cast<const SortPair<T> *
>(v1);
48 const auto *p2 =
static_cast<const SortPair<T> *
>(v2);
49 return p2->
count - p1->count;
53 const auto *p1 =
static_cast<const SortPair<T> *
>(v1);
54 const auto *p2 =
static_cast<const SortPair<T> *
>(v2);
55 if (p2->
value - p1->value < 0) {
58 if (p2->
value - p1->value > 0) {
66 counts_.reserve(sizehint);
73 for (
auto &it : counts_) {
74 if (it.value ==
value) {
87 int best_count = -INT32_MAX;
88 for (
auto &it : counts_) {
89 if (it.count > best_count) {
90 best_count = it.count;
91 if (max_value !=
nullptr) {
92 *max_value = it.value;
111 std::vector<SortPair<T>> counts_;
const std::vector< SortPair< T > > & SortByValue()
int MaxCount(T *max_value) const
void Add(T value, int count)
static int SortPairsByCount(const void *v1, const void *v2)
static int SortPairsByValue(const void *v1, const void *v2)
const std::vector< SortPair< T > > & SortByCount()