hash_map< K, T > Class Template Reference


Public Types

typedef unsigned int size_type
typedef std::pair< const K,
T > 
value_type
typedef hash_map_iterator iterator
typedef hash_map_iterator const_iterator

Public Member Functions

 hash_map (const T &dv=T(), size_type n=107)
 ~hash_map ()
void set_load (float m=0.7, float g=1.7)
size_type size () const
size_type bucket_count () const
void resize (size_type s)
T & operator[] (const K &key)
iterator find (const K &key) const
size_type erase (const K &key)
void clear ()
iterator end () const

Data Structures

struct  Entry
class  hash_map_iterator

Detailed Description

template<class K, class T>
class hash_map< K, T >

Definition at line 25 of file hash_map.icc.


Member Typedef Documentation

template<class K, class T>
typedef hash_map_iterator hash_map< K, T >::const_iterator

Definition at line 52 of file hash_map.icc.

template<class K, class T>
typedef hash_map_iterator hash_map< K, T >::iterator

Definition at line 51 of file hash_map.icc.

template<class K, class T>
typedef unsigned int hash_map< K, T >::size_type

Definition at line 49 of file hash_map.icc.

template<class K, class T>
typedef std::pair<const K,T> hash_map< K, T >::value_type

Definition at line 50 of file hash_map.icc.


Constructor & Destructor Documentation

template<class K, class T>
hash_map< K, T >::hash_map ( const T &  dv = T(),
size_type  n = 107 
) [inline]

Definition at line 83 of file hash_map.icc.

References CLHEP::detail::n, hash_map< K, T >::resize(), and hash_map< K, T >::set_load().

00084     : table(0), cur_size(0), max_size(0), default_value(dv)
00085   {
00086     set_load();
00087     resize(n);
00088   }

template<class K, class T>
hash_map< K, T >::~hash_map (  )  [inline]

Definition at line 91 of file hash_map.icc.

References CLHEP::detail::n, and hash_map< K, T >::Entry::next.

00091               {
00092     for(size_type i=0; i<max_size; i++) {
00093       Entry* n = table[i];
00094       while(n) { Entry* p = n; n = p->next; delete p; }
00095     }
00096     delete [] table;
00097   }    


Member Function Documentation

template<class K, class T>
size_type hash_map< K, T >::bucket_count (  )  const [inline]

Definition at line 106 of file hash_map.icc.

00106 { return max_size; }

template<class K, class T>
void hash_map< K, T >::clear (  )  [inline]

Definition at line 171 of file hash_map.icc.

References G4InuclParticleNames::pp.

00171                {
00172     for(size_type i=0; i<max_size; i++) {
00173       for (Entry* p=table[i]; p;) {
00174         Entry* pp = p; p = p->next; delete pp;
00175       }
00176     table[i] = 0;
00177     }
00178     cur_size = 0;
00179   }

template<class K, class T>
iterator hash_map< K, T >::end (  )  const [inline]

Definition at line 182 of file hash_map.icc.

Referenced by hash_map< K, T >::find().

00182 { return iterator(); }

template<class K, class T>
size_type hash_map< K, T >::erase ( const K &  key  )  [inline]

Definition at line 152 of file hash_map.icc.

References hash_map< K, T >::Entry::data, hash_map< K, T >::Entry::next, and G4InuclParticleNames::pp.

00152                                  {
00153     size_type i = hash(key) % max_size;
00154     Entry* p = table[i];
00155     if (p == 0) return 0;
00156     if (eq(key,p->data.first)) {
00157       table[i] = p->next; delete p; cur_size--; return 1;
00158     }
00159     Entry** pp = &table[i];
00160     for (p=p->next; p; p=p->next) {
00161       if (eq(key,p->data.first)) {
00162         *pp = p->next; delete p; cur_size--; return 1;
00163       }else{
00164         pp = &(p->next);
00165       }
00166     }
00167     return 0;
00168   }

template<class K, class T>
iterator hash_map< K, T >::find ( const K &  key  )  const [inline]

Definition at line 143 of file hash_map.icc.

References hash_map< K, T >::end(), and hash_map< K, T >::Entry::next.

00143                                      {
00144     size_type i = hash(key) % max_size;
00145     for (Entry* p=table[i]; p; p=p->next) {
00146       if (eq(key,p->data.first)) return iterator(*p);
00147     }
00148     return end();
00149   }

template<class K, class T>
T& hash_map< K, T >::operator[] ( const K &  key  )  [inline]

Definition at line 129 of file hash_map.icc.

References hash_map< K, T >::Entry::data, and hash_map< K, T >::resize().

00129                                 {
00130     size_type i = hash(key) % max_size;
00131     for (Entry* p=table[hash(key) % max_size]; p; p=p->next) {
00132       if (eq(key,p->data.first)) return p->data.second;
00133     }
00134     if (cur_size++ >= max_size*max_load) {
00135       resize(size_type(max_size*grow));
00136       i = hash(key) % max_size;
00137     }
00138     table[i] = new Entry(key, default_value, table[i]);
00139     return table[i]->data.second;
00140   }

template<class K, class T>
void hash_map< K, T >::resize ( size_type  s  )  [inline]

Definition at line 109 of file hash_map.icc.

References CLHEP::detail::n, and hash_map< K, T >::Entry::next.

Referenced by hash_map< K, T >::hash_map(), and hash_map< K, T >::operator[]().

00109                            {
00110     if (s <= max_size) return;
00111     Entry** tmp = table;
00112     table = new Entry* [s];
00113     for (size_type k=0; k<s; k++) table[k] = 0;
00114     for (size_type i=0; i<max_size; i++) {
00115       Entry* n = tmp[i];
00116       while(n) {
00117         Entry* p = n;
00118         n = p->next;
00119         size_type ii = hash(p->data.first) % s;
00120         p->next = table[ii];
00121         table[ii] = p;
00122       }
00123     }
00124     max_size = s;
00125     delete [] tmp;
00126   }

template<class K, class T>
void hash_map< K, T >::set_load ( float  m = 0.7,
float  g = 1.7 
) [inline]

Definition at line 100 of file hash_map.icc.

Referenced by hash_map< K, T >::hash_map().

00100 { max_load = m; grow = g; } 

template<class K, class T>
size_type hash_map< K, T >::size (  )  const [inline]

Definition at line 103 of file hash_map.icc.

00103 { return cur_size; }


The documentation for this class was generated from the following file:
Generated on Mon May 27 17:54:03 2013 for Geant4 by  doxygen 1.4.7