SystemC  2.3.2
Accellera SystemC proof-of-concept library
sc_pq.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements. See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License. You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
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
15  implied. See the License for the specific language governing
16  permissions and limitations under the License.
17 
18  *****************************************************************************/
19 
20 /*****************************************************************************
21 
22  sc_pq.h -- A simple priority queue (which can be used to model multiple
23 */
34 #ifndef SC_PQ_H
35 #define SC_PQ_H
36 
37 
38 #include "sysc/kernel/sc_cmnhdr.h"
39 
40 namespace sc_core {
41 
49 {
50 public:
51 
52  typedef int (*compare_fn_t)( const void*, const void* );
53 
54  sc_ppq_base( int sz, compare_fn_t cmp );
55 
56  ~sc_ppq_base();
57 
58  void* top() const
59  { return m_heap[1]; }
60 
61  void* extract_top();
62 
63  void insert( void* elem );
64 
65  int size() const
66  { return m_heap_size; }
67 
68  bool empty() const
69  { return (m_heap_size == 0); }
70 
71 protected:
72 
73  int parent( int i ) const
74  { return i >> 1; }
75 
76  int left( int i ) const
77  { return i << 1; }
78 
79  int right( int i ) const
80  { return (i << 1) + 1; }
81 
82  void heapify( int i );
83 
84 private:
85 
86  void** m_heap;
87  int m_size_alloc;
88  int m_heap_size;
89  compare_fn_t m_compar;
90 };
91 
92 
101 template <class T>
102 class sc_ppq
103  : public sc_ppq_base
104 {
105 public:
106 
107  // constructor - specify the maximum size of the queue and
108  // give a comparison function.
109 
110  sc_ppq( int sz, compare_fn_t cmp )
111  : sc_ppq_base( sz, cmp )
112  {}
113 
115  {}
116 
117  // returns the value of the top element in the priority queue.
118  T top() const
119  { return (T) sc_ppq_base::top(); }
120 
121  // pops the first element of the priority queue.
122 
124  { return (T) sc_ppq_base::extract_top(); }
125 
126  // insert a new element to the priority queue.
127 
128  void insert( T elem )
129  { sc_ppq_base::insert( (void*) elem ); }
130 
131  // size() and empty() are inherited.
132 };
133 
134 } // namespace sc_core
135 
136 // $Log: sc_pq.h,v $
137 // Revision 1.5 2011/08/29 18:04:32 acg
138 // Philipp A. Hartmann: miscellaneous clean ups.
139 //
140 // Revision 1.4 2011/08/26 20:46:18 acg
141 // Andy Goodrich: moved the modification log to the end of the file to
142 // eliminate source line number skew when check-ins are done.
143 //
144 // Revision 1.3 2011/08/24 22:05:56 acg
145 // Torsten Maehne: initialization changes to remove warnings.
146 //
147 // Revision 1.2 2011/02/18 20:38:44 acg
148 // Andy Goodrich: Updated Copyright notice.
149 //
150 // Revision 1.1.1.1 2006/12/15 20:20:06 acg
151 // SystemC 2.3
152 //
153 // Revision 1.3 2006/01/13 18:53:11 acg
154 // Andy Goodrich: Added $Log command so that CVS comments are reproduced in
155 // the source.
156 //
157 
158 #endif
sc_ppq(int sz, compare_fn_t cmp)
Definition: sc_pq.h:110
int right(int i) const
Definition: sc_pq.h:79
T extract_top()
Definition: sc_pq.h:123
void insert(T elem)
Definition: sc_pq.h:128
void insert(void *elem)
int left(int i) const
Definition: sc_pq.h:76
int size() const
Definition: sc_pq.h:65
Priority queue base class.
Definition: sc_pq.h:48
int parent(int i) const
Definition: sc_pq.h:73
bool empty() const
Definition: sc_pq.h:68
#define SC_API
Definition: sc_cmnhdr.h:168
T top() const
Definition: sc_pq.h:118
void * top() const
Definition: sc_pq.h:58