YACASL2
hash.c
Go to the documentation of this file.
1 #include "hash.h"
2 
3 unsigned hash(int keyc, HKEY *keyv[], int tabsize)
4 {
5  unsigned hashval = 0;
6  enum {
7  HASHNUM = 31
8  };
9 
10  for(int i = 0; i < keyc; i++) {
11  switch(keyv[i]->type) {
12  case CHARS:
13  for(int j = 0; keyv[i]->val.s[j]; j++) {
14  hashval = keyv[i]->val.s[j] + HASHNUM * hashval;
15  }
16  break;
17  case INT:
18  hashval = keyv[i]->val.i + HASHNUM * hashval;
19  break;
20  default:
21  break;
22  }
23  }
24  return (hashval % tabsize);
25 }
unsigned hash(int keyc, HKEY *keyv[], int tabsize)
ハッシュ値を取得する
Definition: hash.c:3
@ CHARS
Definition: hash.h:8
@ INT
Definition: hash.h:9
ハッシュ共用体のデータ型
Definition: hash.h:15
char * s
Definition: hash.h:18
int i
Definition: hash.h:19
union HKEY::@3 val