/* Copyright (C) 1993 Stephen F. White */
/*
* This hashing function was ripped from Aho & Ullman, who ripped it
* from someone else.
*/
#include "config.h"
#include "cool.h"
#include "proto.h"
int
hash(const char *s)
{
const char *p;
unsigned h = 0, g;
for (p = s; *p; p++) {
h = (h << 4) + (*p);
g = h & 0xf0000000;
if (g) {
h = h ^ (g >> 24);
h = h ^ g;
}
}
return h;
}
HashT *
hash_new(int htsize)
{
HashT *new;
int i;
if (htsize == 0) {
htsize = 1;
}
new = cool_malloc(sizeof(HashT) + htsize * sizeof(void *));
new->size = htsize;
new->num = 0;
new->table = (void *) (new + 1);
for (i = 0; i < htsize; i++) {
new->table[i] = 0;
}
return new;
}