aboutsummaryrefslogtreecommitdiff
path: root/src/hash.h
blob: 8385bb9584fa2348d3bfeca3c98ae3c1311d70b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#ifndef HASH_H
#define HASH_H
/*
#include <stddef.h>
#include <string.h>
#include "hashable.h"

#define bitsToBytes( n ) (n/8+(n%8>0 ? 1 : 0))

template<class key, class value>
class Hash
{
	class iterator
	{
		friend class Hash<key, value>;
	private:
		iterator( Hash<key, value> *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<key, value> *hsh;
		int nIndex;
		bool bInsert;
		key keyval;
	};

	template<class refval>
	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<key>*[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<key> **aKeys;
	unsigned long int *aHashCodes;
	value *aValues;
};
*/
#endif