All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
altlist.cpp
Go to the documentation of this file.
1 /**********************************************************************
2  * File: alt_list.cpp
3  * Description: Class to abstarct a list of alternate results
4  * Author: Ahmad Abdulkader
5  * Created: 2007
6  *
7  * (C) Copyright 2008, Google Inc.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  *
18  **********************************************************************/
19 
20 #include "altlist.h"
21 #include <stdlib.h>
22 
23 namespace tesseract {
24 
25 AltList::AltList(int max_alt) {
26  max_alt_ = max_alt;
27  alt_cnt_ = 0;
28  alt_cost_ = NULL;
29  alt_tag_ = NULL;
30 }
31 
33  if (alt_cost_ != NULL) {
34  delete []alt_cost_;
35  alt_cost_ = NULL;
36  }
37 
38  if (alt_tag_ != NULL) {
39  delete []alt_tag_;
40  alt_tag_ = NULL;
41  }
42 }
43 
44 // return the best possible cost and index of corresponding alternate
45 int AltList::BestCost(int *best_alt) const {
46  if (alt_cnt_ <= 0) {
47  (*best_alt) = -1;
48  return -1;
49  }
50 
51  int best_alt_idx = 0;
52  for (int alt_idx = 1; alt_idx < alt_cnt_; alt_idx++) {
53  if (alt_cost_[alt_idx] < alt_cost_[best_alt_idx]) {
54  best_alt_idx = alt_idx;
55  }
56  }
57  (*best_alt) = best_alt_idx;
58  return alt_cost_[best_alt_idx];
59 }
60 }
void ** alt_tag_
Definition: altlist.h:57
AltList(int max_alt)
Definition: altlist.cpp:25
virtual ~AltList()
Definition: altlist.cpp:32
int BestCost(int *best_alt) const
Definition: altlist.cpp:45
#define NULL
Definition: host.h:144