541 if (empty == lastpos) /* last key at wrong pos or no next link */
542 goto exit;
543
544 /* Move the last key (lastpos) */
545 lastpos_hashnr=rec_hashnr(hash,lastpos->data);//重新计算最后一个位置的hash值
546 /* pos is where lastpos should be */
547 pos= data + my_hash_mask(lastpos_hashnr, hash->blength, hash->records);//计算掩码//如果空闲位是最后以为掩码的位置,case2
548 if (pos == empty) /* Move to empty position. */
549 {
550 empty[0]=lastpos[0];
551 goto exit;
552 }
553 pos_hashnr=rec_hashnr(hash,pos->data);
554 /* pos3 is where the pos should be */ //计算pos位的hash掩码
555 pos3= data + my_hash_mask(pos_hashnr, hash->blength, hash->records);
556 if (pos != pos3)//如果pos位的元素掩码不等于pos,case3
557 { /* pos is on wrong posit */
558 empty[0]=pos[0]; /* Save it here */
559 pos[0]=lastpos[0]; /* This should be here */
560 movelink(data,(uint) (pos-data),(uint) (pos3-data),empty_index);
561 goto exit;
562 }//计算数组最后一位的掩码(records等于减一之前的值),case4
563 pos2= my_hash_mask(lastpos_hashnr, blength, hash->records + 1);
564 if (pos2 == my_hash_mask(pos_hashnr, blength, hash->records + 1))
565 { /* Identical key-positions */
566 if (pos2 != hash->records)//进入case4-1
567 {
568 empty[0]=lastpos[0];
569 movelink(data,(uint) (lastpos-data),(uint) (pos-data),empty_index);
570 goto exit;
571 }
572 idx= (uint) (pos-data); /* Link pos->next after lastpos */
573 }
//case4-2
574 else idx= NO_RECORD; /* Different positions merge */
575
576 empty[0]=lastpos[0];
577 movelink(data,idx,empty_index,pos->next);
578 pos->next=empty_index;
579
580 exit: