#include <search_column.h>
Definition at line 37 of file search_column.h.
tesseract::SearchColumn::SearchColumn |
( |
int |
col_idx, |
|
|
int |
max_node_cnt |
|
) |
| |
tesseract::SearchColumn::~SearchColumn |
( |
| ) |
|
Definition at line 133 of file search_column.cpp.
137 if (init_ ==
false && Init() ==
false) {
143 SearchNode *new_node = node_hash_table_->
Lookup(edge, parent_node);
145 if (new_node ==
NULL) {
146 new_node =
new SearchNode(cntxt, parent_node, reco_cost, edge, col_idx_);
147 if (new_node ==
NULL) {
154 if (node_cnt_ >= max_node_cnt_ && new_node->BestCost() > max_cost_) {
160 if ((node_cnt_ % kNodeAllocChunk) == 0) {
162 SearchNode **new_node_buff =
163 new SearchNode *[node_cnt_ + kNodeAllocChunk];
164 if (new_node_buff ==
NULL) {
170 if (node_array_ !=
NULL) {
171 memcpy(new_node_buff, node_array_, node_cnt_ *
sizeof(*new_node_buff));
172 delete []node_array_;
175 node_array_ = new_node_buff;
180 if (edge->IsOOD() ==
false) {
181 if (!node_hash_table_->
Insert(edge, new_node)) {
188 node_array_[node_cnt_++] = new_node;
193 if (new_node->UpdateParent(parent_node, reco_cost, edge) ==
false) {
204 if (new_node !=
NULL) {
205 if (min_cost_ > new_node->BestCost()) {
206 min_cost_ = new_node->BestCost();
209 if (max_cost_ < new_node->BestCost()) {
210 max_cost_ = new_node->BestCost();
SearchNode * Lookup(LangModEdge *lang_mod_edge, SearchNode *parent_node)
bool Insert(LangModEdge *lang_mod_edge, SearchNode *srch_node)
SearchNode * tesseract::SearchColumn::BestNode |
( |
| ) |
|
Definition at line 217 of file search_column.cpp.
218 SearchNode *best_node =
NULL;
220 for (
int node_idx = 0; node_idx < node_cnt_; node_idx++) {
221 if (best_node ==
NULL ||
222 best_node->BestCost() > node_array_[node_idx]->
BestCost()) {
223 best_node = node_array_[node_idx];
int tesseract::SearchColumn::ColIdx |
( |
| ) |
const |
|
inline |
void tesseract::SearchColumn::FreeHashTable |
( |
| ) |
|
|
inline |
Definition at line 57 of file search_column.h.
58 if (node_hash_table_ !=
NULL) {
59 delete node_hash_table_;
60 node_hash_table_ =
NULL;
int tesseract::SearchColumn::NodeCount |
( |
| ) |
const |
|
inline |
SearchNode** tesseract::SearchColumn::Nodes |
( |
| ) |
const |
|
inline |
void tesseract::SearchColumn::Prune |
( |
| ) |
|
Definition at line 77 of file search_column.cpp.
79 if (node_cnt_ <= max_node_cnt_) {
84 memset(score_bins_, 0,
sizeof(score_bins_));
85 int cost_range = max_cost_ - min_cost_ + 1;
86 for (
int node_idx = 0; node_idx < node_cnt_; node_idx++) {
87 int cost_bin =
static_cast<int>(
88 ((node_array_[node_idx]->
BestCost() - min_cost_) *
89 kScoreBins) /
static_cast<double>(cost_range));
90 if (cost_bin >= kScoreBins) {
91 cost_bin = kScoreBins - 1;
93 score_bins_[cost_bin]++;
100 int new_node_cnt = 0;
101 for (
int cost_bin = 0; cost_bin < kScoreBins; cost_bin++) {
102 if (new_node_cnt > 0 &&
103 (new_node_cnt + score_bins_[cost_bin]) > max_node_cnt_) {
104 pruning_cost = min_cost_ + ((cost_bin * cost_range) / kScoreBins);
107 new_node_cnt += score_bins_[cost_bin];
111 for (
int node_idx = new_node_cnt = 0; node_idx < node_cnt_; node_idx++) {
113 if (node_array_[node_idx]->BestCost() > pruning_cost ||
114 new_node_cnt > max_node_cnt_) {
115 delete node_array_[node_idx];
118 node_array_[new_node_cnt++] = node_array_[node_idx];
121 node_cnt_ = new_node_cnt;
void tesseract::SearchColumn::Sort |
( |
| ) |
|
Definition at line 125 of file search_column.cpp.
126 if (node_cnt_ > 0 && node_array_ !=
NULL) {
127 qsort(node_array_, node_cnt_,
sizeof(*node_array_),
static int SearchNodeComparer(const void *node1, const void *node2)
The documentation for this class was generated from the following files: