qse/ase/stx/misc.c

71 lines
1.2 KiB
C
Raw Normal View History

2005-05-15 18:37:00 +00:00
/*
2007-03-22 11:19:28 +00:00
* $Id: misc.c,v 1.8 2007-03-22 11:19:28 bacon Exp $
2005-05-15 18:37:00 +00:00
*/
2007-03-22 11:19:28 +00:00
#include <ase/stx/misc.h>
2005-05-15 18:37:00 +00:00
2007-03-22 11:19:28 +00:00
ase_word_t ase_stx_hash (const void* data, ase_word_t len)
2005-07-05 11:15:51 +00:00
{
2007-03-22 11:19:28 +00:00
ase_word_t h = 0;
ase_byte_t* bp, * be;
2005-07-05 11:15:51 +00:00
2007-03-22 11:19:28 +00:00
bp = (ase_byte_t*)data; be = bp + len;
2005-07-05 11:15:51 +00:00
while (bp < be) h = h * 31 + *bp++;
return h;
}
2007-03-22 11:19:28 +00:00
ase_word_t ase_stx_strhash (const ase_char_t* str)
2005-05-15 18:37:00 +00:00
{
2007-03-22 11:19:28 +00:00
ase_word_t h = 0;
ase_byte_t* bp, * be;
const ase_char_t* p = str;
2005-05-15 18:37:00 +00:00
2007-03-22 11:19:28 +00:00
while (*p != ASE_T('\0')) {
bp = (ase_byte_t*)p;
be = bp + ase_sizeof(ase_char_t);
2005-05-15 18:37:00 +00:00
while (bp < be) h = h * 31 + *bp++;
p++;
}
return h;
}
2007-03-22 11:19:28 +00:00
ase_word_t ase_stx_strxhash (const ase_char_t* str, ase_word_t len)
2005-05-15 18:37:00 +00:00
{
2007-03-22 11:19:28 +00:00
ase_word_t h = 0;
ase_byte_t* bp, * be;
const ase_char_t* p = str, * end = str + len;
2005-05-15 18:37:00 +00:00
while (p < end) {
2007-03-22 11:19:28 +00:00
bp = (ase_byte_t*)p;
be = bp + ase_sizeof(ase_char_t);
2005-05-15 18:37:00 +00:00
while (bp < be) h = h * 31 + *bp++;
p++;
}
return h;
}
2007-03-22 11:19:28 +00:00
ase_char_t* ase_stx_strword (
const ase_char_t* str, const ase_char_t* word, ase_word_t* word_index)
2005-06-30 12:07:02 +00:00
{
2007-03-22 11:19:28 +00:00
ase_char_t* p = (ase_char_t*)str;
ase_char_t* tok;
ase_size_t len;
ase_word_t index = 0;
2005-06-30 12:07:02 +00:00
2007-03-22 11:19:28 +00:00
while (p != ASE_NULL) {
p = ase_strtok (p, ASE_T(""), &tok, &len);
if (ase_strxcmp (tok, len, word) == 0) {
2005-06-30 12:07:02 +00:00
*word_index = index;
return tok;
}
index++;
}
2005-06-30 15:11:00 +00:00
*word_index = index;
2007-03-22 11:19:28 +00:00
return ASE_NULL;
2005-06-30 12:07:02 +00:00
}