tesseract 4.1.1
Loading...
Searching...
No Matches
sortflts.cpp
Go to the documentation of this file.
1/**********************************************************************
2 * File: sortflts.cpp (Formerly sfloats.c)
3 * Description: Code to maintain a sorted list of floats.
4 * Author: Ray Smith
5 *
6 * (C) Copyright 1993, Hewlett-Packard Ltd.
7 ** Licensed under the Apache License, Version 2.0 (the "License");
8 ** you may not use this file except in compliance with the License.
9 ** You may obtain a copy of the License at
10 ** http://www.apache.org/licenses/LICENSE-2.0
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 *
17 **********************************************************************/
18
19#include "sortflts.h"
20
27void SORTED_FLOATS::add( //add new entry
28 float value,
29 int32_t key) {
30 auto *new_float = new SORTED_FLOAT (value, key);
31
32 if (list.empty ())
33 it.add_after_stay_put (new_float);
34 else {
35 it.move_to_first ();
36 while (!it.at_last () && it.data ()->entry < value)
37 it.forward ();
38 if (it.data ()->entry < value)
39 it.add_after_stay_put (new_float);
40 else
41 it.add_before_stay_put (new_float);
42 }
43}
44
45
52void SORTED_FLOATS::remove( //remove the entry
53 int32_t key) {
54 if (!list.empty ()) {
55 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
56 if (it.data ()->address == key) {
57 delete it.extract ();
58 return;
59 }
60 }
61 }
62}
63
64
71float
73int32_t index //to list
74) {
75 it.move_to_first ();
76 return it.data_relative (index)->entry;
77}
#define ELISTIZE(CLASSNAME)
Definition: elst.h:931
float operator[](int32_t index)
Definition: sortflts.cpp:72
void remove(int32_t key)
Definition: sortflts.cpp:52