207 lines
4.1 KiB
C
207 lines
4.1 KiB
C
/**
|
|
* THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN
|
|
*/
|
|
|
|
#include "./dbl_list.h"
|
|
#include "../../common/aliases/aliases.h"
|
|
#include <stddef.h>
|
|
|
|
internal Str8List str8_node_to_list(Str8Node *node);
|
|
|
|
Str8Node *wapp_str8_list_get(const Str8List *list, u64 index) {
|
|
if (index >= list->node_count) {
|
|
return NULL;
|
|
}
|
|
|
|
Str8Node *output = NULL;
|
|
Str8Node *current = list->first;
|
|
for (u64 i = 1; i <= index; ++i) {
|
|
current = current->next;
|
|
}
|
|
|
|
output = current;
|
|
|
|
return output;
|
|
}
|
|
|
|
void wapp_str8_list_push_front(Str8List *list, Str8Node *node) {
|
|
if (!list || !node || !(node->item)) {
|
|
return;
|
|
}
|
|
|
|
Str8List node_list = str8_node_to_list(node);
|
|
|
|
if (list->node_count == 0) {
|
|
*list = node_list;
|
|
return;
|
|
}
|
|
|
|
list->node_count += node_list.node_count;
|
|
|
|
Str8Node *first = list->first;
|
|
if (first) {
|
|
first->prev = node_list.last;
|
|
}
|
|
|
|
list->first = node_list.first;
|
|
node_list.last->next = first;
|
|
}
|
|
|
|
void wapp_str8_list_push_back(Str8List *list, Str8Node *node) {
|
|
if (!list || !node || !(node->item)) {
|
|
return;
|
|
}
|
|
|
|
Str8List node_list = str8_node_to_list(node);
|
|
|
|
if (list->node_count == 0) {
|
|
*list = node_list;
|
|
return;
|
|
}
|
|
|
|
list->node_count += node_list.node_count;
|
|
|
|
Str8Node *last = list->last;
|
|
if (last) {
|
|
last->next = node_list.first;
|
|
}
|
|
|
|
list->last = node_list.last;
|
|
node_list.first->prev = last;
|
|
}
|
|
|
|
void wapp_str8_list_insert(Str8List *list, Str8Node *node, u64 index) {
|
|
if (!list || !node || !(node->item)) {
|
|
return;
|
|
}
|
|
|
|
if (index == 0) {
|
|
wapp_str8_list_push_front(list, node);
|
|
return;
|
|
} else if (index == list->node_count) {
|
|
wapp_str8_list_push_back(list, node);
|
|
return;
|
|
}
|
|
|
|
Str8Node *dst_node = wapp_str8_list_get(list, index);
|
|
if (!dst_node) {
|
|
return;
|
|
}
|
|
|
|
Str8List node_list = str8_node_to_list(node);
|
|
|
|
list->node_count += node_list.node_count;
|
|
|
|
Str8Node *prev = dst_node->prev;
|
|
|
|
dst_node->prev = node_list.last;
|
|
prev->next = node_list.first;
|
|
|
|
node_list.first->prev = prev;
|
|
node_list.last->next = dst_node;
|
|
}
|
|
|
|
Str8Node *wapp_str8_list_pop_front(Str8List *list) {
|
|
Str8Node *output = NULL;
|
|
|
|
if (!list || list->node_count == 0) {
|
|
goto RETURN_STR8_LIST_POP_FRONT;
|
|
}
|
|
|
|
output = list->first;
|
|
|
|
if (list->node_count == 1) {
|
|
*list = (Str8List){0};
|
|
goto RETURN_STR8_LIST_POP_FRONT;
|
|
}
|
|
|
|
--(list->node_count);
|
|
list->first = output->next;
|
|
|
|
output->prev = output->next = NULL;
|
|
|
|
RETURN_STR8_LIST_POP_FRONT:
|
|
return output;
|
|
}
|
|
|
|
Str8Node *wapp_str8_list_pop_back(Str8List *list) {
|
|
Str8Node *output = NULL;
|
|
|
|
if (!list || list->node_count == 0) {
|
|
goto RETURN_STR8_LIST_POP_BACK;
|
|
}
|
|
|
|
output = list->last;
|
|
|
|
if (list->node_count == 1) {
|
|
*list = (Str8List){0};
|
|
goto RETURN_STR8_LIST_POP_BACK;
|
|
}
|
|
|
|
--(list->node_count);
|
|
list->last = output->prev;
|
|
|
|
output->prev = output->next = NULL;
|
|
|
|
RETURN_STR8_LIST_POP_BACK:
|
|
return output;
|
|
}
|
|
|
|
Str8Node *wapp_str8_list_remove(Str8List *list, u64 index) {
|
|
Str8Node *output = NULL;
|
|
if (!list) {
|
|
goto RETURN_STR8_LIST_REMOVE;
|
|
}
|
|
|
|
if (index == 0) {
|
|
output = wapp_str8_list_pop_front(list);
|
|
goto RETURN_STR8_LIST_REMOVE;
|
|
} else if (index == list->node_count) {
|
|
output = wapp_str8_list_pop_back(list);
|
|
goto RETURN_STR8_LIST_REMOVE;
|
|
}
|
|
|
|
output = wapp_str8_list_get(list, index);
|
|
if (!output) {
|
|
goto RETURN_STR8_LIST_REMOVE;
|
|
}
|
|
|
|
output->prev->next = output->next;
|
|
output->next->prev = output->prev;
|
|
|
|
--(list->node_count);
|
|
|
|
output->prev = output->next = NULL;
|
|
|
|
RETURN_STR8_LIST_REMOVE:
|
|
return output;
|
|
}
|
|
|
|
void wapp_str8_list_empty(Str8List *list) {
|
|
if (!list) {
|
|
return;
|
|
}
|
|
|
|
u64 count = list->node_count;
|
|
for (u64 i = 0; i < count; ++i) {
|
|
wapp_str8_list_pop_back(list);
|
|
}
|
|
}
|
|
|
|
internal Str8List str8_node_to_list(Str8Node *node) {
|
|
Str8List output = {.first = node, .last = node, .node_count = 1};
|
|
|
|
while (output.first->prev != NULL) {
|
|
output.first = output.first->prev;
|
|
++(output.node_count);
|
|
}
|
|
|
|
while (output.last->next != NULL) {
|
|
output.last = output.last->next;
|
|
++(output.node_count);
|
|
}
|
|
|
|
return output;
|
|
}
|
|
|