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
506acfb9
Commit
506acfb9
authored
8 months ago
by
Eduardo Souza
Browse files
Options
Downloads
Patches
Plain Diff
Lookuptable feita a cuspe
parent
935a194f
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
+18
-12
18 additions, 12 deletions
t2.c
with
18 additions
and
12 deletions
a.out
+
0
−
0
View file @
506acfb9
No preview for this file type
This diff is collapsed.
Click to expand it.
t2.c
+
18
−
12
View file @
506acfb9
...
...
@@ -31,7 +31,6 @@ void redistribute_keys(Node *dht, Node* new_node) {
for
(
int
i
=
0
;
i
<
start
->
key_count
;
i
++
)
{
printf
(
"Start->keys[%d]:%d
\n
"
,
i
,
start
->
keys
[
i
]);
if
(
start
->
keys
[
i
]
>
start
->
id
&&
start
->
keys
[
i
]
<=
current
->
id
)
{
printf
(
"SAIA CHAVE SAIAAAA"
);
current
->
keys
[
current
->
key_count
++
]
=
start
->
keys
[
i
];
start
->
keys
[
i
]
=
0
;
start
->
key_count
--
;
...
...
@@ -204,7 +203,6 @@ void print_finger_table(Node* head, int timestamp) {
// Função para realizar lookup de uma chave
void
lookup
(
Node
*
head
,
int
timestamp
,
int
node_id
,
int
key
){
printf
(
"ENTREI
\n
"
);
Node
*
current
=
head
;
Node
*
nodes_involved
[
TAM_MAX_FINGER
];
int
nodes_count
=
0
;
...
...
@@ -220,23 +218,31 @@ void lookup(Node* head, int timestamp, int node_id, int key){
while
(
1
){
int
found
=
0
;
//Verificar se o nó atual já tem a chave
for
(
int
i
=
0
;
i
<
current
->
key_count
;
i
++
)
{
if
(
current
->
keys
[
i
]
==
key
)
{
printf
(
"%d}
\n
"
,
current
->
id
);
return
;
}
}
//Procura o maior nó conhecido pela finger_table que
precede
o valor da chave
//Procura o maior nó conhecido pela finger_table que
está acima d
o valor da chave
for
(
int
i
=
0
;
i
<
current
->
tam_finger
;
i
++
)
{
if
(
current
->
finger
[
i
]
<
key
&&
current
->
finger
[
i
]
>
id_aux
)
{
printf
(
"%d
,
"
,
current
->
finger
[
i
]);
if
(
current
->
finger
[
i
]
>
key
)
{
printf
(
"%d"
,
current
->
finger
[
i
]);
id_aux
=
current
->
finger
[
i
];
found
=
1
;
break
;
}
//Se não encontrar um nó na tabela finger que preceda o valor da chave, sai do loop
}
//Se não encontrar um nó na tabela finger que seja maior que o valor da chave, procura o maior valor que antecede ela
if
(
!
found
){
break
;
int
max
=
current
->
finger
[
0
];
for
(
int
i
=
1
;
i
<
current
->
tam_finger
;
i
++
)
{
if
(
current
->
finger
[
i
]
>
max
)
{
max
=
current
->
finger
[
i
];
}
}
}
// Mover para o nó com ID id_aux
...
...
@@ -248,17 +254,17 @@ void lookup(Node* head, int timestamp, int node_id, int key){
//Verificar se o nó atual já tem a chave
for
(
int
i
=
0
;
i
<
current
->
key_count
;
i
++
)
{
if
(
current
->
keys
[
i
]
==
key
)
{
printf
(
"
%d
}
\n
"
,
current
->
id
);
printf
(
"}
\n
"
);
return
;
}
}
//Se o nó atual não tiver a chave, continuar a busca
printf
(
","
);
start
=
current
;
}
printf
(
"
%d
}
\n
"
,
current
->
id
);
printf
(
"}
\n
"
);
nodes_involved
[
nodes_count
++
]
=
current
;
}
}
// Função para adicionar uma chave a um nó respeitando o limite de um nó guarda as chaves maiores que seu antecessor e menores e iguais a ele.
void
insert_key
(
Node
*
head
,
int
node_id
,
int
key
)
{
...
...
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