/*************************************************************************************************************************************/
/* */
/* T E S T D ' U N E M E T H O D E D E " H A S H - C O D I N G " : */
/* */
/* */
/* Author of '$xtc/HashCode.01$c' : */
/* */
/* Jean-Francois COLONNA (LACTAMME, 20120309135818). */
/* */
/*************************************************************************************************************************************/
#include <stdio.h>
#include "INCLUDES.01.I"
#define ITER 10000
#define PONDER 7
#define MODULO 23
#define INTE(x) \
((int)(x))
#define HASH(x,y,z) \
REST(INTE(MUL2(MODULO,ABSO((((x)*PONDER+(y))*PONDER+(z))))),MODULO)
extern double drand48();
main()
{
int n;
double Xf,Yf,Zf;
int tableau[MODULO];
for (n=0 ; n<MODULO ; n++)
{
tableau[n]=0;
}
for (n=1 ; n<=ITER ; n++)
{
int code;
Xf = drand48();
Yf = drand48();
Zf = drand48();
/* Creation d'un triplet {Xf,Yf,Zf} aleatoire... */
code=HASH(Xf,Yf,Zf);
tableau[code]++;
/* Codage et comptage des collisions... */
if (0)
{
printf("(%f,%f,%f)=%d\n",Xf,Yf,Zf,code);
}
else
{
}
}
for (n=0 ; n<MODULO ; n++)
{
printf("collision[%d]=%d\n",n,tableau[n]);
}
}