Skip to content

Commit

Permalink
Remove local function declarations from intmatcher.h
Browse files Browse the repository at this point in the history
This requires moving the local function HeapSort to the beginning.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Mar 22, 2019
1 parent 2ba194c commit e1e56d9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 69 deletions.
101 changes: 50 additions & 51 deletions src/classify/intmatcher.cpp
Expand Up @@ -94,6 +94,56 @@ static const uint8_t* const next_table =

namespace tesseract {

/**
* Sort Key array in ascending order using heap sort
* algorithm. Also sort Index array that is tied to
* the key array.
* @param n Number of elements to sort
* @param ra Key array [1..n]
* @param rb Index array [1..n]
* @return none
*/
static void
HeapSort (int n, int ra[], int rb[]) {
int i, rra, rrb;
int l, j, ir;

l = (n >> 1) + 1;
ir = n;
for (;;) {
if (l > 1) {
rra = ra[--l];
rrb = rb[l];
}
else {
rra = ra[ir];
rrb = rb[ir];
ra[ir] = ra[1];
rb[ir] = rb[1];
if (--ir == 1) {
ra[1] = rra;
rb[1] = rrb;
return;
}
}
i = l;
j = l << 1;
while (j <= ir) {
if (j < ir && ra[j] < ra[j + 1])
++j;
if (rra < ra[j]) {
ra[i] = ra[j];
rb[i] = rb[j];
j += (i = j);
}
else
j = ir + 1;
}
ra[i] = rra;
rb[i] = rrb;
}
}

// Encapsulation of the intermediate data and computations made by the class
// pruner. The class pruner implements a simple linear classifier on binary
// features by heavily quantizing the feature space, and applying
Expand Down Expand Up @@ -1017,7 +1067,6 @@ void IntegerMatcher::DisplayProtoDebugInfo(
InitProtoDisplayWindowIfReqd();
}


for (ProtoSetIndex = 0; ProtoSetIndex < ClassTemplate->NumProtoSets;
ProtoSetIndex++) {
ProtoSet = ClassTemplate->ProtoSets[ProtoSetIndex];
Expand Down Expand Up @@ -1182,53 +1231,3 @@ float IntegerMatcher::ApplyCNCorrection(float rating, int blob_length,
matcher_multiplier * normalization_factor / 256.0) /
(blob_length + matcher_multiplier);
}

/**
* Sort Key array in ascending order using heap sort
* algorithm. Also sort Index array that is tied to
* the key array.
* @param n Number of elements to sort
* @param ra Key array [1..n]
* @param rb Index array [1..n]
* @return none
*/
void
HeapSort (int n, int ra[], int rb[]) {
int i, rra, rrb;
int l, j, ir;

l = (n >> 1) + 1;
ir = n;
for (;;) {
if (l > 1) {
rra = ra[--l];
rrb = rb[l];
}
else {
rra = ra[ir];
rrb = rb[ir];
ra[ir] = ra[1];
rb[ir] = rb[1];
if (--ir == 1) {
ra[1] = rra;
rb[1] = rrb;
return;
}
}
i = l;
j = l << 1;
while (j <= ir) {
if (j < ir && ra[j] < ra[j + 1])
++j;
if (rra < ra[j]) {
ra[i] = ra[j];
rb[i] = rb[j];
j += (i = j);
}
else
j = ir + 1;
}
ra[i] = rra;
rb[i] = rrb;
}
}
18 changes: 0 additions & 18 deletions src/classify/intmatcher.h
Expand Up @@ -176,22 +176,4 @@ class IntegerMatcher {
uint32_t evidence_mult_mask_;
};

/**----------------------------------------------------------------------------
Private Function Prototypes
----------------------------------------------------------------------------**/
void IMDebugConfiguration(INT_FEATURE FeatureNum,
uint16_t ActualProtoNum,
uint8_t Evidence,
BIT_VECTOR ConfigMask,
uint32_t ConfigWord);

void IMDebugConfigurationSum(INT_FEATURE FeatureNum,
uint8_t *FeatureEvidence,
int32_t ConfigCount);

void HeapSort (int n, int ra[], int rb[]);

/**----------------------------------------------------------------------------
Global Data Definitions and Declarations
----------------------------------------------------------------------------**/
#endif

0 comments on commit e1e56d9

Please sign in to comment.