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
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
43ba100c
Commit
43ba100c
authored
8 months ago
by
Eduardo Souza
Browse files
Options
Downloads
Patches
Plain Diff
[FIX] Lookuptable não está tão mais feita a cuspe
parent
504657f6
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
a.out
+0
-0
0 additions, 0 deletions
a.out
t2.c
+16
-23
16 additions, 23 deletions
t2.c
with
16 additions
and
23 deletions
a.out
+
0
−
0
View file @
43ba100c
No preview for this file type
This diff is collapsed.
Click to expand it.
t2.c
+
16
−
23
View file @
43ba100c
...
@@ -189,7 +189,7 @@ void calculate_finger_table(Node* head, int max_id) {
...
@@ -189,7 +189,7 @@ void calculate_finger_table(Node* head, int max_id) {
//Função para imprimir todas as tabelas finger
//Função para imprimir todas as tabelas finger
void
print_finger_table
(
Node
**
nodes_involved
,
int
num_nodes
,
int
timestamp
)
{
void
print_finger_table
(
Node
**
nodes_involved
,
int
num_nodes
,
int
timestamp
)
{
for
(
int
i
=
0
;
i
<
=
num_nodes
;
i
++
)
{
for
(
int
i
=
0
;
i
<
num_nodes
;
i
++
)
{
printf
(
"%d T %d {"
,
timestamp
,
nodes_involved
[
i
]
->
id
);
printf
(
"%d T %d {"
,
timestamp
,
nodes_involved
[
i
]
->
id
);
for
(
int
j
=
0
;
j
<
nodes_involved
[
i
]
->
tam_finger
;
j
++
)
{
for
(
int
j
=
0
;
j
<
nodes_involved
[
i
]
->
tam_finger
;
j
++
)
{
printf
(
"%d"
,
nodes_involved
[
i
]
->
finger
[
j
]);
printf
(
"%d"
,
nodes_involved
[
i
]
->
finger
[
j
]);
...
@@ -216,6 +216,7 @@ void print_finger_table_completa(Node* head, int timestamp) {
...
@@ -216,6 +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
"
);
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
;
...
@@ -225,25 +226,23 @@ Node ** lookup(Node* head, int timestamp, int node_id, int key, int *num_nodes)
...
@@ -225,25 +226,23 @@ Node ** lookup(Node* head, int timestamp, int node_id, int key, int *num_nodes)
}
}
printf
(
"%d L %d {"
,
timestamp
,
key
);
printf
(
"%d L %d {"
,
timestamp
,
key
);
Node
*
start
=
current
;
//Meu nó partida
Node
*
start
=
current
;
int
id_aux
=
current
->
id
;
int
id_aux
=
current
->
id
;
nodes_involved
[(
*
num_nodes
)
++
]
=
current
;
nodes_involved
[(
*
num_nodes
)
++
]
=
current
;
printf
(
"%d,"
,
current
->
id
);
while
(
1
){
while
(
1
){
int
found
=
0
;
int
found
=
0
;
printf
(
"%d"
,
current
->
id
);
//Verificar se o nó atual já tem a chave
//Verificar se o nó atual já tem a chave
for
(
int
i
=
0
;
i
<
current
->
key_count
;
i
++
)
{
for
(
int
i
=
0
;
i
<
current
->
key_count
;
i
++
)
{
if
(
current
->
keys
[
i
]
==
key
)
{
if
(
current
->
keys
[
i
]
==
key
)
{
printf
(
"%d}
\n
"
,
current
->
id
);
printf
(
"}
\n
"
);
nodes_involved
[(
*
num_nodes
)
++
]
=
current
;
return
nodes_involved
;
return
nodes_involved
;
}
}
}
}
printf
(
","
);
//Procura o maior nó conhecido pela finger_table que está acima do valor da chave
//Procura o maior nó conhecido pela finger_table que está acima do valor da chave
for
(
int
i
=
0
;
i
<
current
->
tam_finger
;
i
++
)
{
for
(
int
i
=
0
;
i
<
current
->
tam_finger
;
i
++
)
{
if
(
current
->
finger
[
i
]
>
key
)
{
if
(
current
->
finger
[
i
]
>
key
)
{
printf
(
"%d"
,
current
->
finger
[
i
]);
id_aux
=
current
->
finger
[
i
];
id_aux
=
current
->
finger
[
i
];
found
=
1
;
found
=
1
;
break
;
break
;
...
@@ -258,28 +257,21 @@ Node ** lookup(Node* head, int timestamp, int node_id, int key, int *num_nodes)
...
@@ -258,28 +257,21 @@ Node ** lookup(Node* head, int timestamp, int node_id, int key, int *num_nodes)
max
=
current
->
finger
[
i
];
max
=
current
->
finger
[
i
];
}
}
}
}
id_aux
=
max
;
}
}
// Mover para o nó com ID id_aux
// Mover para o nó com ID id_aux
while
(
current
->
id
!=
id_aux
){
while
(
current
->
id
!=
id_aux
){
current
=
current
->
next
;
current
=
current
->
next
;
}
}
nodes_involved
[
*
num_nodes
++
]
=
current
;
//Adiciona o nó atual ao array de nós envolvidos
nodes_involved
[
(
*
num_nodes
)
++
]
=
current
;
//Adiciona o nó atual ao array de nós envolvidos
//Verificar se o nó atual já tem a chave
//Previne loops infinitos
for
(
int
i
=
0
;
i
<
current
->
key_count
;
i
++
)
{
if
(
current
->
id
==
start
->
id
){
if
(
current
->
keys
[
i
]
==
key
)
{
nodes_involved
[(
*
num_nodes
)
++
]
=
current
;
printf
(
"}
\n
"
);
printf
(
"}
\n
"
);
return
nodes_involved
;
nodes_involved
[(
*
num_nodes
)
++
]
=
current
;
}
break
;
}
}
//Se o nó atual não tiver a chave, continuar a busca
printf
(
","
);
start
=
current
;
}
}
printf
(
"}
\n
"
);
nodes_involved
[(
*
num_nodes
)
++
]
=
current
;
return
nodes_involved
;
return
nodes_involved
;
}
}
...
@@ -336,6 +328,7 @@ int main() {
...
@@ -336,6 +328,7 @@ int main() {
int
num_nodes
=
0
;
int
num_nodes
=
0
;
nodes_involved
=
lookup
(
dht
,
timestamp
,
id
,
key
,
&
num_nodes
);
nodes_involved
=
lookup
(
dht
,
timestamp
,
id
,
key
,
&
num_nodes
);
print_finger_table
(
nodes_involved
,
num_nodes
,
timestamp
);
print_finger_table
(
nodes_involved
,
num_nodes
,
timestamp
);
free
(
nodes_involved
);
}
else
if
(
op
==
'P'
){
}
else
if
(
op
==
'P'
){
imprime_chaves
(
dht
);
imprime_chaves
(
dht
);
print_finger_table_completa
(
dht
,
timestamp
);
print_finger_table_completa
(
dht
,
timestamp
);
...
...
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