Tesseract
3.02
|
00001 /********************************************************************** 00002 * File: alt_list.cpp 00003 * Description: Class to abstarct a list of alternate results 00004 * Author: Ahmad Abdulkader 00005 * Created: 2007 00006 * 00007 * (C) Copyright 2008, Google Inc. 00008 ** Licensed under the Apache License, Version 2.0 (the "License"); 00009 ** you may not use this file except in compliance with the License. 00010 ** You may obtain a copy of the License at 00011 ** http://www.apache.org/licenses/LICENSE-2.0 00012 ** Unless required by applicable law or agreed to in writing, software 00013 ** distributed under the License is distributed on an "AS IS" BASIS, 00014 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 ** See the License for the specific language governing permissions and 00016 ** limitations under the License. 00017 * 00018 **********************************************************************/ 00019 00020 #include "altlist.h" 00021 #include <stdlib.h> 00022 00023 namespace tesseract { 00024 00025 AltList::AltList(int max_alt) { 00026 max_alt_ = max_alt; 00027 alt_cnt_ = 0; 00028 alt_cost_ = NULL; 00029 alt_tag_ = NULL; 00030 } 00031 00032 AltList::~AltList() { 00033 if (alt_cost_ != NULL) { 00034 delete []alt_cost_; 00035 alt_cost_ = NULL; 00036 } 00037 00038 if (alt_tag_ != NULL) { 00039 delete []alt_tag_; 00040 alt_tag_ = NULL; 00041 } 00042 } 00043 00044 // return the best possible cost and index of corresponding alternate 00045 int AltList::BestCost(int *best_alt) const { 00046 if (alt_cnt_ <= 0) { 00047 (*best_alt) = -1; 00048 return -1; 00049 } 00050 00051 int best_alt_idx = 0; 00052 for (int alt_idx = 1; alt_idx < alt_cnt_; alt_idx++) { 00053 if (alt_cost_[alt_idx] < alt_cost_[best_alt_idx]) { 00054 best_alt_idx = alt_idx; 00055 } 00056 } 00057 (*best_alt) = best_alt_idx; 00058 return alt_cost_[best_alt_idx]; 00059 } 00060 }