OpendTect-6_4  6.4
toplist.h
Go to the documentation of this file.
1 #ifndef toplist_h
2 #define toplist_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: K Tingdahl
9  Date: April 2003
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 #include "algomod.h"
16 #include "typeset.h"
17 
18 #include <utility>
19 
26 template <class VT, class AVT>
27 mClass(Algo) TopList
28 {
29 public:
30  TopList( int maxsize )
31  : maxsize_( maxsize ) {}
32 
33  virtual ~TopList() {}
34 
35  inline void reset();
38  inline VT getValue(int rank) const;
39  inline AVT getAssociatedValue(int rank) const;
40 
41  inline bool getHighestValue( VT& ) const;
42  inline bool getLowestValue( VT& ) const;
43 
44  inline int size() const;
45  inline int isEmpty() const { return !size(); }
46 
47  inline void addValue( VT val, AVT aval );
48 private:
49 
51  const int maxsize_;
52 };
53 
54 
55 template <class VT, class AVT> inline
57 {
58  values_.erase();
59 }
60 
61 
62 template <class VT, class AVT> inline
63 VT TopList<VT,AVT>::getValue(int pos) const
64 { return values_[pos].first; }
65 
66 
67 template <class VT, class AVT> inline
69 { return values_[pos].second; }
70 
71 
72 template <class VT, class AVT> inline
74 { return values_.size(); }
75 
76 
77 
78 template <class VT, class AVT> inline
79 bool TopList<VT,AVT>::getHighestValue( VT& res ) const
80 {
81  if ( size() )
82  {
83  res = values_[0].first;
84  return true;
85  }
86 
87  return false;
88 }
89 
90 
91 template <class VT, class AVT> inline
92 bool TopList<VT,AVT>::getLowestValue( VT& res ) const
93 {
94  const int sz = size();
95  if ( sz )
96  {
97  res = values_[sz-1].first;
98  return true;
99  }
100 
101  return false;
102 }
103 
104 
105 
106 template <class VT, class AVT> inline
107 void TopList<VT,AVT>::addValue( VT val, AVT aval )
108 {
109  int pos = 0;
110  const int mysize = size();
111 
112  while ( pos<mysize && values_[pos].first>val ) pos++;
113 
114  if ( pos==mysize )
115  {
116  if ( mysize>=maxsize_ )
117  return;
118 
119  values_ += std::pair<VT,AVT>( val, aval );
120  }
121  else
122  {
123  values_.insert( pos, std::pair<VT,AVT>(val,aval) );
124 
125  if ( mysize==maxsize_ )
126  values_.removeSingle(mysize);
127  }
128 }
129 #endif
AVT getAssociatedValue(int rank) const
Definition: toplist.h:68
bool getHighestValue(VT &) const
Definition: toplist.h:79
int isEmpty() const
Definition: toplist.h:45
bool getLowestValue(VT &) const
Definition: toplist.h:92
int size() const
Definition: toplist.h:73
TypeSet< std::pair< VT, AVT > > values_
Definition: toplist.h:50
VT getValue(int rank) const
Definition: toplist.h:63
void addValue(VT val, AVT aval)
Definition: toplist.h:107
Is a class that holds a "top N" list with the N highest (or lowest) values that is added...
Definition: houghtransform.h:23
Set of (small) copyable elements.
Definition: commontypes.h:30
const int maxsize_
Definition: toplist.h:51
TopList(int maxsize)
Definition: toplist.h:30
virtual ~TopList()
Definition: toplist.h:33
#define mClass(module)
Definition: commondefs.h:164
void reset()
Definition: toplist.h:56

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2019