MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / listAddNodeHead

Function listAddNodeHead

src/adlist.c:89–107  ·  view source on GitHub ↗

Add a new node to the list, to head, containing the specified 'value' * pointer as value. * * On error, NULL is returned and no operation is performed (i.e. the * list remains unaltered). * On success the 'list' pointer you pass to the function is returned. */

Source from the content-addressed store, hash-verified

87 * list remains unaltered).
88 * On success the 'list' pointer you pass to the function is returned. */
89list *listAddNodeHead(list *list, void *value)
90{
91 listNode *node;
92
93 if ((node = zmalloc(sizeof(*node), MALLOC_SHARED)) == NULL)
94 return NULL;
95 node->value = value;
96 if (list->len == 0) {
97 list->head = list->tail = node;
98 node->prev = node->next = NULL;
99 } else {
100 node->prev = NULL;
101 node->next = list->head;
102 list->head->prev = node;
103 list->head = node;
104 }
105 list->len++;
106 return list;
107}
108
109/* Add a new node to the list, to tail, containing the specified 'value'
110 * pointer as value.

Callers 8

ziplistTestFunction · 0.85
snapshot_scan_callbackFunction · 0.85
waitCommandFunction · 0.85
debugCommandFunction · 0.85
addACLLogEntryFunction · 0.85
slowlogPushEntryIfNeededFunction · 0.85

Calls 1

zmallocFunction · 0.85

Tested by

no test coverage detected