tesseract  3.03
/usr/local/google/home/jbreiden/tesseract-ocr-read-only/textord/sortflts.cpp
Go to the documentation of this file.
00001 /**********************************************************************
00002  * File:        sortflts.cpp  (Formerly sfloats.c)
00003  * Description: Code to maintain a sorted list of floats.
00004  * Author:              Ray Smith
00005  * Created:             Mon Oct  4 16:15:40 BST 1993
00006  *
00007  * (C) Copyright 1993, Hewlett-Packard Ltd.
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          "sortflts.h"
00021 
00022 ELISTIZE (SORTED_FLOAT)
00028 void SORTED_FLOATS::add(  //add new entry
00029                         float value,
00030                         inT32 key) {
00031   SORTED_FLOAT *new_float = new SORTED_FLOAT (value, key);
00032 
00033   if (list.empty ())
00034     it.add_after_stay_put (new_float);
00035   else {
00036     it.move_to_first ();
00037     while (!it.at_last () && it.data ()->entry < value)
00038       it.forward ();
00039     if (it.data ()->entry < value)
00040       it.add_after_stay_put (new_float);
00041     else
00042       it.add_before_stay_put (new_float);
00043   }
00044 }
00045 
00046 
00053 void SORTED_FLOATS::remove(  //remove the entry
00054                            inT32 key) {
00055   if (!list.empty ()) {
00056     for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00057       if (it.data ()->address == key) {
00058         delete it.extract ();
00059         return;
00060       }
00061     }
00062   }
00063 }
00064 
00065 
00072 float
00073 SORTED_FLOATS::operator[] (      //get an entry
00074 inT32 index                      //to list
00075 ) {
00076   it.move_to_first ();
00077   return it.data_relative (index)->entry;
00078 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines