Skip to content
Snippets Groups Projects
Commit 506acfb9 authored by Eduardo Souza's avatar Eduardo Souza
Browse files

Lookuptable feita a cuspe

parent 935a194f
Branches
No related tags found
No related merge requests found
No preview for this file type
......@@ -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 do 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) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment