MCPcopy Create free account
hub / github.com/nutsdb/nutsdb / delete

Method delete

sorted_set.go:447–471  ·  view source on GitHub ↗

delete removes an element with matching score/key from the skiplist.

(score SCORE, hash uint32)

Source from the content-addressed store, hash-verified

445
446// delete removes an element with matching score/key from the skiplist.
447func (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.
474func (sl *SkipList) Size() int {

Callers 2

PutMethod · 0.95
RemoveMethod · 0.95

Calls 2

cmpMethod · 0.95
deleteNodeMethod · 0.95

Tested by

no test coverage detected