Tesseract  3.02
tesseract-ocr/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 "mfcpch.h"
00021 #include          "sortflts.h"
00022 #include          "notdll.h"
00023 
00024 ELISTIZE (SORTED_FLOAT)
00030 void SORTED_FLOATS::add(  //add new entry
00031                         float value,
00032                         inT32 key) {
00033   SORTED_FLOAT *new_float = new SORTED_FLOAT (value, key);
00034 
00035   if (list.empty ())
00036     it.add_after_stay_put (new_float);
00037   else {
00038     it.move_to_first ();
00039     while (!it.at_last () && it.data ()->entry < value)
00040       it.forward ();
00041     if (it.data ()->entry < value)
00042       it.add_after_stay_put (new_float);
00043     else
00044       it.add_before_stay_put (new_float);
00045   }
00046 }
00047 
00048 
00055 void SORTED_FLOATS::remove(  //remove the entry
00056                            inT32 key) {
00057   if (!list.empty ()) {
00058     for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00059       if (it.data ()->address == key) {
00060         delete it.extract ();
00061         return;
00062       }
00063     }
00064   }
00065 }
00066 
00067 
00074 float
00075 SORTED_FLOATS::operator[] (      //get an entry
00076 inT32 index                      //to list
00077 ) {
00078   it.move_to_first ();
00079   return it.data_relative (index)->entry;
00080 }