-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFingerTable.h
83 lines (75 loc) · 1.64 KB
/
FingerTable.h
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
#pragma once
#ifndef FINGERTABLE_H_
#define FINGERTABLE_H_
#include<iostream>
#include<string>
#include"FunctionUtil.h"
using namespace std;
// Prototype for the Dht class to use it pointer in Finger Table Single list Class
template <typename T>
struct dhtNode;
// This is Class Implemented for the Routing Table
template<typename T>
struct SinglyListNode
{
dhtNode<T>* Pointer;
SinglyListNode* next;
SinglyListNode()
{
Pointer = NULL;
next = NULL;
}
SinglyListNode(dhtNode<T>* n)
{
Pointer = n;
next = NULL;
}
};
// This class contain a refrence of next machine in the DDH
template<typename T>
struct RoutingTable
{
SinglyListNode<T>* head, * tail;
RoutingTable()
{
head = tail = NULL;
}
void insert(dhtNode<T>* ptr)
{
SinglyListNode<T>* new_node = new SinglyListNode<T>(ptr);
if (head == NULL)
head = tail = new_node;
else
{
tail->next = new_node;
tail = new_node;
}
}
void clear() {
SinglyListNode<T>* temp = head;
SinglyListNode<T>* current;
while (temp != NULL) {
current = temp;
temp = temp->next;
delete current;
}
head = NULL;
}
void display()
{
SinglyListNode<T>* temp = head;
if (head == NULL)
{
cout << "List is Empty..." << endl;
return;
}
while (temp != NULL)
{
cout << To_Integer(temp->Pointer->id) << " ";
temp = temp->next;
}
cout << endl;
return;
}
};
#endif