heap_rep< C > Class Template Reference

#include <heap.hpp>

Inheritance diagram for heap_rep< C >:
rep_struct

List of all members.

Public Member Functions

Public Attributes

Friends


Detailed Description

template<typename C>
class mmx::heap_rep< C >

Definition at line 39 of file heap.hpp.


Constructor & Destructor Documentation

heap_rep ( comparison  compare2  )  [inline]
heap_rep ( C a2,
nat  n2,
nat  l2,
comparison  compare2 
) [inline]
~heap_rep (  )  [inline]

Member Function Documentation

void correct_downwards (  )  [inline]

Definition at line 117 of file heap.hpp.

References mmx::swap().

Referenced by heap_rep< C >::Pull(), and heap_rep< C >::Set_top().

00117                              {
00118   nat i= 0;
00119   while (true) {
00120     nat l= (i<<1) + 1, r= l+1;
00121     if (l >= n) break;
00122     if (compare (a[i], a[l])) {
00123       if (r >= n || compare (a[i], a[r])) break;
00124       else {
00125         swap (a[i], a[r]);
00126         i= r;
00127       }
00128     }
00129     else {
00130       if (r >= n || compare (a[i], a[r]) || compare (a[l], a[r])) {
00131         swap (a[i], a[l]);
00132         i= l;
00133       }
00134       else {
00135         swap (a[i], a[r]);
00136         i= r;
00137       }
00138     }
00139   }
00140 }

void correct_upwards (  )  [inline]

Definition at line 143 of file heap.hpp.

References mmx::swap().

Referenced by heap_rep< C >::Push().

00143                            {
00144   nat i= n-1;
00145   while (i>0) {
00146     nat u= (i-1) >> 1;
00147     if (compare (a[u], a[i])) break;
00148     else {
00149       swap (a[u], a[i]);
00150       i= u;
00151     }
00152   }
00153 }

C Get_top (  )  const [inline]

Definition at line 163 of file heap.hpp.

References ASSERT.

00163                          {
00164   ASSERT (n>0, "non-empty heap expected");
00165   return a[0];
00166 }

C Pull (  )  [inline]

Definition at line 176 of file heap.hpp.

References ASSERT, mmx::C, heap_rep< C >::correct_downwards(), and heap_rep< C >::resize().

00176                 {
00177   ASSERT (n>0, "non-empty heap expected");
00178   C r = a[0];
00179   a[0]= a[n-1];
00180   resize (n-1);
00181   correct_downwards ();
00182   return r;
00183 }

void Push ( const C x  )  [inline]

Definition at line 169 of file heap.hpp.

References heap_rep< C >::correct_upwards(), and heap_rep< C >::resize().

00169                           {
00170   resize (n+1);
00171   a[n-1]= x;
00172   correct_upwards ();
00173 }

void resize ( nat  n2  )  [inline]

Definition at line 103 of file heap.hpp.

References mmx::C, mmx::min(), and n.

Referenced by heap_rep< C >::Pull(), and heap_rep< C >::Push().

00103                         {
00104   if (n2 > l || n2 < ((l+1)>>1)) {
00105     nat l2= (((n2 < ((l+1)>>1)) || (n2 > (l<<1))) ? n2: l<<1);
00106     C* b= mmx_new<C> (l2);
00107     nat nn= min (n, n2);
00108     for (nat i=0; i<nn; i++) b[i]= a[i];
00109     mmx_delete<C> (a, l);
00110     a= b;
00111     l= l2;
00112   }
00113   n= n2;
00114 }

void Set_top ( const C x  )  [inline]

Definition at line 156 of file heap.hpp.

References ASSERT, and heap_rep< C >::correct_downwards().

00156                              {
00157   ASSERT (n>0, "non-empty heap expected");
00158   a[0]= x;
00159   correct_downwards ();
00160 }


Friends And Related Function Documentation

heap<C> copy ( const heap< C > &  h  )  [friend]

Definition at line 247 of file heap.hpp.

00247                      {
00248   C* b= mmx_new<C> (h->l);
00249   for (nat i=0; i<h->n; i++) b[i]= h->a[i];
00250   return Heap (b, h->n, h->l, h->compare);
00251 }

C get_top ( const heap< C > &  h  )  [friend]

Definition at line 187 of file heap.hpp.

00187                                       {
00188   return h.rep->Get_top (); }

friend class heap< C > [friend]

Definition at line 62 of file heap.hpp.

nat N ( const heap< C > &  h  )  [friend]

Definition at line 193 of file heap.hpp.

00193                                   {
00194   return l.rep->n; }

C pull ( heap< C > &  h  )  [friend]

Definition at line 191 of file heap.hpp.

00191                              {
00192   h.secure(); return h.rep->Pull (); }

void push ( heap< C > &  h,
const C x 
) [friend]

Definition at line 189 of file heap.hpp.

00189                                             {
00190   h.secure(); h.rep->Push (x); }

void set_top ( heap< C > &  h,
const C x 
) [friend]

Definition at line 185 of file heap.hpp.

00185                                                {
00186   h.secure(); h.rep->Set_top (x); }


Member Data Documentation

MMX_ALLOCATORS int ref_count [inherited]

Definition at line 164 of file basix.hpp.


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

Generated on 6 Dec 2012 for basix by  doxygen 1.6.1