-
Notifications
You must be signed in to change notification settings - Fork 0
/
Node.cpp
executable file
·94 lines (82 loc) · 1.6 KB
/
Node.cpp
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
/**********************************
* FILE NAME: Node.cpp
*
* DESCRIPTION: Node class definition
**********************************/
#include "Node.h"
/**
* constructor
*/
Node::Node() {}
/**
* constructor
*/
Node::Node(Address address) {
this->nodeAddress = address;
computeHashCode();
}
/**
* Destructor
*/
Node::~Node() {}
/**
* FUNCTION NAME: computeHashCode
*
* DESCRIPTION: This function computes the hash code of the node address
*/
void Node::computeHashCode() {
nodeHashCode = hashFunc(nodeAddress.addr)%RING_SIZE;
}
/**
* copy constructor
*/
Node::Node(const Node& another) {
this->nodeAddress = another.nodeAddress;
this->nodeHashCode = another.nodeHashCode;
}
/**
* Assignment operator overloading
*/
Node& Node::operator=(const Node& another) {
this->nodeAddress = another.nodeAddress;
this->nodeHashCode = another.nodeHashCode;
return *this;
}
/**
* operator overloading
*/
bool Node::operator < (const Node& another) const {
return this->nodeHashCode < another.nodeHashCode;
}
/**
* FUNCTION NAME: getHashCode
*
* DESCRIPTION: return hash code of the node
*/
size_t Node::getHashCode() {
return nodeHashCode;
}
/**
* FUNCTION NAME: getAddress
*
* DESCRIPTION: return the address of the node
*/
Address * Node::getAddress() {
return &nodeAddress;
}
/**
* FUNCTION NAME: setHashCode
*
* DESCRIPTION: set the hash code of the node
*/
void Node::setHashCode(size_t hashCode) {
this->nodeHashCode = hashCode;
}
/**
* FUNCTION NAME: setAddress
*
* DESCRIPTION: set the address of the node
*/
void Node::setAddress(Address address) {
this->nodeAddress = address;
}