Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DHT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
emsouza
DHT
Commits
7bcd4731
Commit
7bcd4731
authored
7 months ago
by
emsouza
Browse files
Options
Downloads
Patches
Plain Diff
[ADD
] MAKEFILE
parent
f6098b5c
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
Makefile
+4
-0
4 additions, 0 deletions
Makefile
a.out
+0
-0
0 additions, 0 deletions
a.out
t2.c
+10
-15
10 additions, 15 deletions
t2.c
teste1.in
+15
-0
15 additions, 0 deletions
teste1.in
with
29 additions
and
15 deletions
Makefile
0 → 100644
+
4
−
0
View file @
7bcd4731
all
:
t2.c
gcc t2.c
-o
mydht
-Wall
-lm
purge
:
rm
-f
mydht
This diff is collapsed.
Click to expand it.
a.out
deleted
100644 → 0
+
0
−
0
View file @
f6098b5c
File deleted
This diff is collapsed.
Click to expand it.
t2.c
+
10
−
15
View file @
7bcd4731
...
@@ -16,20 +16,15 @@ typedef struct Node {
...
@@ -16,20 +16,15 @@ typedef struct Node {
struct
Node
*
prev
;
struct
Node
*
prev
;
}
Node
;
}
Node
;
typedef
struct
DHT
{
Node
*
head
;
int
max_id
;
}
DHT
;
void
redistribute_keys
(
Node
*
dht
,
Node
*
new_node
)
{
void
redistribute_keys
(
Node
*
dht
,
Node
*
new_node
)
{
Node
*
start
=
dht
;
Node
*
start
=
dht
;
do
{
do
{
Node
*
current
=
new_node
;
Node
*
current
=
new_node
;
printf
(
"Start:%d Next:%d
\n
"
,
start
->
id
,
current
->
id
);
//
printf("Start:%d Next:%d\n", start->id, current->id);
printf
(
"Start->key_count:%d
\n
"
,
start
->
key_count
);
//
printf("Start->key_count:%d\n", start->key_count);
//O novo nodo deve ter as chaves EXISTENTES que são maiores que o antecessor e menores ou iguais a ele
//O novo nodo deve ter as chaves EXISTENTES que são maiores que o antecessor e menores ou iguais a ele
for
(
int
i
=
0
;
i
<
start
->
key_count
;
i
++
)
{
for
(
int
i
=
0
;
i
<
start
->
key_count
;
i
++
)
{
printf
(
"Start->keys[%d]:%d
\n
"
,
i
,
start
->
keys
[
i
]);
//
printf("Start->keys[%d]:%d\n", i, start->keys[i]);
if
(
start
->
keys
[
i
]
>
start
->
id
&&
start
->
keys
[
i
]
<=
current
->
id
)
{
if
(
start
->
keys
[
i
]
>
start
->
id
&&
start
->
keys
[
i
]
<=
current
->
id
)
{
current
->
keys
[
current
->
key_count
++
]
=
start
->
keys
[
i
];
current
->
keys
[
current
->
key_count
++
]
=
start
->
keys
[
i
];
start
->
keys
[
i
]
=
0
;
start
->
keys
[
i
]
=
0
;
...
@@ -166,14 +161,14 @@ Node* remove_node(Node* head, int id) {
...
@@ -166,14 +161,14 @@ Node* remove_node(Node* head, int id) {
// Função para calcular a tabela finger
// Função para calcular a tabela finger
void
calculate_finger_table
(
Node
*
head
,
int
max_id
)
{
void
calculate_finger_table
(
Node
*
head
,
int
max_id
)
{
Node
*
current
=
head
;
Node
*
current
=
head
;
printf
(
"Max_id:%d
\n
"
,
max_id
);
//
printf("Max_id:%d\n", max_id);
int
log2_max_id
=
ceil
(
log2
(
max_id
));
int
log2_max_id
=
ceil
(
log2
(
max_id
));
printf
(
"Log2_max_id:%d
\n
"
,
log2_max_id
);
//
printf("Log2_max_id:%d\n", log2_max_id);
do
{
do
{
for
(
int
k
=
1
;
k
<=
log2_max_id
;
k
++
)
{
for
(
int
k
=
1
;
k
<=
log2_max_id
;
k
++
)
{
printf
(
"N:%d"
,
current
->
id
);
//
printf("N:%d", current->id);
int
finger_id
=
(
current
->
id
+
(
1
<<
k
-
1
))
%
(
1
<<
log2_max_id
);
int
finger_id
=
(
current
->
id
+
(
1
<<
(
k
-
1
))
)
%
(
1
<<
log2_max_id
);
printf
(
" Finger_id:%d
\n
"
,
finger_id
);
//
printf(" Finger_id:%d\n", finger_id);
Node
*
temp
=
head
;
Node
*
temp
=
head
;
//Inserir na tabela_finger o id do nó que é o menor id maior que o id do finger_id, ou seja, o id mais próximo do finger_id
//Inserir na tabela_finger o id do nó que é o menor id maior que o id do finger_id, ou seja, o id mais próximo do finger_id
while
(
temp
->
id
<
finger_id
&&
temp
->
next
!=
head
)
{
while
(
temp
->
id
<
finger_id
&&
temp
->
next
!=
head
)
{
...
@@ -221,7 +216,7 @@ void print_finger_table_completa(Node* head, int timestamp) {
...
@@ -221,7 +216,7 @@ void print_finger_table_completa(Node* head, int timestamp) {
// Função para realizar lookup de uma chave
// Função para realizar lookup de uma chave
Node
**
lookup
(
Node
*
head
,
int
timestamp
,
int
node_id
,
int
key
,
int
*
num_nodes
)
{
Node
**
lookup
(
Node
*
head
,
int
timestamp
,
int
node_id
,
int
key
,
int
*
num_nodes
)
{
printf
(
"Lookup
\n
"
);
//
printf("Lookup\n");
Node
*
current
=
head
;
Node
*
current
=
head
;
Node
**
nodes_involved
=
(
Node
**
)
malloc
(
TAM_MAX_FINGER
*
sizeof
(
Node
*
));
Node
**
nodes_involved
=
(
Node
**
)
malloc
(
TAM_MAX_FINGER
*
sizeof
(
Node
*
));
*
num_nodes
=
0
;
*
num_nodes
=
0
;
...
@@ -295,7 +290,7 @@ void insert_key(Node* head, int node_id, int key) {
...
@@ -295,7 +290,7 @@ void insert_key(Node* head, int node_id, int key) {
}
}
current
->
keys
[
current
->
key_count
++
]
=
key
;
current
->
keys
[
current
->
key_count
++
]
=
key
;
printf
(
"Chave %d inserida no nó %d
\n
"
,
key
,
current
->
id
);
//
printf("Chave %d inserida no nó %d\n", key, current->id);
}
}
void
imprime_chaves
(
Node
*
head
)
{
void
imprime_chaves
(
Node
*
head
)
{
...
...
This diff is collapsed.
Click to expand it.
teste1.in
0 → 100644
+
15
−
0
View file @
7bcd4731
1 E 4 -
2 E 10 -
3 I 10 18
4 E 20 -
5 E 14 -
6 S 4 -
7 E 28 -
8 L 10 18
9 E 1 -
10 E 56 -
11 I 1 50
12 S 56 -
13 E 52 -
14 E 42 -
15 L 10 50
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment