-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashNode.h
More file actions
90 lines (77 loc) · 1.54 KB
/
HashNode.h
File metadata and controls
90 lines (77 loc) · 1.54 KB
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
/* Suyi Liu
* sliu92@jhu.edu
* 600.120 Final Project
* HashNode.h
*/
#ifndef HASHNODE_H
#define HASHNODE_H
#include <iostream>
using std::cout;
using std::endl;
#include "ML_hash.h"
template< typename T > class Structure;
template< typename T >
#define MAX_SIZE 5
//single node of type T in structure
class HashNode
{
friend class Structure< T >;
public:
//constructor
HashNode();
//destructor
~HashNode();
//num objects stored
int getnumobject();
// friend ostream &operator<<( ostream &, T* &);
private:
//array of keys
int keys[MAX_SIZE];
//array of pointers to values
T *values[MAX_SIZE];
//array of children
HashNode< T > *next[MAX_SIZE];
//parent pointer
HashNode< T > *parent;
//numobject
int numobject;
//in which level is the node
int level;
};
template< typename T >
HashNode< T >::HashNode()
{
//basic construction
parent = NULL;
numobject = 0;
level = 0;
for (int i=0; i<MAX_SIZE; i++)
{
next[i] = NULL;
keys[i] = 0;
values[i] = NULL;
}
}
template< typename T >
HashNode< T >::~HashNode()
{
//destructor deleting dynamic memory
for (int i=0; i<MAX_SIZE; i++)
{
if ( values[i] != NULL)
{
values[i] = NULL;
}
if ( next[i] != NULL)
{
delete next[i];
}
}
}
template< typename T >
int HashNode< T >::getnumobject()
{
//returns int total number of objects stored beneath
return numobject;
}
#endif