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
48d9d48d
Commit
48d9d48d
authored
7 months ago
by
emsouza
Browse files
Options
Downloads
Patches
Plain Diff
[ADD] Restrição cabeça
parent
db121423
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
mydht
+0
-0
0 additions, 0 deletions
mydht
t2.c
+9
-9
9 additions, 9 deletions
t2.c
teste1.in
+1
-1
1 addition, 1 deletion
teste1.in
with
10 additions
and
10 deletions
mydht
+
0
−
0
View file @
48d9d48d
No preview for this file type
This diff is collapsed.
Click to expand it.
t2.c
+
9
−
9
View file @
48d9d48d
...
@@ -33,11 +33,11 @@ void redistribute_keys(Node *dht, Node* new_node) {
...
@@ -33,11 +33,11 @@ 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
;
...
@@ -174,14 +174,14 @@ Node* remove_node(Node* head, int id) {
...
@@ -174,14 +174,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
)
{
...
@@ -229,7 +229,7 @@ void print_finger_table_completa(Node* head, int timestamp) {
...
@@ -229,7 +229,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
,
int
max_id
)
{
Node
**
lookup
(
Node
*
head
,
int
timestamp
,
int
node_id
,
int
key
,
int
*
num_nodes
,
int
max_id
)
{
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
;
...
@@ -310,7 +310,7 @@ void insert_key(Node* head, int node_id, int key) {
...
@@ -310,7 +310,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
+
1
−
1
View file @
48d9d48d
...
@@ -13,4 +13,4 @@
...
@@ -13,4 +13,4 @@
13 E 52 -
13 E 52 -
14 E 42 -
14 E 42 -
15 P 1 -
15 P 1 -
16 L 28 58
16 L 28 18
\ No newline at end of file
\ 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