/*
....[@@@..[@@@..............[@.................. MUD++ is a written from
....[@..[@..[@..[@..[@..[@@@@@....[@......[@.... scratch multi-user swords and
....[@..[@..[@..[@..[@..[@..[@..[@@@@@..[@@@@@.. sorcery game written in C++.
....[@......[@..[@..[@..[@..[@....[@......[@.... This server is an ongoing
....[@......[@..[@@@@@..[@@@@@.................. development project. All
................................................ contributions are welcome.
....Copyright(C).1995.Melvin.Smith.............. Enjoy.
------------------------------------------------------------------------------
Melvin Smith (aka Fusion) msmith@hom.net
MUD++ development mailing list mudpp@van.ml.org
------------------------------------------------------------------------------
hash.h
*/
#ifndef _HASH_H
#define _HASH_H
#include "string.h"
#include "llist.h"
class HashNode
{
public:
String key;
void * obj;
HashNode()
: obj(0)
{
}
HashNode( const String & x, void * y )
: key( x ), obj( y )
{
}
void * getObj() const { return obj; }
void setObj( void * x ) { obj = x; }
const String & getKey() const { return key; }
void setKey( const String & x ) { key = x; }
};
#define HASH_KEY 64
// An array of LList objects.
template< class T >
class HashTable
{
private:
LList< HashNode > table[ HASH_KEY ];
int ihash;
public:
HashTable()
: ihash(0)
{
}
void add( const String &, T * );
int getHashKey( const char * );
int getHashKey( const String & x ) { return getHashKey( x.chars() ); }
T *lookup( const String & );
T *lookup( const char * );
void remove( const String & );
void remove( const char * );
void removeAllInstancesOf( T * );
// List-like iteration interface
void reset() const;
void clr(); // Destroys all nodes within index
const HashTable & next() const;
T * peek() const;
T * remove();
const String & getKey() const;
};
#endif