table_rep< C, T, V > Class Template Reference

#include <table.hpp>

Inheritance diagram for table_rep< C, T, V >:
rep_struct encapsulate1< format< C > > encapsulate2< format< T > > format< C > format< T > empty_format empty_format

List of all members.

Public Types

Public Member Functions

Public Attributes

Friends


Detailed Description

template<typename C, typename T, typename V = exact_eq_table>
class mmx::table_rep< C, T, V >

Definition at line 68 of file table.hpp.


Member Typedef Documentation

typedef empty_format FT [inherited]

Definition at line 196 of file type_props.hpp.

typedef empty_format FT [inherited]

Definition at line 196 of file type_props.hpp.


Constructor & Destructor Documentation

table_rep ( nat  n2,
const format< C > &  fm1,
const format< T > &  fm2 
) [inline]
table_rep ( const C init2,
nat  n2,
const format< T > &  fm2 
) [inline]
~table_rep (  )  [inline]

Member Function Documentation

double complexity (  )  const [inline]

Definition at line 337 of file table.hpp.

References table_rep< C, T, V >::N.

00337                              {
00338   double sum= 0.0;
00339   //mmout << "{";
00340   for (nat i=0; i<n; i++) {
00341     nat l= N(a[i]);
00342     sum += l*l;
00343     //mmout << " " << l;
00344   }
00345   //mmout << " }";
00346   return sum / n;
00347 }

bool contains ( const T x  )  const [inline]

Definition at line 254 of file table.hpp.

References mmx::is_nil(), mmx::read_car(), and mmx::read_cdr().

00254                                      {
00255   list<pair<T,C> >  l (a [V::key_op::hash_op (x) & (n-1)]);
00256   while (!is_nil (l)) {
00257     if (V::key_op::op (read_car (l).x1, x)) return true;
00258     l= read_cdr (l);
00259   }
00260   return false;
00261 }

empty_format format1 (  )  const [inline, inherited]

Definition at line 189 of file type_props.hpp.

Referenced by mmx::get_format1().

00189 { return empty_format (); }

empty_format format1 (  )  const [inline, inherited]

Definition at line 189 of file type_props.hpp.

Referenced by mmx::get_format1().

00189 { return empty_format (); }

empty_format format2 (  )  const [inline, inherited]

Definition at line 190 of file type_props.hpp.

Referenced by mmx::get_format2().

00190 { return empty_format (); }

empty_format format2 (  )  const [inline, inherited]

Definition at line 190 of file type_props.hpp.

Referenced by mmx::get_format2().

00190 { return empty_format (); }

empty_format format3 (  )  const [inline, inherited]

Definition at line 191 of file type_props.hpp.

00191 { return empty_format (); }

empty_format format3 (  )  const [inline, inherited]

Definition at line 191 of file type_props.hpp.

00191 { return empty_format (); }

const C & get ( const T x  )  const [inline]

Definition at line 296 of file table.hpp.

References mmx::is_nil(), table_rep< C, T, V >::lazy_initialize(), mmx::read_car(), and mmx::read_cdr().

00296                                 {
00297   list<pair<T,C> > l (a [V::key_op::hash_op (x) & (n-1)]);
00298   while (!is_nil (l)) {
00299     if (V::key_op::op (read_car (l).x1, x)) return read_car (l).x2;
00300     l= read_cdr (l);
00301   }
00302   lazy_initialize ();
00303   return *init;
00304 }

bool get ( const T x,
C y 
) const [inline]

Definition at line 264 of file table.hpp.

References mmx::is_nil(), mmx::read_car(), and mmx::read_cdr().

00264                                       {
00265   list<pair<T,C> >  l (a [V::key_op::hash_op (x) & (n-1)]);
00266   while (!is_nil (l)) {
00267     if (V::key_op::op (read_car (l).x1, x)) {
00268       y= read_car (l).x2;
00269       return true;
00270     }
00271     l= read_cdr (l);
00272   }
00273   return false;
00274 }

void lazy_initialize (  )  const [inline]

Definition at line 103 of file table.hpp.

Referenced by table_rep< C, T, V >::get(), table_rep< C, T, V >::set(), and table_rep< C, T, V >::simplify().

00103                                        {
00104     if (init == NULL) {
00105       *((C**) ((void*) &init))= mmx_new_one<C> ();
00106       //mmout << "[:init=" << init << "," << this
00107       //<< ";" << ((int*) ((void*) init))[-1]
00108       //<< "]" << flush_now;
00109     }
00110   }

void reset ( const T x  )  [inline]

Definition at line 307 of file table.hpp.

References mmx::cdr(), mmx::is_nil(), mmx::read_car(), mmx::read_cdr(), and table_rep< C, T, V >::resize().

00307                             {
00308   list<pair<T,C> > *l= &(a [V::key_op::hash_op (x) & (n-1)]);
00309   while (!is_nil (*l)) {
00310     if (V::key_op::op (read_car (*l).x1, x)) {
00311       *l= read_cdr (*l);
00312       size --;
00313       if (size < (n>>1)) resize (n>>1);
00314       return;
00315     }
00316     l= &cdr (*l);
00317   }
00318 }

void resize ( nat  n  )  [inline]

Definition at line 232 of file table.hpp.

