DESCRIPTION deletes an element with the given key from the hash (if a hash is not unique and there're many elements with this key - the "first" matching element is deleted) RETURN 0 - deleted 1 - didn't (not found) -1 - out of memory NOTE see ldelete() for pin usage notes */
| 409 | see ldelete() for pin usage notes |
| 410 | */ |
| 411 | int lf_hash_delete(LF_HASH *hash, LF_PINS *pins, const void *key, uint keylen) |
| 412 | { |
| 413 | LF_SLIST * volatile *el; |
| 414 | uint bucket, hashnr= calc_hash(hash, (uchar *)key, keylen); |
| 415 | |
| 416 | bucket= hashnr % hash->size; |
| 417 | lf_rwlock_by_pins(pins); |
| 418 | el= _lf_dynarray_lvalue(&hash->array, bucket); |
| 419 | if (unlikely(!el)) |
| 420 | return -1; |
| 421 | /* |
| 422 | note that we still need to initialize_bucket here, |
| 423 | we cannot return "node not found", because an old bucket of that |
| 424 | node may've been split and the node was assigned to a new bucket |
| 425 | that was never accessed before and thus is not initialized. |
| 426 | */ |
| 427 | if (*el == NULL && unlikely(initialize_bucket(hash, el, bucket, pins))) |
| 428 | return -1; |
| 429 | if (ldelete(el, hash->charset, my_reverse_bits(hashnr) | 1, |
| 430 | (uchar *)key, keylen, pins)) |
| 431 | { |
| 432 | lf_rwunlock_by_pins(pins); |
| 433 | return 1; |
| 434 | } |
| 435 | my_atomic_add32(&hash->count, -1); |
| 436 | lf_rwunlock_by_pins(pins); |
| 437 | return 0; |
| 438 | } |
| 439 | |
| 440 | /* |
| 441 | RETURN |
no test coverage detected