#include <search_column.h>
Definition at line 37 of file search_column.h.
◆ SearchColumn()
tesseract::SearchColumn::SearchColumn |
( |
int |
col_idx, |
|
|
int |
max_node_cnt |
|
) |
| |
Definition at line 25 of file search_column.cpp.
29 max_node_cnt_ = max_node;
30 node_hash_table_ = NULL;
◆ ~SearchColumn()
tesseract::SearchColumn::~SearchColumn |
( |
| ) |
|
◆ AddNode()
Definition at line 130 of file search_column.cpp.
134 if (init_ ==
false && Init() ==
false) {
140 SearchNode *new_node = node_hash_table_->
Lookup(edge, parent_node);
142 if (new_node == NULL) {
143 new_node =
new SearchNode(cntxt, parent_node, reco_cost, edge, col_idx_);
148 if (node_cnt_ >= max_node_cnt_ && new_node->BestCost() > max_cost_) {
154 if ((node_cnt_ % kNodeAllocChunk) == 0) {
156 SearchNode **new_node_buff =
157 new SearchNode *[node_cnt_ + kNodeAllocChunk];
160 if (node_array_ != NULL) {
161 memcpy(new_node_buff, node_array_, node_cnt_ *
sizeof(*new_node_buff));
162 delete []node_array_;
165 node_array_ = new_node_buff;
170 if (edge->IsOOD() ==
false) {
171 if (!node_hash_table_->
Insert(edge, new_node)) {
178 node_array_[node_cnt_++] = new_node;
183 if (new_node->UpdateParent(parent_node, reco_cost, edge) ==
false) {
192 if (new_node != NULL) {
193 if (min_cost_ > new_node->BestCost()) {
194 min_cost_ = new_node->BestCost();
197 if (max_cost_ < new_node->BestCost()) {
198 max_cost_ = new_node->BestCost();
bool Insert(LangModEdge *lang_mod_edge, SearchNode *srch_node)
SearchNode * Lookup(LangModEdge *lang_mod_edge, SearchNode *parent_node)
◆ BestNode()
SearchNode * tesseract::SearchColumn::BestNode |
( |
| ) |
|
Definition at line 205 of file search_column.cpp.
206 SearchNode *best_node = NULL;
208 for (
int node_idx = 0; node_idx < node_cnt_; node_idx++) {
209 if (best_node == NULL ||
210 best_node->BestCost() > node_array_[node_idx]->
BestCost()) {
211 best_node = node_array_[node_idx];
◆ ColIdx()
int tesseract::SearchColumn::ColIdx |
( |
| ) |
const |
|
inline |
◆ FreeHashTable()
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;
◆ NodeCount()
int tesseract::SearchColumn::NodeCount |
( |
| ) |
const |
|
inline |
◆ Nodes()
SearchNode** tesseract::SearchColumn::Nodes |
( |
| ) |
const |
|
inline |
◆ Prune()
void tesseract::SearchColumn::Prune |
( |
| ) |
|
Definition at line 74 of file search_column.cpp.
76 if (node_cnt_ <= max_node_cnt_) {
81 memset(score_bins_, 0,
sizeof(score_bins_));
82 int cost_range = max_cost_ - min_cost_ + 1;
83 for (
int node_idx = 0; node_idx < node_cnt_; node_idx++) {
84 int cost_bin =
static_cast<int>(
85 ((node_array_[node_idx]->
BestCost() - min_cost_) *
86 kScoreBins) /
static_cast<double>(cost_range));
87 if (cost_bin >= kScoreBins) {
88 cost_bin = kScoreBins - 1;
90 score_bins_[cost_bin]++;
98 for (
int cost_bin = 0; cost_bin < kScoreBins; cost_bin++) {
99 if (new_node_cnt > 0 &&
100 (new_node_cnt + score_bins_[cost_bin]) > max_node_cnt_) {
101 pruning_cost = min_cost_ + ((cost_bin * cost_range) / kScoreBins);
104 new_node_cnt += score_bins_[cost_bin];
108 for (
int node_idx = new_node_cnt = 0; node_idx < node_cnt_; node_idx++) {
110 if (node_array_[node_idx]->BestCost() > pruning_cost ||
111 new_node_cnt > max_node_cnt_) {
112 delete node_array_[node_idx];
115 node_array_[new_node_cnt++] = node_array_[node_idx];
118 node_cnt_ = new_node_cnt;
◆ Sort()
void tesseract::SearchColumn::Sort |
( |
| ) |
|
Definition at line 122 of file search_column.cpp.
123 if (node_cnt_ > 0 && node_array_ != NULL) {
124 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: