29 max_node_cnt_ = max_node;
30 node_hash_table_ =
NULL;
37 void SearchColumn::Cleanup() {
38 if (node_array_ !=
NULL) {
39 for (
int node_idx = 0; node_idx < node_cnt_; node_idx++) {
40 if (node_array_[node_idx] !=
NULL) {
41 delete node_array_[node_idx];
57 bool SearchColumn::Init() {
63 if (node_hash_table_ ==
NULL) {
64 node_hash_table_ =
new SearchNodeHashTable();
65 if (node_hash_table_ ==
NULL) {
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;
126 if (node_cnt_ > 0 && node_array_ !=
NULL) {
127 qsort(node_array_, node_cnt_,
sizeof(*node_array_),
137 if (init_ ==
false && Init() ==
false) {
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) {
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()) {
209 if (max_cost_ < new_node->BestCost()) {
220 for (
int node_idx = 0; node_idx < node_cnt_; node_idx++) {
221 if (best_node ==
NULL ||
223 best_node = node_array_[node_idx];
virtual bool IsOOD() const =0
SearchNode * Lookup(LangModEdge *lang_mod_edge, SearchNode *parent_node)
SearchColumn(int col_idx, int max_node_cnt)
bool UpdateParent(SearchNode *new_parent, int new_reco_cost, LangModEdge *new_edge)
bool Insert(LangModEdge *lang_mod_edge, SearchNode *srch_node)
SearchNode * AddNode(LangModEdge *edge, int score, SearchNode *parent, CubeRecoContext *cntxt)
static int SearchNodeComparer(const void *node1, const void *node2)