Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Member Functions | Static Public Member Functions
SortHelper< T > Class Template Reference

`#include <sorthelper.h>`

List of all members.

## Classes

struct | SortPair

## Public Member Functions

| SortHelper (int sizehint)
void | Add (T value, int count)
int | MaxCount (T *max_value) const
const GenericVector< SortPair < T > > & | SortByCount ()
const GenericVector< SortPair < T > > & | SortByValue ()

## Static Public Member Functions

static int | SortPairsByCount (const void *v1, const void *v2)
static int | SortPairsByValue (const void *v1, const void *v2)

## Detailed Description

### template<typename T>
class SortHelper< T >

Definition at line 36 of file sorthelper.h.

## Constructor & Destructor Documentation

template<typename T >

SortHelper< T >::SortHelper | ( | int | sizehint | ) |

inlineexplicit

Definition at line 59 of file sorthelper.h.

: counts_(sizehint) {}

## Member Function Documentation

template<typename T >

void SortHelper< T >::Add | ( | T | value,
|  | int | count
| ) |  |

inline

Definition at line 63 of file sorthelper.h.

{
// Linear search for value.
for (int i = 0; i < counts_.size(); ++i) {
if (counts_[i].value == value) {
counts_[i].count += count;
return;
}
}
SortPair<T> new_pair = {value, count};
counts_.push_back(SortPair<T>(new_pair));
}
template<typename T >

int SortHelper< T >::MaxCount | ( | T * | max_value | ) | const

inline

Definition at line 78 of file sorthelper.h.

{
int best_count = -MAX_INT32;
for (int i = 0; i < counts_.size(); ++i) {
if (counts_[i].count > best_count) {
best_count = counts_[i].count;
if (max_value != NULL)
*max_value = counts_[i].value;
}
}
return best_count;
}
template<typename T >

const GenericVector<SortPair<T> >& SortHelper< T >::SortByCount | ( |  | ) |

inline

Definition at line 91 of file sorthelper.h.

{
counts_.sort(&SortPairsByCount);
return counts_;
}
template<typename T >

const GenericVector<SortPair<T> >& SortHelper< T >::SortByValue | ( |  | ) |

inline

Definition at line 96 of file sorthelper.h.

{
counts_.sort(&SortPairsByValue);
return counts_;
}
template<typename T >

static int SortHelper< T >::SortPairsByCount | ( | const void * | v1,
|  | const void * | v2
| ) |  |

inlinestatic

Definition at line 44 of file sorthelper.h.

{
const SortPair<T>* p1 = reinterpret_cast<const SortPair<T>*>(v1);
const SortPair<T>* p2 = reinterpret_cast<const SortPair<T>*>(v2);
return p2->count - p1->count;
}
template<typename T >

static int SortHelper< T >::SortPairsByValue | ( | const void * | v1,
|  | const void * | v2
| ) |  |

inlinestatic

Definition at line 50 of file sorthelper.h.

{
const SortPair<T>* p1 = reinterpret_cast<const SortPair<T>*>(v1);
const SortPair<T>* p2 = reinterpret_cast<const SortPair<T>*>(v2);
if (p2->value - p1->value < 0) return -1;
if (p2->value - p1->value > 0) return 1;
return 0;
}

The documentation for this class was generated from the following file:

- /mnt/data/src/tesseract-ocr/ccutil/sorthelper.h