自分で考えたプログラムを載せておきます。
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#define B 10000
#define A 100
typedef struct _point{
int x;
int y;
}POINT;
typedef struct h_cell{
POINT data;
struct h_cell *next;
}CELL;
CELL H[B];
CELL *head[B];
CELL insert_cell_top(POINT p,int a){
CELL *new_cell;
new_cell=(CELL*)malloc(sizeof(CELL));
new_cell->data=p;
new_cell->next=head[a];
head[a]=new_cell;
return *new_cell;
}
int h(POINT p){
return (p.x)*(p.y)%B;
}
int insert_hash(POINT p){
CELL *a;
int b=h(p);
H[b]=*head[b];
a=&H[b];
while(a->next!=NULL){
if(a->data.x!=p.x && a->data.y!=p.y){
H[b]=insert_cell_top(p,b);
a=a->next;
return 1;
}
else return 0;
}
return 0;
}
int search_hash(POINT p){
int b=h(p);
CELL *a;
a=&H[b];
while(a->next!=NULL){
if(a->data.x==p.x && a->data.y==p.y){
return 1;
a=a->next;
}else return 0;
}
return 0;
}
void hash_status(){
int i,j=0;
int max,min;
CELL *a;
for(i=0;i<B;i++){
a=&H[i];
while(a->next!=NULL)
printf("Number of H[%d]'s data=%d\n",i,j);
printf("H[%d]'smax=%d,min=%d\n",i,max,min);
}
}
int main(void){
int i,j,X;
srand((unsigned)time(NULL));
POINT a[A];
for(j=0;j<A;j++){
a[j].x=0;
a[j].y=0;
}
for(i=0;i<A;i++){
a[i].x=rand()%9999;
a[i].y=rand()%9999;
insert_hash(a[i]);
}
return 0;
}