Skip to content
Snippets Groups Projects
Commit 48d9d48d authored by emsouza's avatar emsouza
Browse files

[ADD] Restrição cabeça

parent db121423
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -33,11 +33,11 @@ void redistribute_keys(Node *dht, Node* new_node) {
Node *start = dht;
do {
Node* current = new_node;
printf("Start:%d Next:%d\n", start->id, current->id);
printf("Start->key_count:%d\n", start->key_count);
// printf("Start:%d Next:%d\n", start->id, current->id);
// 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
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) {
current->keys[current->key_count++] = start->keys[i];
start->keys[i] = 0;
......@@ -174,14 +174,14 @@ Node* remove_node(Node* head, int id) {
// Função para calcular a tabela finger
void calculate_finger_table(Node* head, int max_id) {
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));
printf("Log2_max_id:%d\n", log2_max_id);
// printf("Log2_max_id:%d\n", log2_max_id);
do {
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);
printf(" Finger_id:%d\n", finger_id);
// printf(" Finger_id:%d\n", finger_id);
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
while(temp->id < finger_id && temp->next != head) {
......@@ -229,7 +229,7 @@ void print_finger_table_completa(Node* head, int timestamp) {
// 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) {
printf("Lookup\n");
// printf("Lookup\n");
Node* current = head;
Node** nodes_involved = (Node**)malloc(TAM_MAX_FINGER * sizeof(Node*));
*num_nodes = 0;
......@@ -310,7 +310,7 @@ void insert_key(Node* head, int node_id, int 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) {
......
......@@ -13,4 +13,4 @@
13 E 52 -
14 E 42 -
15 P 1 -
16 L 28 58
\ No newline at end of file
16 L 28 18
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment