MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / my_hash_insert

Function my_hash_insert

mysys/hash.c:386–515  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

384 /* Write a hash-key to the hash-index */
385
386my_bool my_hash_insert(HASH *info, const uchar *record)
387{
388 int flag;
389 size_t idx,halfbuff,first_index;
390 my_hash_value_type hash_nr;
391 uchar *UNINIT_VAR(ptr_to_rec),*UNINIT_VAR(ptr_to_rec2);
392 HASH_LINK *data,*empty,*UNINIT_VAR(gpos),*UNINIT_VAR(gpos2),*pos;
393
394 if (HASH_UNIQUE & info->flags)
395 {
396 uchar *key= (uchar*) my_hash_key(info, record, &idx, 1);
397 if (my_hash_search(info, key, idx))
398 return(TRUE); /* Duplicate entry */
399 }
400
401 flag=0;
402 if (!(empty=(HASH_LINK*) alloc_dynamic(&info->array)))
403 return(TRUE); /* No more memory */
404
405 data=dynamic_element(&info->array,0,HASH_LINK*);
406 halfbuff= info->blength >> 1;
407
408 idx=first_index=info->records-halfbuff;
409 if (idx != info->records) /* If some records */
410 {
411 do
412 {
413 pos=data+idx;
414 hash_nr=rec_hashnr(info,pos->data);
415 if (flag == 0) /* First loop; Check if ok */
416 if (my_hash_mask(hash_nr, info->blength, info->records) != first_index)
417 break;
418 if (!(hash_nr & halfbuff))
419 { /* Key will not move */
420 if (!(flag & LOWFIND))
421 {
422 if (flag & HIGHFIND)
423 {
424 flag=LOWFIND | HIGHFIND;
425 /* key shall be moved to the current empty position */
426 gpos=empty;
427 ptr_to_rec=pos->data;
428 empty=pos; /* This place is now free */
429 }
430 else
431 {
432 flag=LOWFIND | LOWUSED; /* key isn't changed */
433 gpos=pos;
434 ptr_to_rec=pos->data;
435 }
436 }
437 else
438 {
439 if (!(flag & LOWUSED))
440 {
441 /* Change link of previous LOW-key */
442 gpos->data=ptr_to_rec;
443 gpos->next= (uint) (pos-data);

Callers 13

mysql_options4Function · 0.85
get_variableFunction · 0.85
merge_table_listMethod · 0.85
item_create_initFunction · 0.85
mysql_add_sys_var_chainFunction · 0.85
insertMethod · 0.85
put_dboptFunction · 0.85
insertMethod · 0.85
addMethod · 0.85
safe_hash_setFunction · 0.85
do_testFunction · 0.85

Calls 7

my_hash_keyFunction · 0.85
my_hash_searchFunction · 0.85
alloc_dynamicFunction · 0.85
rec_hashnrFunction · 0.85
my_hash_maskFunction · 0.85
my_hash_rec_maskFunction · 0.85
movelinkFunction · 0.85

Tested by 1

do_testFunction · 0.68