# C 코드 조각. hash_string

#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>

/*
 * hashtable 구현을 위한 hash function
 */
size_t hash_string (char *str, int hash_size){
    int32_t hash = 2829;
    int32_t c;
    size_t res;
    while((c = *str++)){
        hash = (hash * 615) + c;
    }
    res = (size_t)hash % hash_size;
    return res;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19