newSkipListNode is a function that takes integer as level, score and a string as key along with a value of any type. It returns a pointer to a SkipListNode. This function is responsible for creating a new SkipListNode with provided level, score, key, and value. After creating the node, it initialize
(level int, score int, key string, value interface{})
| 190 | // key, and value. After creating the node, it initializes every level of the node with an empty SkipListLevel object. |
| 191 | // In the context of a skip list data structure, this function serves as a helper function for creating new nodes to be inserted to the list. |
| 192 | func newSkipListNode(level int, score int, key string, value interface{}) *SkipListNode { |
| 193 | // Create a new SkipListNode with specified score, key, value and a slice of |
| 194 | // SkipListLevel with length equal to specified level |
| 195 | node := &SkipListNode{ |
| 196 | value: newSkipListNodeValue(score, key, value), |
| 197 | level: make([]*SkipListLevel, level), |
| 198 | } |
| 199 | |
| 200 | // Initialize each SkipListLevel in the level slice |
| 201 | for i := range node.level { |
| 202 | node.level[i] = new(SkipListLevel) |
| 203 | } |
| 204 | // Returning the pointer to the created node |
| 205 | return node |
| 206 | } |
| 207 | |
| 208 | // newSkipListNodeValue is a function that constructs and returns a new ZSetValue. |
| 209 | // It takes a score (int), a key (string), and a value (interface{}) as parameters. |