*optimized linear lookup.
This commit is contained in:
parent
5ab34b5088
commit
029ba170cd
@ -2587,7 +2587,10 @@ static unsigned _ht_hash_object(void* ht, void* d) {
|
|||||||
switch(o->type) {
|
switch(o->type) {
|
||||||
case _DT_STRING:
|
case _DT_STRING:
|
||||||
h = 5 * h + _ht_hash_string(ht, o->data.string);
|
h = 5 * h + _ht_hash_string(ht, o->data.string);
|
||||||
result = h % self->array_size;
|
if(self->array_size == 1)
|
||||||
|
result = 0;
|
||||||
|
else
|
||||||
|
result = h % self->array_size;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
#ifdef MB_ENABLE_CLASS
|
#ifdef MB_ENABLE_CLASS
|
||||||
@ -2616,8 +2619,12 @@ static unsigned _ht_hash_object(void* ht, void* d) {
|
|||||||
#ifdef MB_ENABLE_USERTYPE_REF
|
#ifdef MB_ENABLE_USERTYPE_REF
|
||||||
case _DT_USERTYPE_REF:
|
case _DT_USERTYPE_REF:
|
||||||
if(o->data.usertype_ref->hash) {
|
if(o->data.usertype_ref->hash) {
|
||||||
h = 5 * h + o->data.usertype_ref->hash(o->data.usertype_ref->ref.s, o->data.usertype_ref->usertype);
|
if(self->array_size == 1) {
|
||||||
result = h % self->array_size;
|
result = 0;
|
||||||
|
} else {
|
||||||
|
h = 5 * h + o->data.usertype_ref->hash(o->data.usertype_ref->ref.s, o->data.usertype_ref->usertype);
|
||||||
|
result = h % self->array_size;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -2628,9 +2635,13 @@ static unsigned _ht_hash_object(void* ht, void* d) {
|
|||||||
#if defined MB_ENABLE_CLASS || defined MB_ENABLE_USERTYPE_REF
|
#if defined MB_ENABLE_CLASS || defined MB_ENABLE_USERTYPE_REF
|
||||||
_default:
|
_default:
|
||||||
#endif /* MB_ENABLE_CLASS || MB_ENABLE_USERTYPE_REF */
|
#endif /* MB_ENABLE_CLASS || MB_ENABLE_USERTYPE_REF */
|
||||||
for(i = 0; i < sizeof(_raw_t); ++i)
|
if(self->array_size == 1) {
|
||||||
h = 5 * h + o->data.raw[i];
|
result = 0;
|
||||||
result = h % self->array_size;
|
} else {
|
||||||
|
for(i = 0; i < sizeof(_raw_t); ++i)
|
||||||
|
h = 5 * h + o->data.raw[i];
|
||||||
|
result = h % self->array_size;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -2649,9 +2660,13 @@ static unsigned _ht_hash_string(void* ht, void* d) {
|
|||||||
|
|
||||||
mb_assert(ht);
|
mb_assert(ht);
|
||||||
|
|
||||||
for( ; *s; ++s)
|
if(self->array_size == 1) {
|
||||||
h = 5 * h + *s;
|
result = 0;
|
||||||
result = h % self->array_size;
|
} else {
|
||||||
|
for( ; *s; ++s)
|
||||||
|
h = 5 * h + *s;
|
||||||
|
result = h % self->array_size;
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -2663,7 +2678,10 @@ static unsigned _ht_hash_intptr(void* ht, void* d) {
|
|||||||
|
|
||||||
mb_assert(ht);
|
mb_assert(ht);
|
||||||
|
|
||||||
result = (unsigned)(i % self->array_size);
|
if(self->array_size == 1)
|
||||||
|
result = 0;
|
||||||
|
else
|
||||||
|
result = (unsigned)(i % self->array_size);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -2675,8 +2693,12 @@ static unsigned _ht_hash_ref(void* ht, void* d) {
|
|||||||
|
|
||||||
mb_assert(ht);
|
mb_assert(ht);
|
||||||
|
|
||||||
result = (unsigned)(intptr_t)ref;
|
if(self->array_size == 1) {
|
||||||
result %= self->array_size;
|
result = 0;
|
||||||
|
} else {
|
||||||
|
result = (unsigned)(intptr_t)ref;
|
||||||
|
result %= self->array_size;
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user