delete removes an element with matching score/key from the skiplist.
(score SCORE, hash uint32)
| 445 | |
| 446 | // delete removes an element with matching score/key from the skiplist. |
| 447 | func (sl *SkipList) delete(score SCORE, hash uint32) bool { |
| 448 | var update [SkipListMaxLevel]*SkipListNode |
| 449 | |
| 450 | targetNode := sl.dict[hash] |
| 451 | |
| 452 | x := sl.header |
| 453 | for i := sl.level - 1; i >= 0; i-- { |
| 454 | for x.level[i].forward != nil && |
| 455 | (x.level[i].forward.score < score || |
| 456 | (x.level[i].forward.score == score && |
| 457 | sl.cmp(x.level[i].forward.record, targetNode.record) < 0)) { |
| 458 | x = x.level[i].forward |
| 459 | } |
| 460 | update[i] = x |
| 461 | } |
| 462 | /* We may have multiple elements with the same score, what we need |
| 463 | * is to find the element with both the right score and object. */ |
| 464 | x = x.level[0].forward |
| 465 | if x != nil && score == x.score && sl.cmp(x.record, targetNode.record) == 0 { |
| 466 | sl.deleteNode(x, update) |
| 467 | // free x |
| 468 | return true |
| 469 | } |
| 470 | return false /* not found */ |
| 471 | } |
| 472 | |
| 473 | // Size returns the number of elements in the SkipList. |
| 474 | func (sl *SkipList) Size() int { |
no test coverage detected