References mmx::cons(), mmx::is_nil(), mmx::read_car(), and mmx::read_cdr().

Referenced by table_rep< C, T, V >::reset(), table_rep< C, T, V >::set(), and table_rep< C, T, V >::simplify().

00232                          {
00233   nat i, oldn= n;
00234   list<pair<T,C> >* olda= a;
00235   n= n2;
00236   a= mmx_new<list<pair<T,C> > > (n);
00237   for (i=0; i<oldn; i++) {
00238     list<pair<T,C> > l (olda [i]);
00239     while (!is_nil (l)) {
00240       nat code= V::key_op::hash_op (read_car(l).x1);
00241       list<pair<T,C> >& newl= a [code & (n-1)];
00242       newl= cons (read_car (l), newl);
00243       l= read_cdr (l);
00244     }
00245   }
00246   mmx_delete<list<pair<T,C> > > (olda, oldn);
00247   //double acc= 0.0;
00248   //for (i=0; i<n; i++)
00249   //acc += N(a[i]) * N(a[i]);
00250   //mmout << "Access ratio: " << (acc/n) << " out of " << n << "\n";
00251 }

empty_format rfm (  )  const [inline, inherited]

Definition at line 188 of file type_props.hpp.

00188 { return *this; }

empty_format rfm (  )  const [inline, inherited]

Definition at line 188 of file type_props.hpp.

00188 { return *this; }

T sample (  )  const [inline, inherited]

Definition at line 202 of file type_props.hpp.

00202 { return C(); }

C sample (  )  const [inline, inherited]

Definition at line 202 of file type_props.hpp.

Referenced by mmx::get_sample().

00202 { return C(); }

C & set ( const T x  )  [inline]

Definition at line 277 of file table.hpp.

References mmx::car(), mmx::cdr(), mmx::cons(), mmx::is_nil(), table_rep< C, T, V >::lazy_initialize(), mmx::read_car(), and table_rep< C, T, V >::resize().

00277                           {
00278   register nat hv= V::key_op::hash_op (x);
00279   list<pair<T,C> >* l= &(a [hv & (n-1)]);
00280   while (!is_nil (*l)) {
00281     if (V::key_op::op (read_car (*l).x1, x))
00282       return car (*l).x2;
00283     l= &cdr (*l);
00284   }
00285   //mmout << "size= " << size << ", n= " << n << "\n";
00286   if (size>=n) resize (n<<1);
00287   //mmout << "Resized\n";
00288   lazy_initialize ();
00289   l= &a [hv & (n-1)];
00290   *l= cons (pair<T,C> (x, *init), *l);
00291   size ++;
00292   return car (*l).x2;
00293 }

void simplify (  )  [inline]

Definition at line 321 of file table.hpp.

References mmx::cdr(), mmx::is_nil(), table_rep< C, T, V >::lazy_initialize(), mmx::read_car(), mmx::read_cdr(), and table_rep< C, T, V >::resize().

00321                      {
00322   lazy_initialize ();
00323   for (nat i=0; i<n; i++) {
00324     list<pair<T,C> > *l= &(a[i]);
00325     while (!is_nil (*l)) {
00326       if (V::val_op::op (read_car (*l).x2, *init)) {
00327         *l= read_cdr (*l);
00328         size --;
00329       }
00330       else l= &cdr (*l);
00331     }
00332   }
00333   while (size < (n>>1)) resize (n>>1);
00334 }

format<T > tfm (  )  const [inline, inherited]

Definition at line 201 of file type_props.hpp.

00201 { return *this; }

format<C> tfm (  )  const [inline, inherited]

Definition at line 201 of file type_props.hpp.

00201 { return *this; }

format< C > tfm1 (  )  const [inline, inherited]

Definition at line 264 of file type_props.hpp.

00264 { return this->tfm (); }

format< T > tfm2 (  )  const [inline, inherited]

Definition at line 271 of file type_props.hpp.

00271 { return this->tfm (); }


Friends And Related Function Documentation

friend class entries_iterator_rep< C, T, V > [friend]

Definition at line 121 of file table.hpp.

const C& I ( const table< C, T, V > &  t  )  [friend]

Definition at line 215 of file table.hpp.

00215                    {
00216   t->lazy_initialize ();
00217   return *t->init;
00218 }

C& I ( table< C, T, V > &  t  )  [friend]

Definition at line 209 of file table.hpp.

00209              {
00210   t->lazy_initialize ();
00211   return *t->init;
00212 }

nat N ( const table< C, T, V > &  t  )  [friend]

Definition at line 227 of file table.hpp.

Referenced by table_rep< C, T, V >::complexity().

00227                    {
00228   return t->size;
00229 }

bool operator== ( const table< C, T, V > &  t1,
const table< C, T, V > &  t2 
) [friend]

Definition at line 693 of file table.hpp.

00698 { return unary_map<sqrt_op> (t); }

const C& read_I ( const table< C, T, V > &  t  )  [friend]

Definition at line 221 of file table.hpp.

00221                         {
00222   t->lazy_initialize ();
00223   return *t->init;
00224 }

friend class table< C, T, V > [friend]

Definition at line 120 of file table.hpp.

friend class table_iterator_rep< C, T, V > [friend]

Definition at line 122 of file table.hpp.


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