All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  * Created: Mon Oct 4 16:15:40 BST 1993
6  *
7  * (C) Copyright 1993, Hewlett-Packard Ltd.
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 "sortflts.h"
21 
28 void SORTED_FLOATS::add( //add new entry
29  float value,
30  inT32 key) {
31  SORTED_FLOAT *new_float = new SORTED_FLOAT (value, key);
32 
33  if (list.empty ())
34  it.add_after_stay_put (new_float);
35  else {
36  it.move_to_first ();
37  while (!it.at_last () && it.data ()->entry < value)
38  it.forward ();
39  if (it.data ()->entry < value)
40  it.add_after_stay_put (new_float);
41  else
42  it.add_before_stay_put (new_float);
43  }
44 }
45 
46 
53 void SORTED_FLOATS::remove( //remove the entry
54  inT32 key) {
55  if (!list.empty ()) {
56  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
57  if (it.data ()->address == key) {
58  delete it.extract ();
59  return;
60  }
61  }
62  }
63 }
64 
65 
72 float
74 inT32 index //to list
75 ) {
76  it.move_to_first ();
77  return it.data_relative (index)->entry;
78 }
#define ELISTIZE(CLASSNAME)
Definition: elst.h:994
float operator[](inT32 index)
Definition: sortflts.cpp:73
void remove(inT32 key)
Definition: sortflts.cpp:53
int inT32
Definition: host.h:102