MCPcopy Create free account
hub / github.com/ByteStorage/FlyDB / deleteNode

Method deleteNode

structure/zset.go:372–392  ·  view source on GitHub ↗

deleteNode is a method linked to the SkipList struct that allows to remove nodes from the SkipList instance. It takes two parameters: a pointer to the node to be deleted, and a slice of pointers to SkipListNode which are required for node updates. deleteNode performs the deletion through a two-step

(node *SkipListNode, updates []*SkipListNode)

Source from the content-addressed store, hash-verified

370// Finally, it decreases the size of the list by one, as a node is being removed from it.
371// It doesn't return any value and modifies the SkipList directly.
372func (sl *SkipList) deleteNode(node *SkipListNode, updates []*SkipListNode) {
373 for i := 0; i < sl.level; i++ {
374 if updates[i].level[i].next == node {
375 updates[i].level[i].span += node.level[i].span - 1
376 updates[i].level[i].next = node.level[i].next
377 } else {
378 updates[i].level[i].span--
379 }
380 }
381 //update backwards
382 if node.level[0].next != nil {
383 node.level[0].next.prev = node.prev
384 } else {
385 sl.tail = node.prev
386 }
387
388 for sl.level > 1 && sl.head.level[sl.level-1].next == nil {
389 sl.level--
390 }
391 sl.size--
392}
393
394// getRank method receives a SkipList pointer and two parameters: an integer 'score' and a string 'key'.
395// It then calculates the rank of an element in the SkipList. The rank is determined based on two conditions:

Callers 1

deleteMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected