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();
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;
123 if (node_cnt_ > 0 && node_array_ != NULL) {
124 qsort(node_array_, node_cnt_,
sizeof(*node_array_),
134 if (init_ ==
false && Init() ==
false) {
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) {
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()) {
197 if (max_cost_ < new_node->BestCost()) {
208 for (
int node_idx = 0; node_idx < node_cnt_; node_idx++) {
209 if (best_node == NULL ||
211 best_node = node_array_[node_idx];
bool UpdateParent(SearchNode *new_parent, int new_reco_cost, LangModEdge *new_edge)
bool Insert(LangModEdge *lang_mod_edge, SearchNode *srch_node)
virtual bool IsOOD() const =0
SearchNode * Lookup(LangModEdge *lang_mod_edge, SearchNode *parent_node)
static int SearchNodeComparer(const void *node1, const void *node2)
SearchNode * AddNode(LangModEdge *edge, int score, SearchNode *parent, CubeRecoContext *cntxt)
SearchColumn(int col_idx, int max_node_cnt)