mlookup.table = nodes;
mlookup.size = size;
mlookup.threshold=size*loadfactor;
- mlookup.mask = (size << 1) -1;
+ mlookup.mask = size -1;
mlookup.numelements = 0; // Initial number of elements in the hash
mlookup.loadfactor = loadfactor;
int i;
mhashResize(newsize);
}
- unsigned int keyindex=(key&mlookup.mask)>>1;
- volatile unsigned int * lockptr=&mlookup.larray[keyindex&LOCKAMASK].lock;
+ unsigned int keyindex=key>>1;
+ volatile unsigned int * lockptr=&mlookup.larray[keyindex&LOCKMASK].lock;
while(!write_trylock(lockptr)) {
sched_yield();
}
- mhashlistnode_t * ptr = &mlookup.table[keyindex];
+ mhashlistnode_t * ptr = &mlookup.table[keyindex&mlookup.mask];
atomic_inc(&mlookup.numelements);
if(ptr->key ==0) {
void *mhashSearch(unsigned int key) {
int index;
- unsigned int keyindex=(key&mlookup.mask)>>1;
+ unsigned int keyindex=key>>1;
volatile unsigned int * lockptr=&mlookup.larray[keyindex&LOCKMASK].lock;
while(!read_trylock(lockptr)) {
sched_yield();
}
- mhashlistnode_t *node = &mlookup.table[keyindex];
+ mhashlistnode_t *node = &mlookup.table[keyindex&mlookup.mask];
do {
if(node->key == key) {
mhashlistnode_t *prev;
mhashlistnode_t *ptr, *node;
- unsigned int keyindex=(key&mlookup.mask)>>1;
+ unsigned int keyindex=key>>1;
volatile unsigned int * lockptr=&mlookup.larray[keyindex&LOCKMASK].lock;
while(!write_trylock(lockptr)) {
sched_yield();
}
- mhashlistnode_t *curr = &mlookup.table[keyindex];
+ mhashlistnode_t *curr = &mlookup.table[keyindex&mlookup.mask];
for (; curr != NULL; curr = curr->next) {
if (curr->key == key) {
mlookup.table = node;
mlookup.size = newsize;
mlookup.threshold=newsize*mlookup.loadfactor;
- mask=mlookup.mask = (newsize << 1)-1;
+ mask=mlookup.mask = newsize -1;
for(i = 0; i < oldsize; i++) {
curr = &ptr[i];
break;
}
next = curr->next;
- index = (key & mask) >>1;
+ index = (key >> 1) & mask;
tmp=&mlookup.table[index];
if(tmp->key ==0) {