creaImageIO_lib
creaImageIOIndexedHeap.h
Go to the documentation of this file.
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # pour la Santé)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 #
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
16 #
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
21 # liability.
22 #
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
26 */
27 
28 
29 /*
30 
31 */
35 #ifndef __creaImageIOIndexedHeap_h_INCLUDED__
36 #define __creaImageIOIndexedHeap_h_INCLUDED__
37 
38 #include <vector>
39 
40 namespace creaImageIO
41 {
42 
43 
44 
45  template <class T,
46  class Comparator/*=Less<T>*/,
47  class Indexer/*=Index<T> */>
48  class IndexedHeap ;
49  template < class T,
50  class C,
51  class I>
52  std::ostream& operator << (std::ostream&, const IndexedHeap<T,C,I>& );
53 
54 
55  //template <class T, class Comparator=std::less<T>, class Index=IndexIndex<T> > class SlicedIndexedHeap;
56 
57 
58  //========================================================================
74  template <class T,
75  class Comparator /*=Less<T>*/,
76  class Indexer /*=Index<T>*/>
77  class IndexedHeap
78  {
79  // friend class SlicedIndexedHeap<T,Comparator,Index>;
80  public :
81 
82  //======================================================================
86  IndexedHeap ( const Comparator& comp, const Indexer& ind ) ;
90  void set( const Comparator& comp );
92  void set( const Indexer& ind );
93  //======================================================================
94 
95  //======================================================================
97  int insert(T);
99  T& top();
101  const T& top() const;
103  T remove_top();
105  T remove(int n);
107  inline int size() const {return (int)m_p.size(); }
109  void clear();
110  //======================================================================
111 
112  //======================================================================
114  const std::vector<T> & stack() const {return m_p;}
116  T& operator [] (int i) { return m_p[i];}
118  const T& operator [] (int i) const { return m_p[i];}
120  inline int index(T& t) { return (*m_i)(t); }
121  //======================================================================
122 
123  //======================================================================
125  inline int father( int i ) const;
127  inline int rightson( int i ) const;
129  inline int leftson( int i ) const;
130  //======================================================================
132  inline void swap(int i, int j);
135  inline int upsort(int);
138  inline int downsort(int);
139  //======================================================================
140 
141  protected :
143  std::vector<T> m_p;
145  const Comparator* m_c;
147  const Indexer* m_i;
148  };
149  //========================================================================
150  // EO class IndexedHeap
151  //========================================================================
152 
153 
155 
156 
157 };
158 //===========================================================================
159 // EO namespace creaImageIO
160 //===========================================================================
161 
162 
163 
164 //===========================================================================
165 // EOF
166 //===========================================================================
167 #endif