ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
Gluco2::Heap< Comp > Class Template Reference

#include <Heap.h>

Public Member Functions

 Heap (const Comp &c)
 
int size () const
 
bool empty () const
 
bool inHeap (int n) const
 
int operator[] (int index) const
 
void decrease (int n)
 
void increase (int n)
 
void prelocate (int ext_cap)
 
void update (int n)
 
void insert (int n)
 
int removeMin ()
 
void build (vec< int > &ns)
 
void clear (bool dealloc=false)
 
void clear_ (bool dealloc=false)
 

Detailed Description

template<class Comp>
class Gluco2::Heap< Comp >

Definition at line 35 of file Heap.h.

Constructor & Destructor Documentation

◆ Heap()

template<class Comp>
Gluco2::Heap< Comp >::Heap ( const Comp & c)
inline

Definition at line 78 of file Heap.h.

78: lt(c) { }

Member Function Documentation

◆ build()

template<class Comp>
void Gluco2::Heap< Comp >::build ( vec< int > & ns)
inline

Definition at line 125 of file Heap.h.

125 {
126 int i;
127 for (i = 0; i < heap.size(); i++)
128 indices[heap[i]] = -1;
129 heap.clear();
130
131 for (i = 0; i < ns.size(); i++){
132 indices[ns[i]] = i;
133 heap.push(ns[i]); }
134
135 for (i = heap.size() / 2 - 1; i >= 0; i--)
136 percolateDown(i);
137 }
void clear(bool dealloc=false)
Definition Heap.h:139
int size() const
Definition Heap.h:80
Here is the call graph for this function:

◆ clear()

template<class Comp>
void Gluco2::Heap< Comp >::clear ( bool dealloc = false)
inline

Definition at line 139 of file Heap.h.

140 {
141 int i;
142 for (i = 0; i < heap.size(); i++)
143 indices[heap[i]] = -1;
144 heap.clear(dealloc);
145 }

◆ clear_()

template<class Comp>
void Gluco2::Heap< Comp >::clear_ ( bool dealloc = false)
inline

Definition at line 146 of file Heap.h.

147 {
148 int i;
149 for (i = 0; i < heap.size(); i++)
150 indices[heap[i]] = -1;
151
152 if( ! dealloc ) heap.shrink_( heap.size() );
153 else heap.clear(true);
154 }

◆ decrease()

template<class Comp>
void Gluco2::Heap< Comp >::decrease ( int n)
inline

Definition at line 86 of file Heap.h.

86{ assert(inHeap(n)); percolateUp (indices[n]); }
bool inHeap(int n) const
Definition Heap.h:82
#define assert(ex)
Definition util_old.h:213
Here is the call graph for this function:

◆ empty()

template<class Comp>
bool Gluco2::Heap< Comp >::empty ( ) const
inline

Definition at line 81 of file Heap.h.

81{ return heap.size() == 0; }

◆ increase()

template<class Comp>
void Gluco2::Heap< Comp >::increase ( int n)
inline

Definition at line 87 of file Heap.h.

87{ assert(inHeap(n)); percolateDown(indices[n]); }
Here is the call graph for this function:

◆ inHeap()

template<class Comp>
bool Gluco2::Heap< Comp >::inHeap ( int n) const
inline

Definition at line 82 of file Heap.h.

82{ return n < indices.size() && indices[n] >= 0; }
Here is the caller graph for this function:

◆ insert()

template<class Comp>
void Gluco2::Heap< Comp >::insert ( int n)
inline

Definition at line 101 of file Heap.h.

102 {
103 indices.growTo(n+1, -1);
104 assert(!inHeap(n));
105
106 indices[n] = heap.size();
107 heap.push(n);
108 percolateUp(indices[n]);
109 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator[]()

template<class Comp>
int Gluco2::Heap< Comp >::operator[] ( int index) const
inline

Definition at line 83 of file Heap.h.

83{ assert(index < heap.size()); return heap[index]; }

◆ prelocate()

template<class Comp>
void Gluco2::Heap< Comp >::prelocate ( int ext_cap)
inline

Definition at line 88 of file Heap.h.

88{ indices.prelocate(ext_cap); }

◆ removeMin()

template<class Comp>
int Gluco2::Heap< Comp >::removeMin ( )
inline

Definition at line 112 of file Heap.h.

113 {
114 int x = heap[0];
115 heap[0] = heap.last();
116 indices[heap[0]] = 0;
117 indices[x] = -1;
118 heap.pop();
119 if (heap.size() > 1) percolateDown(0);
120 return x;
121 }

◆ size()

template<class Comp>
int Gluco2::Heap< Comp >::size ( ) const
inline

Definition at line 80 of file Heap.h.

80{ return heap.size(); }

◆ update()

template<class Comp>
void Gluco2::Heap< Comp >::update ( int n)
inline

Definition at line 91 of file Heap.h.

92 {
93 if (!inHeap(n))
94 insert(n);
95 else {
96 percolateUp(indices[n]);
97 percolateDown(indices[n]); }
98 }
void insert(int n)
Definition Heap.h:101
Here is the call graph for this function:

The documentation for this class was generated from the following file: