Last active
August 29, 2015 14:07
-
-
Save icarofreire/0198da67fecc3edbdc24 to your computer and use it in GitHub Desktop.
Técnica de tabela hash em C com inteiros de 32 bits.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ctype.h> | |
#include <math.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define max(a,b)((a<b)?(b):(a)) | |
#define min(a,b)((b<a)?(b):(a)) | |
#define dif(a,b)(max(a,b)-min(a,b)) | |
#define rep(i,b) for(i=0;i<b;i++) | |
#define repi(i,a,b) for(i=a;i<b;i++) | |
unsigned hashtab[(1<<24)]; | |
#define hash32(x) (((x)*2654435761) >> (32-24)) | |
#define hash(v,k) hashtab[hash32(k)]=v; | |
#define key(k) (hashtab[hash32(k)]) | |
int main(){ | |
int valor = 154; | |
int chave_qualquer = 56; | |
/* \/ Guarda o valor na tabela 'hashtab' atraves de um calculo com o valor da chave. */ | |
hash(valor,chave_qualquer); | |
printf("valor: %d\nchave: %d\n", valor, chave_qualquer ); | |
/* \/ Obtem o valor que foi guardado na tabela pela chave. */ | |
printf("valor obtido pela chave %d: %d\n", chave_qualquer, key(chave_qualquer) ); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment