summaryrefslogtreecommitdiff
path: root/mysys/lf_hash.c
diff options
context:
space:
mode:
authorunknown <serg@janus.mylan>2006-11-16 15:40:08 +0100
committerunknown <serg@janus.mylan>2006-11-16 15:40:08 +0100
commit915cebdd53fe5071dc9443a236a798764f504c22 (patch)
tree4caaa7043f4421f3b849b7ad0452294ac15eff86 /mysys/lf_hash.c
parent966e4b4425e66bf57683a764d1d21a5d99ac2138 (diff)
downloadmariadb-git-915cebdd53fe5071dc9443a236a798764f504c22.tar.gz
post-review fixes.
tablockman: fixed a bug in finding a blocker lock mysys/my_getsystime.c: this is no longer true storage/maria/lockman.h: post-review fixes storage/maria/tablockman.h: post-review fixes storage/maria/unittest/lockman-t.c: post-review fixes storage/maria/unittest/lockman1-t.c: post-review fixes storage/maria/unittest/lockman2-t.c: post-review fixes include/my_atomic.h: moved intptr definition to my_global.h storage/maria/tablockman.c: post-review fixes BUILD/SETUP.sh: add -DMY_LF_EXTRA_DEBUG to debug builds include/atomic/nolock.h: suppress warning include/my_global.h: suppress warning mysys/lf_alloc-pin.c: post-review fixes mysys/lf_dynarray.c: post-review fixes mysys/lf_hash.c: post-review fixes storage/maria/trnman.c: suppress warning include/lf.h: post-review fix
Diffstat (limited to 'mysys/lf_hash.c')
-rw-r--r--mysys/lf_hash.c119
1 files changed, 60 insertions, 59 deletions
diff --git a/mysys/lf_hash.c b/mysys/lf_hash.c
index 66ad672f345..ff0eb8326d5 100644
--- a/mysys/lf_hash.c
+++ b/mysys/lf_hash.c
@@ -23,6 +23,7 @@
(but how to do it in lf_hash_delete ?)
*/
#include <my_global.h>
+#include <m_string.h>
#include <my_sys.h>
#include <my_bit.h>
#include <lf.h>
@@ -33,7 +34,7 @@ LF_REQUIRE_PINS(3);
typedef struct {
intptr volatile link; /* a pointer to the next element in a listand a flag */
uint32 hashnr; /* reversed hash number, for sorting */
- const uchar *key;
+ const byte *key;
uint keylen;
} LF_SLIST;
@@ -67,31 +68,31 @@ typedef struct {
pins[0..2] are used, they are NOT removed on return
*/
static int lfind(LF_SLIST * volatile *head, CHARSET_INFO *cs, uint32 hashnr,
- const uchar *key, uint keylen, CURSOR *cursor, LF_PINS *pins)
+ const byte *key, uint keylen, CURSOR *cursor, LF_PINS *pins)
{
uint32 cur_hashnr;
- const uchar *cur_key;
+ const byte *cur_key;
uint cur_keylen;
intptr link;
retry:
- cursor->prev=(intptr *)head;
+ cursor->prev= (intptr *)head;
do {
- cursor->curr=PTR(*cursor->prev);
- _lf_pin(pins,1,cursor->curr);
+ cursor->curr= PTR(*cursor->prev);
+ _lf_pin(pins, 1, cursor->curr);
} while(*cursor->prev != (intptr)cursor->curr && LF_BACKOFF);
for (;;)
{
if (!cursor->curr)
return 0;
do { // XXX or goto retry ?
- link=cursor->curr->link;
- cursor->next=PTR(link);
+ link= cursor->curr->link;
+ cursor->next= PTR(link);
_lf_pin(pins, 0, cursor->next);
} while(link != cursor->curr->link && LF_BACKOFF);
- cur_hashnr=cursor->curr->hashnr;
- cur_key=cursor->curr->key;
- cur_keylen=cursor->curr->keylen;
+ cur_hashnr= cursor->curr->hashnr;
+ cur_key= cursor->curr->key;
+ cur_keylen= cursor->curr->keylen;
if (*cursor->prev != (intptr)cursor->curr)
{
LF_BACKOFF;
@@ -101,12 +102,12 @@ retry:
{
if (cur_hashnr >= hashnr)
{
- int r=1;
+ int r= 1;
if (cur_hashnr > hashnr ||
- (r=my_strnncoll(cs, cur_key, cur_keylen, key, keylen)) >= 0)
+ (r= my_strnncoll(cs, cur_key, cur_keylen, key, keylen)) >= 0)
return !r;
}
- cursor->prev=&(cursor->curr->link);
+ cursor->prev= &(cursor->curr->link);
_lf_pin(pins, 2, cursor->curr);
}
else
@@ -120,7 +121,7 @@ retry:
goto retry;
}
}
- cursor->curr=cursor->next;
+ cursor->curr= cursor->next;
_lf_pin(pins, 1, cursor->curr);
}
}
@@ -141,21 +142,21 @@ static LF_SLIST *linsert(LF_SLIST * volatile *head, CHARSET_INFO *cs,
LF_SLIST *node, LF_PINS *pins, uint flags)
{
CURSOR cursor;
- int res=-1;
+ int res= -1;
do
{
if (lfind(head, cs, node->hashnr, node->key, node->keylen,
&cursor, pins) &&
(flags & LF_HASH_UNIQUE))
- res=0; /* duplicate found */
+ res= 0; /* duplicate found */
else
{
- node->link=(intptr)cursor.curr;
+ node->link= (intptr)cursor.curr;
assert(node->link != (intptr)node);
assert(cursor.prev != &node->link);
if (my_atomic_casptr((void **)cursor.prev, (void **)&cursor.curr, node))
- res=1; /* inserted ok */
+ res= 1; /* inserted ok */
}
} while (res == -1);
_lf_unpin(pins, 0);
@@ -177,10 +178,10 @@ static LF_SLIST *linsert(LF_SLIST * volatile *head, CHARSET_INFO *cs,
it uses pins[0..2], on return all pins are removed.
*/
static int ldelete(LF_SLIST * volatile *head, CHARSET_INFO *cs, uint32 hashnr,
- const uchar *key, uint keylen, LF_PINS *pins)
+ const byte *key, uint keylen, LF_PINS *pins)
{
CURSOR cursor;
- int res=-1;
+ int res= -1;
do
{
@@ -218,30 +219,30 @@ static int ldelete(LF_SLIST * volatile *head, CHARSET_INFO *cs, uint32 hashnr,
all other pins are removed.
*/
static LF_SLIST *lsearch(LF_SLIST * volatile *head, CHARSET_INFO *cs,
- uint32 hashnr, const uchar *key, uint keylen,
+ uint32 hashnr, const byte *key, uint keylen,
LF_PINS *pins)
{
CURSOR cursor;
- int res=lfind(head, cs, hashnr, key, keylen, &cursor, pins);
+ int res= lfind(head, cs, hashnr, key, keylen, &cursor, pins);
if (res) _lf_pin(pins, 2, cursor.curr);
_lf_unpin(pins, 0);
_lf_unpin(pins, 1);
return res ? cursor.curr : 0;
}
-static inline const uchar* hash_key(const LF_HASH *hash,
- const uchar *record, uint *length)
+static inline const byte* hash_key(const LF_HASH *hash,
+ const byte *record, uint *length)
{
if (hash->get_key)
- return (*hash->get_key)(record,length,0);
- *length=hash->key_length;
+ return (*hash->get_key)(record, length, 0);
+ *length= hash->key_length;
return record + hash->key_offset;
}
-static inline uint calc_hash(LF_HASH *hash, const uchar *key, uint keylen)
+static inline uint calc_hash(LF_HASH *hash, const byte *key, uint keylen)
{
- ulong nr1=1, nr2=4;
- hash->charset->coll->hash_sort(hash->charset,key,keylen,&nr1,&nr2);
+ ulong nr1= 1, nr2= 4;
+ hash->charset->coll->hash_sort(hash->charset, key, keylen, &nr1, &nr2);
return nr1 & INT_MAX32;
}
@@ -258,28 +259,28 @@ void lf_hash_init(LF_HASH *hash, uint element_size, uint flags,
lf_alloc_init(&hash->alloc, sizeof(LF_SLIST)+element_size,
offsetof(LF_SLIST, key));
lf_dynarray_init(&hash->array, sizeof(LF_SLIST **));
- hash->size=1;
- hash->count=0;
- hash->element_size=element_size;
- hash->flags=flags;
- hash->charset=charset ? charset : &my_charset_bin;
- hash->key_offset=key_offset;
- hash->key_length=key_length;
- hash->get_key=get_key;
+ hash->size= 1;
+ hash->count= 0;
+ hash->element_size= element_size;
+ hash->flags= flags;
+ hash->charset= charset ? charset : &my_charset_bin;
+ hash->key_offset= key_offset;
+ hash->key_length= key_length;
+ hash->get_key= get_key;
DBUG_ASSERT(get_key ? !key_offset && !key_length : key_length);
}
void lf_hash_destroy(LF_HASH *hash)
{
- LF_SLIST *el=*(LF_SLIST **)_lf_dynarray_lvalue(&hash->array, 0);
+ LF_SLIST *el= *(LF_SLIST **)_lf_dynarray_lvalue(&hash->array, 0);
while (el)
{
- intptr next=el->link;
+ intptr next= el->link;
if (el->hashnr & 1)
lf_alloc_real_free(&hash->alloc, el);
else
my_free((void *)el, MYF(0));
- el=(LF_SLIST *)next;
+ el= (LF_SLIST *)next;
}
lf_alloc_destroy(&hash->alloc);
lf_dynarray_destroy(&hash->array);
@@ -299,19 +300,19 @@ void lf_hash_destroy(LF_HASH *hash)
*/
int lf_hash_insert(LF_HASH *hash, LF_PINS *pins, const void *data)
{
- uint csize, bucket, hashnr;
+ int csize, bucket, hashnr;
LF_SLIST *node, * volatile *el;
lf_rwlock_by_pins(pins);
- node=(LF_SLIST *)_lf_alloc_new(pins);
+ node= (LF_SLIST *)_lf_alloc_new(pins);
memcpy(node+1, data, hash->element_size);
- node->key= hash_key(hash, (uchar *)(node+1), &node->keylen);
+ node->key= hash_key(hash, (byte *)(node+1), &node->keylen);
hashnr= calc_hash(hash, node->key, node->keylen);
bucket= hashnr % hash->size;
- el=_lf_dynarray_lvalue(&hash->array, bucket);
+ el= _lf_dynarray_lvalue(&hash->array, bucket);
if (*el == NULL)
initialize_bucket(hash, el, bucket, pins);
- node->hashnr=my_reverse_bits(hashnr) | 1;
+ node->hashnr= my_reverse_bits(hashnr) | 1;
if (linsert(el, hash->charset, node, pins, hash->flags))
{
_lf_alloc_free(pins, node);
@@ -335,15 +336,15 @@ int lf_hash_insert(LF_HASH *hash, LF_PINS *pins, const void *data)
int lf_hash_delete(LF_HASH *hash, LF_PINS *pins, const void *key, uint keylen)
{
LF_SLIST * volatile *el;
- uint bucket, hashnr=calc_hash(hash, (uchar *)key, keylen);
+ uint bucket, hashnr= calc_hash(hash, (byte *)key, keylen);
bucket= hashnr % hash->size;
lf_rwlock_by_pins(pins);
- el=_lf_dynarray_lvalue(&hash->array, bucket);
+ el= _lf_dynarray_lvalue(&hash->array, bucket);
if (*el == NULL)
initialize_bucket(hash, el, bucket, pins);
if (ldelete(el, hash->charset, my_reverse_bits(hashnr) | 1,
- (uchar *)key, keylen, pins))
+ (byte *)key, keylen, pins))
{
lf_rwunlock_by_pins(pins);
return 1;
@@ -360,33 +361,33 @@ int lf_hash_delete(LF_HASH *hash, LF_PINS *pins, const void *key, uint keylen)
void *lf_hash_search(LF_HASH *hash, LF_PINS *pins, const void *key, uint keylen)
{
LF_SLIST * volatile *el, *found;
- uint bucket, hashnr=calc_hash(hash, (uchar *)key, keylen);
+ uint bucket, hashnr= calc_hash(hash, (byte *)key, keylen);
bucket= hashnr % hash->size;
lf_rwlock_by_pins(pins);
- el=_lf_dynarray_lvalue(&hash->array, bucket);
+ el= _lf_dynarray_lvalue(&hash->array, bucket);
if (*el == NULL)
initialize_bucket(hash, el, bucket, pins);
found= lsearch(el, hash->charset, my_reverse_bits(hashnr) | 1,
- (uchar *)key, keylen, pins);
+ (byte *)key, keylen, pins);
lf_rwunlock_by_pins(pins);
return found ? found+1 : 0;
}
-static char *dummy_key="";
+static char *dummy_key= "";
static void initialize_bucket(LF_HASH *hash, LF_SLIST * volatile *node,
uint bucket, LF_PINS *pins)
{
uint parent= my_clear_highest_bit(bucket);
- LF_SLIST *dummy=(LF_SLIST *)my_malloc(sizeof(LF_SLIST), MYF(MY_WME));
- LF_SLIST **tmp=0, *cur;
- LF_SLIST * volatile *el=_lf_dynarray_lvalue(&hash->array, parent);
+ LF_SLIST *dummy= (LF_SLIST *)my_malloc(sizeof(LF_SLIST), MYF(MY_WME));
+ LF_SLIST **tmp= 0, *cur;
+ LF_SLIST * volatile *el= _lf_dynarray_lvalue(&hash->array, parent);
if (*el == NULL && bucket)
initialize_bucket(hash, el, parent, pins);
- dummy->hashnr=my_reverse_bits(bucket);
- dummy->key=dummy_key;
- dummy->keylen=0;
+ dummy->hashnr= my_reverse_bits(bucket);
+ dummy->key= dummy_key;
+ dummy->keylen= 0;
if ((cur= linsert(el, hash->charset, dummy, pins, 0)))
{
my_free((void *)dummy, MYF(0));