• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "mfcpch.h"
21 #include          "sortflts.h"
22 #include          "notdll.h"
23 
ELISTIZE(SORTED_FLOAT)24 ELISTIZE (SORTED_FLOAT)
25 /**********************************************************************
26  * SORTED_FLOATS::add
27  *
28  * Add a new entry to the sorted lsit of floats.
29  **********************************************************************/
30 void SORTED_FLOATS::add(  //add new entry
31                         float value,
32                         inT32 key) {
33   SORTED_FLOAT *new_float = new SORTED_FLOAT (value, key);
34 
35   if (list.empty ())
36     it.add_after_stay_put (new_float);
37   else {
38     it.move_to_first ();
39     while (!it.at_last () && it.data ()->entry < value)
40       it.forward ();
41     if (it.data ()->entry < value)
42       it.add_after_stay_put (new_float);
43     else
44       it.add_before_stay_put (new_float);
45   }
46 }
47 
48 
49 /**********************************************************************
50  * SORTED_FLOATS::remove
51  *
52  * Remove an entry from the sorted lsit of floats.
53  **********************************************************************/
54 
remove(inT32 key)55 void SORTED_FLOATS::remove(  //remove the entry
56                            inT32 key) {
57   if (!list.empty ()) {
58     for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
59       if (it.data ()->address == key) {
60         delete it.extract ();
61         return;
62       }
63     }
64   }
65 }
66 
67 
68 /**********************************************************************
69  * SORTED_FLOATS::operator[]
70  *
71  * Return the floating point value of the given index into the list.
72  **********************************************************************/
73 
74 float
operator [](inT32 index)75 SORTED_FLOATS::operator[] (      //get an entry
76 inT32 index                      //to list
77 ) {
78   it.move_to_first ();
79   return it.data_relative (index)->entry;
80 }
81