qse/ase/stx/misc.c

39 lines
646 B
C
Raw Normal View History

2005-05-15 18:37:00 +00:00
/*
2005-06-08 16:14:52 +00:00
* $Id: misc.c,v 1.4 2005-06-08 16:11:18 bacon Exp $
2005-05-15 18:37:00 +00:00
*/
#include <xp/stx/misc.h>
2005-06-08 16:00:51 +00:00
xp_word_t xp_stx_strhash (const xp_char_t* str)
2005-05-15 18:37:00 +00:00
{
2005-06-08 16:00:51 +00:00
xp_word_t h = 0;
xp_byte_t* bp, * be;
const xp_char_t* p = str;
2005-05-15 18:37:00 +00:00
2005-06-08 16:00:51 +00:00
while (*p != XP_CHAR('\0')) {
bp = (xp_byte_t*)p;
be = bp + xp_sizeof(xp_char_t);
2005-05-15 18:37:00 +00:00
while (bp < be) h = h * 31 + *bp++;
p++;
}
return h;
}
2005-06-08 16:00:51 +00:00
xp_word_t xp_stx_strxhash (const xp_char_t* str, xp_word_t len)
2005-05-15 18:37:00 +00:00
{
2005-06-08 16:00:51 +00:00
xp_word_t h = 0;
xp_byte_t* bp, * be;
const xp_char_t* p = str, * end = str + len;
2005-05-15 18:37:00 +00:00
while (p < end) {
2005-06-08 16:00:51 +00:00
bp = (xp_byte_t*)p;
be = bp + xp_sizeof(xp_char_t);
2005-05-15 18:37:00 +00:00
while (bp < be) h = h * 31 + *bp++;
p++;
}
return h;
}