29 #ifndef __HASHTABLE_H__
30 #define __HASHTABLE_H__
41 template<
class Type >
51 size_t Size(
void )
const;
53 void Set(
const char *key, Type &
value );
54 bool Get(
const char *key, Type **value =
NULL )
const;
55 bool Remove(
const char *key );
62 int Num(
void )
const;
83 int GetHash(
const char *key )
const;
91 template<
class Type >
96 tablesize = newtablesize;
100 memset( heads, 0,
sizeof( *heads ) * tablesize );
104 tablesizemask = tablesize - 1;
112 template<
class Type >
125 for( i = 0; i < tablesize; i++ ) {
126 if ( !map.
heads[ i ] ) {
132 for( node = map.
heads[ i ]; node !=
NULL; node = node->
next ) {
134 prev = &( *prev )->
next;
144 template<
class Type >
155 template<
class Type >
157 return sizeof( heads ) * tablesize +
sizeof( *heads ) * numentries;
165 template<
class Type >
167 return sizeof(
idHashTable<Type> ) +
sizeof( heads ) * tablesize +
sizeof( *heads ) * numentries;
175 template<
class Type >
185 template<
class Type >
190 hash = GetHash( key );
191 for( nextPtr = &(heads[hash]), node = *nextPtr; node !=
NULL; nextPtr = &(node->
next), node = *nextPtr ) {
204 *nextPtr =
new hashnode_s( key, value, heads[ hash ] );
205 (*nextPtr)->next = node;
213 template<
class Type >
218 hash = GetHash( key );
219 for( node = heads[ hash ]; node !=
NULL; node = node->
next ) {
223 *value = &node->
value;
247 template<
class Type >
253 if ( ( index < 0 ) || ( index > numentries ) ) {
259 for( i = 0; i < tablesize; i++ ) {
260 for( node = heads[ i ]; node !=
NULL; node = node->
next ) {
261 if ( count == index ) {
276 template<
class Type >
283 hash = GetHash( key );
284 head = &heads[ hash ];
286 for( prev =
NULL, node = *head; node !=
NULL; prev = node, node = node->
next ) {
287 if ( node->key == key ) {
309 template<
class Type >
315 for( i = 0; i < tablesize; i++ ) {
317 while( next !=
NULL ) {
334 template<
class Type >
340 for( i = 0; i < tablesize; i++ ) {
342 while( next !=
NULL ) {
360 template<
class Type >
365 #if defined(ID_TYPEINFO)
369 #if !defined(__GNUC__) || __GNUC__ < 4
375 template<
class Type >
377 int i, average, error, e;
384 average = numentries / tablesize;
386 for ( i = 0; i < tablesize; i++ ) {
388 for( node = heads[ i ]; node !=
NULL; node = node->
next ) {
391 e = abs( numItems - average );
396 return 100 - (error * 100 / numentries);
400 #if defined(ID_TYPEINFO)
hashnode_s(const char *k, Type v, hashnode_s *n)
GLsizei const GLfloat * value
hashnode_s(const idStr &k, Type v, hashnode_s *n)
assert(prefInfo.fullscreenBtn)
int Cmp(const char *text) const
size_t Allocated(void) const
Type * GetIndex(int index) const
idHashTable(int newtablesize=256)
void DeleteContents(void)
void Set(const char *key, Type &value)
GLuint GLuint GLsizei count
int GetSpread(void) const
bool Remove(const char *key)
static int Hash(const char *string)
static bool IsPowerOfTwo(int x)
bool Get(const char *key, Type **value=NULL) const
int GetHash(const char *key) const