From 76ed3c164662f4ee4c109bb2054c61c99ea86251 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 26 Jul 2006 21:58:35 +0000 Subject: Added the not-yet-working hash class. More thought must be done. This doesn't actually change any existing code really just adds a new class that you can't use because it's commented out. I'll probably move it to a branch. --- src/hash.h | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 src/hash.h (limited to 'src/hash.h') diff --git a/src/hash.h b/src/hash.h new file mode 100644 index 0000000..8385bb9 --- /dev/null +++ b/src/hash.h @@ -0,0 +1,106 @@ +#ifndef HASH_H +#define HASH_H +/* +#include +#include +#include "hashable.h" + +#define bitsToBytes( n ) (n/8+(n%8>0 ? 1 : 0)) + +template +class Hash +{ + class iterator + { + friend class Hash; + private: + iterator( Hash *hsh, int nIndex, key keyval, bool bInsert ) : + hsh( hsh ), + nIndex( nIndex ), + keyval( keyval ), + bInsert( bInsert ) + { + } + + public: + iterator() : + hsh( NULL ), + nIndex( -1 ) + { + } + + iterator &operator=( iterator &src ) + { + this->hsh = src.hsh; + this->nIndex = src.nIndex; + } + + iterator &operator=( value &src ) + { + if( bInsert ) + printf("You wanted to insert %d\n", src ); + else + printf("You wanted to insert %d\n", src ); + } + + private: + Hash *hsh; + int nIndex; + bool bInsert; + key keyval; + }; + + template + class VRef + { + public: + VRef( refval &data ) : + data( data ) + { + } + refval &data; + }; + +public: + Hash() : + nCapacity( 11 ), + nFilled( 0 ), + bFilled( NULL ), + aKeys( NULL ), + aValues( NULL ), + aHashCodes( NULL ) + { + int nKeysSize = bitsToBytes( nCapacity ); + bFilled = new unsigned char[ nKeysSize ]; + memset( bFilled, 0, nKeysSize ); + + aKeys = new VRef*[nCapacity]; + aValues = new value[nCapacity]; + } + + virtual ~Hash() + { + } + + iterator operator[]( key keyval ) + { + //iterator i( this, 4, keyval, true ); + //return i; + printf("%s\n", keyval.getString() ); + } + + int hasKey( key keyval ) + { + printf("%s\n", keyval.getString() ); + } + +private: + int nCapacity; + int nFilled; + unsigned char *bFilled; + VRef **aKeys; + unsigned long int *aHashCodes; + value *aValues; +}; +*/ +#endif -- cgit v1.2.3