MCPcopy Index your code
hub / github.com/ByteStorage/FlyDB / delete

Method delete

structure/zset.go:299–328  ·  view source on GitHub ↗

SkipList is a data structure that allows fast search, insertion, and removal operations. Here we define a method delete on it. The delete method in the skip list will remove nodes that have a given score and key from the skip list. If no such nodes are found, the function does nothing. Parameters:

(score int, member string)

Source from the content-addressed store, hash-verified

297// score: the score of the node to delete.
298// key: the key of the node to delete.
299func (sl *SkipList) delete(score int, member string) {
300
301 // update: an array of pointers to SkipListNodes; holds the nodes that will have their next pointers updated.
302 update := make([]*SkipListNode, SKIPLIST_MAX_LEVEL)
303
304 // node: start from the head of our SkipList sl
305 node := sl.head
306
307 // The code block of "for" loop populates the "update" variable with nodes which reference will change
308 // due to the removal of the target node.
309 for i := sl.level; i >= 0; i-- {
310 // This loop is traversing the SkipList horizontally until it finds a node with a score greater
311 // than or equal to our target score or if the scores are equal it also checks the member.
312 for node.level[i].next != nil &&
313 (node.level[i].next.value.score < score ||
314 (node.level[i].next.value.score == score &&
315 node.level[i].next.value.member < member)) {
316 node = node.level[i].next
317 }
318 update[i] = node
319 }
320
321 // After the traversal, we set the node to point to the possibly (to be) deleted node.
322 node = node.level[0].next
323
324 // If the possibly deleted node is the target node (it has the same score and member), then remove it.
325 if node != nil && node.value.score == score && node.value.member == member {
326 sl.deleteNode(node, update)
327 }
328}
329func (sl *SkipList) getRange(start int, end int, reverse bool) (nv []ZSetValue) {
330 if end > sl.size {
331 end = sl.size - 1

Callers 2

InsertNodeMethod · 0.80
RemoveNodeMethod · 0.80

Calls 1

deleteNodeMethod · 0.95

Tested by

no test coverage detected