diff options
Diffstat (limited to 'mysys/hash.c')
-rw-r--r-- | mysys/hash.c | 49 |
1 files changed, 29 insertions, 20 deletions
diff --git a/mysys/hash.c b/mysys/hash.c index 602823e6d43..3afd31a079b 100644 --- a/mysys/hash.c +++ b/mysys/hash.c @@ -1,19 +1,18 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, +/* Copyright (C) 2000 MySQL AB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* The hash functions used for saveing keys */ /* One of key_length or key_length_offset must be given */ @@ -153,9 +152,7 @@ static uint calc_hashnr_caseup(const byte *key,uint length) * * The magic is in the interesting relationship between the special prime * 16777619 (2^24 + 403) and 2^32 and 2^8. - * - * This hash produces the fewest collisions of any function that we've seen so - * far, and works well on both numbers and strings. + * This works well on both numbers and strings. */ uint calc_hashnr(const byte *key, uint len) @@ -522,8 +519,8 @@ 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 ? - old_key_length : - hash->key_length)), + old_key_length : + hash->key_length)), blength,records); new_index=hash_mask(rec_hashnr(hash,record),blength,records); if (idx == new_index) @@ -583,6 +580,18 @@ byte *hash_element(HASH *hash,uint idx) } +/* + Replace old row with new row. This should only be used when key + isn't changed +*/ + +void hash_replace(HASH *hash, uint idx, byte *new_row) +{ + if (idx != NO_RECORD) /* Safety */ + dynamic_element(&hash->array,idx,HASH_LINK*)->data=new_row; +} + + #ifndef DBUG_OFF my_bool hash_check(HASH *hash) |