Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Hashtable< KEY, VALUE, SIZ > Class Template Reference

#include <hashtable.h>

Inheritance diagram for Hashtable< KEY, VALUE, SIZ >:

Public Member Functions

std::vector< VALUE * > GetAll () const
 
VALUE * Get (const KEY &key) const
 
void Put (const KEY &key, VALUE *value)
 
void Delete (const KEY &key)
 

Static Public Member Functions

static int hash (const int key)
 
static int hash (const char *key)
 
static int hash (const std::string &key)
 

Detailed Description

template<class KEY, class VALUE, int SIZ>
class Hashtable< KEY, VALUE, SIZ >

Definition at line 38 of file hashtable.h.

Member Function Documentation

template<class KEY, class VALUE, int SIZ>
void Hashtable< KEY, VALUE, SIZ >::Delete ( const KEY &  key)
inline

Definition at line 97 of file hashtable.h.

Referenced by collideTrees::Dec(), Unit::GetCargo(), Mesh::Mesh(), StarSystem::RemoveStarsystemFromUniverse(), Logo::~Logo(), and Mesh::~Mesh().

98  {
99  typename supertype::iterator iter = this->find( key );
100  if ( iter == this->end() )
101 //fprintf(stderr,"failed to remove item in hash_map\n");
102  return;
103  this->erase( iter );
104  }
template<class KEY, class VALUE, int SIZ>
VALUE* Hashtable< KEY, VALUE, SIZ >::Get ( const KEY &  key) const
inline

Definition at line 84 of file hashtable.h.

Referenced by Box::Box(), UnitUtil::commAnimation(), CompilePython(), collideTrees::Get(), Unit::GetCargo(), GetLoadedStarSystem(), Mesh::getLOD(), Mesh::getNumAnimationFrames(), StarSystem::JumpTo(), Mesh::LoadExistant(), XMLSupport::EnumMap::lookup(), Mesh::Mesh(), StarSystem::RemoveStarsystemFromUniverse(), Logo::SetDecal(), and Mesh::~Mesh().

85  {
86  typename supertype::const_iterator iter = this->find( key );
87  typename supertype::const_iterator end = this->end();
88  if (iter != end) return iter->second;
89  return NULL;
90  }
template<class KEY, class VALUE, int SIZ>
std::vector< VALUE* > Hashtable< KEY, VALUE, SIZ >::GetAll ( ) const
inline

Definition at line 73 of file hashtable.h.

74  {
75  std::vector< VALUE* >retval( this->size() );
76  typename supertype::const_iterator iter = this->begin();
77  typename supertype::const_iterator end = this->end();
78  size_t i = 0;
79  for (; iter != end; ++iter, ++i)
80  retval[i] = iter->second;
81  return retval;
82  }
template<class KEY, class VALUE, int SIZ>
static int Hashtable< KEY, VALUE, SIZ >::hash ( const int  key)
inlinestatic

Definition at line 43 of file hashtable.h.

44  {
45  unsigned int k = key;
46  k %= SIZ;
47  return k;
48  }
template<class KEY, class VALUE, int SIZ>
static int Hashtable< KEY, VALUE, SIZ >::hash ( const char *  key)
inlinestatic

Definition at line 49 of file hashtable.h.

50  {
51  unsigned int k = 0;
52  for (const char *start = key; *start != '\0'; ++start) {
53  k ^= (*start&HASH_SALT_1);
54  k ^= HASH_SALT_0;
55  k = ( ( (k>>4)&0xF )|( k<<(HASH_INTSIZE-4) ) );
56  k ^= *start;
57  }
58  k %= SIZ;
59  return k;
60  }
template<class KEY, class VALUE, int SIZ>
static int Hashtable< KEY, VALUE, SIZ >::hash ( const std::string &  key)
inlinestatic

Definition at line 61 of file hashtable.h.

62  {
63  unsigned int k = 0;
64  for (typename std::string::const_iterator start = key.begin(); start != key.end(); ++start) {
65  k ^= (*start&HASH_SALT_1);
66  k ^= HASH_SALT_0;
67  k = ( ( (k>>4)&0xF )|( k<<(HASH_INTSIZE-4) ) );
68  k ^= *start;
69  }
70  k %= SIZ;
71  return k;
72  }
template<class KEY, class VALUE, int SIZ>
void Hashtable< KEY, VALUE, SIZ >::Put ( const KEY &  key,
VALUE *  value 
)
inline

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