summaryrefslogtreecommitdiff
path: root/mysys/hash.c
diff options
context:
space:
mode:
authorunknown <bar@gw.udmsearch.izhnet.ru>2002-03-14 21:44:42 +0400
committerunknown <bar@gw.udmsearch.izhnet.ru>2002-03-14 21:44:42 +0400
commit8959b690fe796a44ddda440290b3fe9a9cf89ca5 (patch)
treed80812bbab290e762f4a058cded480022c09d0f3 /mysys/hash.c
parentee1ef8c58c9df9a62f7a0cc3dee6c2f705c8eb44 (diff)
downloadmariadb-git-8959b690fe796a44ddda440290b3fe9a9cf89ca5.tar.gz
Hash now supports several charsets
Diffstat (limited to 'mysys/hash.c')
-rw-r--r--mysys/hash.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/mysys/hash.c b/mysys/hash.c
index f1ce5052e4f..41ebe59c2de 100644
--- a/mysys/hash.c
+++ b/mysys/hash.c
@@ -31,12 +31,13 @@
static uint hash_mask(uint hashnr,uint buffmax,uint maxlength);
static void movelink(HASH_LINK *array,uint pos,uint next_link,uint newlink);
-static uint calc_hashnr(const byte *key,uint length);
-static uint calc_hashnr_caseup(const byte *key,uint length);
+static uint calc_hashnr(CHARSET_INFO *cs,const byte *key,uint length);
+static uint calc_hashnr_caseup(CHARSET_INFO *cs, const byte *key,uint length);
static int hashcmp(HASH *hash,HASH_LINK *pos,const byte *key,uint length);
-my_bool hash_init(HASH *hash,uint size,uint key_offset,uint key_length,
+my_bool hash_init(HASH *hash,CHARSET_INFO *charset,
+ uint size,uint key_offset,uint key_length,
hash_get_key get_key,
void (*free_element)(void*),uint flags)
{
@@ -56,6 +57,7 @@ my_bool hash_init(HASH *hash,uint size,uint key_offset,uint key_length,
hash->get_key=get_key;
hash->free=free_element;
hash->flags=flags;
+ hash->charset=charset;
if (flags & HASH_CASE_INSENSITIVE)
hash->calc_hashnr=calc_hashnr_caseup;
else
@@ -104,14 +106,15 @@ static uint hash_rec_mask(HASH *hash,HASH_LINK *pos,uint buffmax,
{
uint length;
byte *key=hash_key(hash,pos->data,&length,0);
- return hash_mask((*hash->calc_hashnr)(key,length),buffmax,maxlength);
+ return hash_mask((*hash->calc_hashnr)(hash->charset,key,length),
+ buffmax,maxlength);
}
#ifndef NEW_HASH_FUNCTION
/* Calc hashvalue for a key */
-static uint calc_hashnr(const byte *key,uint length)
+static uint calc_hashnr(CHARSET_INFO *cs, const byte *key,uint length)
{
register uint nr=1, nr2=4;
while (length--)
@@ -124,14 +127,13 @@ static uint calc_hashnr(const byte *key,uint length)
/* Calc hashvalue for a key, case indepenently */
-static uint calc_hashnr_caseup(const byte *key,uint length)
+static uint calc_hashnr_caseup(CHARSET_INFO *cs, const byte *key,uint length)
{
register uint nr=1, nr2=4;
while (length--)
{
- /* BAR TODO: remove default_charset_info */
nr^= (((nr & 63)+nr2)*
- ((uint) (uchar) my_toupper(default_charset_info, *key++)))+ (nr << 8);
+ ((uint) (uchar) my_toupper(cs, *key++)))+ (nr << 8);
nr2+=3;
}
return((uint) nr);
@@ -152,7 +154,7 @@ static uint calc_hashnr_caseup(const byte *key,uint length)
* This works well on both numbers and strings.
*/
-uint calc_hashnr(const byte *key, uint len)
+uint calc_hashnr(CHARSET_INFO *cs, const byte *key, uint len)
{
const byte *end=key+len;
uint hash;
@@ -164,14 +166,14 @@ uint calc_hashnr(const byte *key, uint len)
return (hash);
}
-uint calc_hashnr_caseup(const byte *key, uint len)
+uint calc_hashnr_caseup(CHARSET_INFO *cs, const byte *key, uint len)
{
const byte *end=key+len;
uint hash;
for (hash = 0; key < end; key++)
{
hash *= 16777619;
- hash ^= (uint) (uchar) toupper(*key);
+ hash ^= (uint) (uchar) my_toupper(cs,*key);
}
return (hash);
}
@@ -186,7 +188,7 @@ uint rec_hashnr(HASH *hash,const byte *record)
{
uint length;
byte *key=hash_key(hash,record,&length,0);
- return (*hash->calc_hashnr)(key,length);
+ return (*hash->calc_hashnr)(hash->charset,key,length);
}
@@ -202,7 +204,7 @@ gptr hash_search(HASH *hash,const byte *key,uint length)
flag=1;
if (hash->records)
{
- idx=hash_mask((*hash->calc_hashnr)(key,length ? length :
+ idx=hash_mask((*hash->calc_hashnr)(hash->charset,key,length ? length :
hash->key_length),
hash->blength,hash->records);
do
@@ -516,7 +518,7 @@ my_bool hash_update(HASH *hash,byte *record,byte *old_key,uint old_key_length)
/* Search after record with key */
- idx=hash_mask((*hash->calc_hashnr)(old_key,(old_key_length ?
+ idx=hash_mask((*hash->calc_hashnr)(hash->charset, old_key,(old_key_length ?
old_key_length :
hash->key_length)),
blength,records);