Compare commits
4 Commits
0942643b4e
...
aa04fab6ea
Author | SHA1 | Date | |
---|---|---|---|
|
aa04fab6ea | ||
|
2017f6de79 | ||
|
63acdd1336 | ||
|
cfa8094260 |
@ -1,8 +1,16 @@
|
|||||||
from codegen.dbl_list.gen_dbl_list import gen_dbl_list
|
from pathlib import Path
|
||||||
|
from codegen.datatypes import CDataType
|
||||||
|
from codegen.dbl_list.gen_dbl_list import DblListData, gen_dbl_list
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
gen_dbl_list()
|
datatypes: dict[CDataType, DblListData] = {
|
||||||
|
"int": DblListData(
|
||||||
|
out_dir=Path("/Users/abdelrahman/dev/personal/wizapp-stdlib"),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_dbl_list(datatypes)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -21,15 +21,13 @@ from codegen.datatypes import (
|
|||||||
@dataclass
|
@dataclass
|
||||||
class DblListData:
|
class DblListData:
|
||||||
out_dir: Path
|
out_dir: Path
|
||||||
common_includes: list[CInclude] = field(default_factory=list)
|
|
||||||
hdr_includes: list[CInclude] = field(default_factory=list)
|
hdr_includes: list[CInclude] = field(default_factory=list)
|
||||||
src_includes: list[CInclude] = field(default_factory=list)
|
src_includes: list[CInclude] = field(default_factory=list)
|
||||||
common_decl_types: list[CStruct] = field(default_factory=list)
|
|
||||||
hdr_decl_types: list[CStruct] = field(default_factory=list)
|
hdr_decl_types: list[CStruct] = field(default_factory=list)
|
||||||
src_decl_types: list[CStruct] = field(default_factory=list)
|
src_decl_types: list[CStruct] = field(default_factory=list)
|
||||||
|
|
||||||
|
|
||||||
def gen_dbl_list():
|
def gen_dbl_list(user_datatypes: dict[CDataType, DblListData] = {}):
|
||||||
def __format_func_body(filename: Path, type_string: str):
|
def __format_func_body(filename: Path, type_string: str):
|
||||||
return load_func_body_from_file(filename).format(
|
return load_func_body_from_file(filename).format(
|
||||||
T=type_string,
|
T=type_string,
|
||||||
@ -37,11 +35,14 @@ def gen_dbl_list():
|
|||||||
Tlower=type_string.lower(),
|
Tlower=type_string.lower(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
common_includes: list[CInclude] = [
|
||||||
|
CInclude(header="../../../common/aliases/aliases.h", local=True),
|
||||||
|
]
|
||||||
|
|
||||||
|
common_decl_types: list[CStruct] = []
|
||||||
|
|
||||||
datatypes: dict[CDataType, DblListData] = {
|
datatypes: dict[CDataType, DblListData] = {
|
||||||
"Str8": DblListData(
|
"Str8": DblListData(
|
||||||
common_includes=[
|
|
||||||
CInclude(header="../../../common/aliases/aliases.h", local=True),
|
|
||||||
],
|
|
||||||
src_includes=[
|
src_includes=[
|
||||||
CInclude(header="./str8.h", local=True),
|
CInclude(header="./str8.h", local=True),
|
||||||
],
|
],
|
||||||
@ -51,6 +52,8 @@ def gen_dbl_list():
|
|||||||
out_dir=WAPP_SRC_ROOT / "core/strings/str8/",
|
out_dir=WAPP_SRC_ROOT / "core/strings/str8/",
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
datatypes.update(user_datatypes)
|
||||||
|
|
||||||
snippets_dir = Path(__file__).parent / "snippets"
|
snippets_dir = Path(__file__).parent / "snippets"
|
||||||
|
|
||||||
for _type, dbl_list_data in datatypes.items():
|
for _type, dbl_list_data in datatypes.items():
|
||||||
@ -59,7 +62,7 @@ def gen_dbl_list():
|
|||||||
node = CStruct(
|
node = CStruct(
|
||||||
name=f"{type_string}Node",
|
name=f"{type_string}Node",
|
||||||
cargs=[
|
cargs=[
|
||||||
CArg(name="string", _type=type_string, pointer=CPointer(_type=CPointerType.SINGLE)),
|
CArg(name="item", _type=type_string, pointer=CPointer(_type=CPointerType.SINGLE)),
|
||||||
CArg(name="prev", _type=f"{type_string}Node", pointer=CPointer(_type=CPointerType.SINGLE)),
|
CArg(name="prev", _type=f"{type_string}Node", pointer=CPointer(_type=CPointerType.SINGLE)),
|
||||||
CArg(name="next", _type=f"{type_string}Node", pointer=CPointer(_type=CPointerType.SINGLE)),
|
CArg(name="next", _type=f"{type_string}Node", pointer=CPointer(_type=CPointerType.SINGLE)),
|
||||||
],
|
],
|
||||||
@ -70,7 +73,6 @@ def gen_dbl_list():
|
|||||||
cargs=[
|
cargs=[
|
||||||
CArg(name="first", _type=node, pointer=CPointer(_type=CPointerType.SINGLE)),
|
CArg(name="first", _type=node, pointer=CPointer(_type=CPointerType.SINGLE)),
|
||||||
CArg(name="last", _type=node, pointer=CPointer(_type=CPointerType.SINGLE)),
|
CArg(name="last", _type=node, pointer=CPointer(_type=CPointerType.SINGLE)),
|
||||||
CArg(name="total_size", _type=CType.U64),
|
|
||||||
CArg(name="node_count", _type=CType.U64),
|
CArg(name="node_count", _type=CType.U64),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@ -169,7 +171,7 @@ def gen_dbl_list():
|
|||||||
|
|
||||||
header = CHeader(
|
header = CHeader(
|
||||||
name=f"{type_string.lower()}_list",
|
name=f"{type_string.lower()}_list",
|
||||||
decl_types=dbl_list_data.common_decl_types + dbl_list_data.hdr_decl_types,
|
decl_types=common_decl_types + dbl_list_data.hdr_decl_types,
|
||||||
includes=[],
|
includes=[],
|
||||||
types=[node, dl_list],
|
types=[node, dl_list],
|
||||||
funcs=[
|
funcs=[
|
||||||
@ -186,15 +188,15 @@ def gen_dbl_list():
|
|||||||
|
|
||||||
source = CSource(
|
source = CSource(
|
||||||
name=header.name,
|
name=header.name,
|
||||||
decl_types=dbl_list_data.common_decl_types + dbl_list_data.src_decl_types,
|
decl_types=common_decl_types + dbl_list_data.src_decl_types,
|
||||||
includes=[CInclude(header, local=True, same_dir=True), CInclude(header="stddef.h")],
|
includes=[CInclude(header, local=True, same_dir=True), CInclude(header="stddef.h")],
|
||||||
internal_funcs=[node_to_list_func],
|
internal_funcs=[node_to_list_func],
|
||||||
funcs=header.funcs
|
funcs=header.funcs
|
||||||
)
|
)
|
||||||
|
|
||||||
if len(dbl_list_data.common_includes) > 0:
|
if len(common_includes) > 0:
|
||||||
header.includes.extend(dbl_list_data.common_includes)
|
header.includes.extend(common_includes)
|
||||||
source.includes.extend(dbl_list_data.common_includes)
|
source.includes.extend(common_includes)
|
||||||
|
|
||||||
if len(dbl_list_data.hdr_includes) > 0:
|
if len(dbl_list_data.hdr_includes) > 0:
|
||||||
header.includes.extend(dbl_list_data.hdr_includes)
|
header.includes.extend(dbl_list_data.hdr_includes)
|
||||||
|
@ -4,5 +4,5 @@
|
|||||||
|
|
||||||
u64 count = list->node_count;
|
u64 count = list->node_count;
|
||||||
for (u64 i = 0; i < count; ++i) {{
|
for (u64 i = 0; i < count; ++i) {{
|
||||||
wapp_str8_list_pop_back(list);
|
wapp_{Tlower}_list_pop_back(list);
|
||||||
}}
|
}}
|
||||||
|
@ -1,23 +1,22 @@
|
|||||||
if (!list || !node || !(node->string)) {{
|
if (!list || !node || !(node->item)) {{
|
||||||
return;
|
return;
|
||||||
}}
|
}}
|
||||||
|
|
||||||
if (index == 0) {{
|
if (index == 0) {{
|
||||||
wapp_str8_list_push_front(list, node);
|
wapp_{Tlower}_list_push_front(list, node);
|
||||||
return;
|
return;
|
||||||
}} else if (index == list->node_count) {{
|
}} else if (index == list->node_count) {{
|
||||||
wapp_str8_list_push_back(list, node);
|
wapp_{Tlower}_list_push_back(list, node);
|
||||||
return;
|
return;
|
||||||
}}
|
}}
|
||||||
|
|
||||||
{T}Node *dst_node = wapp_str8_list_get(list, index);
|
{T}Node *dst_node = wapp_{Tlower}_list_get(list, index);
|
||||||
if (!dst_node) {{
|
if (!dst_node) {{
|
||||||
return;
|
return;
|
||||||
}}
|
}}
|
||||||
|
|
||||||
{T}List node_list = {Tlower}_node_to_list(node);
|
{T}List node_list = {Tlower}_node_to_list(node);
|
||||||
|
|
||||||
list->total_size += node_list.total_size;
|
|
||||||
list->node_count += node_list.node_count;
|
list->node_count += node_list.node_count;
|
||||||
|
|
||||||
{T}Node *prev = dst_node->prev;
|
{T}Node *prev = dst_node->prev;
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
}}
|
}}
|
||||||
|
|
||||||
--(list->node_count);
|
--(list->node_count);
|
||||||
list->total_size -= output->string->size;
|
|
||||||
list->last = output->prev;
|
list->last = output->prev;
|
||||||
|
|
||||||
output->prev = output->next = NULL;
|
output->prev = output->next = NULL;
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
}}
|
}}
|
||||||
|
|
||||||
--(list->node_count);
|
--(list->node_count);
|
||||||
list->total_size -= output->string->size;
|
|
||||||
list->first = output->next;
|
list->first = output->next;
|
||||||
|
|
||||||
output->prev = output->next = NULL;
|
output->prev = output->next = NULL;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
if (!list || !node || !(node->string)) {{
|
if (!list || !node || !(node->item)) {{
|
||||||
return;
|
return;
|
||||||
}}
|
}}
|
||||||
|
|
||||||
@ -9,7 +9,6 @@
|
|||||||
return;
|
return;
|
||||||
}}
|
}}
|
||||||
|
|
||||||
list->total_size += node_list.total_size;
|
|
||||||
list->node_count += node_list.node_count;
|
list->node_count += node_list.node_count;
|
||||||
|
|
||||||
{T}Node *last = list->last;
|
{T}Node *last = list->last;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
if (!list || !node || !(node->string)) {{
|
if (!list || !node || !(node->item)) {{
|
||||||
return;
|
return;
|
||||||
}}
|
}}
|
||||||
|
|
||||||
@ -9,7 +9,6 @@
|
|||||||
return;
|
return;
|
||||||
}}
|
}}
|
||||||
|
|
||||||
list->total_size += node_list.total_size;
|
|
||||||
list->node_count += node_list.node_count;
|
list->node_count += node_list.node_count;
|
||||||
|
|
||||||
{T}Node *first = list->first;
|
{T}Node *first = list->first;
|
||||||
|
@ -4,14 +4,14 @@
|
|||||||
}}
|
}}
|
||||||
|
|
||||||
if (index == 0) {{
|
if (index == 0) {{
|
||||||
output = wapp_str8_list_pop_front(list);
|
output = wapp_{Tlower}_list_pop_front(list);
|
||||||
goto RETURN_{Tupper}_LIST_REMOVE;
|
goto RETURN_{Tupper}_LIST_REMOVE;
|
||||||
}} else if (index == list->node_count) {{
|
}} else if (index == list->node_count) {{
|
||||||
output = wapp_str8_list_pop_back(list);
|
output = wapp_{Tlower}_list_pop_back(list);
|
||||||
goto RETURN_{Tupper}_LIST_REMOVE;
|
goto RETURN_{Tupper}_LIST_REMOVE;
|
||||||
}}
|
}}
|
||||||
|
|
||||||
output = wapp_str8_list_get(list, index);
|
output = wapp_{Tlower}_list_get(list, index);
|
||||||
if (!output) {{
|
if (!output) {{
|
||||||
goto RETURN_{Tupper}_LIST_REMOVE;
|
goto RETURN_{Tupper}_LIST_REMOVE;
|
||||||
}}
|
}}
|
||||||
@ -20,7 +20,6 @@
|
|||||||
output->next->prev = output->prev;
|
output->next->prev = output->prev;
|
||||||
|
|
||||||
--(list->node_count);
|
--(list->node_count);
|
||||||
list->total_size -= output->string->size;
|
|
||||||
|
|
||||||
output->prev = output->next = NULL;
|
output->prev = output->next = NULL;
|
||||||
|
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
{T}List output = {{.first = node, .last = node, .total_size = node->string->size, .node_count = 1}};
|
{T}List output = {{.first = node, .last = node, .node_count = 1}};
|
||||||
|
|
||||||
while (output.first->prev != NULL) {{
|
while (output.first->prev != NULL) {{
|
||||||
output.total_size += output.first->prev->string->size;
|
|
||||||
output.first = output.first->prev;
|
output.first = output.first->prev;
|
||||||
++(output.node_count);
|
++(output.node_count);
|
||||||
}}
|
}}
|
||||||
|
|
||||||
while (output.last->next != NULL) {{
|
while (output.last->next != NULL) {{
|
||||||
output.total_size += output.last->next->string->size;
|
|
||||||
output.last = output.last->next;
|
output.last = output.last->next;
|
||||||
++(output.node_count);
|
++(output.node_count);
|
||||||
}}
|
}}
|
||||||
|
@ -3,4 +3,4 @@ from pathlib import Path
|
|||||||
|
|
||||||
def load_func_body_from_file(filename: Path) -> str:
|
def load_func_body_from_file(filename: Path) -> str:
|
||||||
with open(filename, "r") as infile:
|
with open(filename, "r") as infile:
|
||||||
return infile.read()
|
return infile.read().strip()
|
||||||
|
@ -21,14 +21,14 @@ u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts) {
|
|||||||
Str8 separator = wapp_str8_buf(4);
|
Str8 separator = wapp_str8_buf(4);
|
||||||
wapp_str8_push_back(&separator, PATH_SEP);
|
wapp_str8_push_back(&separator, PATH_SEP);
|
||||||
|
|
||||||
u64 required_capacity = parts->node_count * separator.size + parts->total_size;
|
u64 required_capacity = parts->node_count * separator.size + wapp_str8_list_total_size(parts);
|
||||||
if (dst->capacity < required_capacity) {
|
if (dst->capacity < required_capacity) {
|
||||||
return CPATH_JOIN_INSUFFICIENT_DST_CAPACITY;
|
return CPATH_JOIN_INSUFFICIENT_DST_CAPACITY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle first node
|
// Handle first node
|
||||||
const Str8Node *first_node = wapp_str8_list_get(parts, 0);
|
const Str8Node *first_node = wapp_str8_list_get(parts, 0);
|
||||||
wapp_str8_copy_str8_capped(dst, first_node->string);
|
wapp_str8_copy_str8_capped(dst, first_node->item);
|
||||||
|
|
||||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||||
// MSVC Spectre mitigation warnings
|
// MSVC Spectre mitigation warnings
|
||||||
@ -37,13 +37,13 @@ u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts) {
|
|||||||
bool running = true;
|
bool running = true;
|
||||||
while (running && node->next) {
|
while (running && node->next) {
|
||||||
node = node->next;
|
node = node->next;
|
||||||
if (node->string->size == 0) {
|
if (node->item->size == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dst->size > 0) {
|
if (dst->size > 0) {
|
||||||
char dst_last = wapp_str8_get(dst, dst->size - 1);
|
char dst_last = wapp_str8_get(dst, dst->size - 1);
|
||||||
char node_start = wapp_str8_get(node->string, 0);
|
char node_start = wapp_str8_get(node->item, 0);
|
||||||
bool add_path_sep = dst_last != PATH_SEP && node_start != PATH_SEP;
|
bool add_path_sep = dst_last != PATH_SEP && node_start != PATH_SEP;
|
||||||
|
|
||||||
if (add_path_sep) {
|
if (add_path_sep) {
|
||||||
@ -51,7 +51,7 @@ u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wapp_str8_concat_capped(dst, node->string);
|
wapp_str8_concat_capped(dst, node->item);
|
||||||
|
|
||||||
++node_index;
|
++node_index;
|
||||||
running = node_index < parts->node_count;
|
running = node_index < parts->node_count;
|
||||||
@ -108,7 +108,7 @@ Str8 *dirup(const Allocator *allocator, Str8RO *path, u64 levels) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
u64 alignment = sizeof(void *) * 2;
|
u64 alignment = sizeof(void *) * 2;
|
||||||
u64 alloc_size = parts->total_size + parts->node_count * separator.size;
|
u64 alloc_size = wapp_str8_list_total_size(parts) + parts->node_count * separator.size;
|
||||||
u64 modulo = alloc_size & (alignment - 1);
|
u64 modulo = alloc_size & (alignment - 1);
|
||||||
alloc_size += alignment - modulo;
|
alloc_size += alignment - modulo;
|
||||||
|
|
||||||
|
@ -311,7 +311,7 @@ Str8List *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8
|
|||||||
Str8 *full = wapp_str8_alloc_str8(allocator, str);
|
Str8 *full = wapp_str8_alloc_str8(allocator, str);
|
||||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||||
if (node) {
|
if (node) {
|
||||||
node->string = full;
|
node->item = full;
|
||||||
wapp_str8_list_push_back(output, node);
|
wapp_str8_list_push_back(output, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -332,7 +332,7 @@ Str8List *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8
|
|||||||
before_str = wapp_str8_alloc_substr(allocator, str, start, start + end);
|
before_str = wapp_str8_alloc_substr(allocator, str, start, start + end);
|
||||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||||
if (node) {
|
if (node) {
|
||||||
node->string = before_str;
|
node->item = before_str;
|
||||||
wapp_str8_list_push_back(output, node);
|
wapp_str8_list_push_back(output, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,7 +347,7 @@ Str8List *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8
|
|||||||
rest = wapp_str8_alloc_substr(allocator, str, start, str->size);
|
rest = wapp_str8_alloc_substr(allocator, str, start, str->size);
|
||||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||||
if (node) {
|
if (node) {
|
||||||
node->string = rest;
|
node->item = rest;
|
||||||
wapp_str8_list_push_back(output, node);
|
wapp_str8_list_push_back(output, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -366,7 +366,7 @@ Str8List *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str
|
|||||||
Str8 *full = wapp_str8_alloc_str8(allocator, str);
|
Str8 *full = wapp_str8_alloc_str8(allocator, str);
|
||||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||||
if (node) {
|
if (node) {
|
||||||
node->string = full;
|
node->item = full;
|
||||||
wapp_str8_list_push_back(output, node);
|
wapp_str8_list_push_back(output, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,7 +386,7 @@ Str8List *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str
|
|||||||
after_str = wapp_str8_alloc_substr(allocator, rest, end + delimiter->size, str->size);
|
after_str = wapp_str8_alloc_substr(allocator, rest, end + delimiter->size, str->size);
|
||||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||||
if (node) {
|
if (node) {
|
||||||
node->string = after_str;
|
node->item = after_str;
|
||||||
wapp_str8_list_push_front(output, node);
|
wapp_str8_list_push_front(output, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -399,7 +399,7 @@ Str8List *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str
|
|||||||
rest = wapp_str8_alloc_substr(allocator, str, 0, rest->size);
|
rest = wapp_str8_alloc_substr(allocator, str, 0, rest->size);
|
||||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||||
if (node) {
|
if (node) {
|
||||||
node->string = rest;
|
node->item = rest;
|
||||||
wapp_str8_list_push_front(output, node);
|
wapp_str8_list_push_front(output, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -412,7 +412,7 @@ Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8RO *d
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 capacity = list->total_size + (delimiter->size * (list->node_count - 1));
|
u64 capacity = wapp_str8_list_total_size(list) + (delimiter->size * (list->node_count - 1));
|
||||||
Str8 *output = wapp_str8_alloc_buf(allocator, capacity * 2);
|
Str8 *output = wapp_str8_alloc_buf(allocator, capacity * 2);
|
||||||
|
|
||||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||||
@ -422,7 +422,7 @@ Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8RO *d
|
|||||||
bool running = true;
|
bool running = true;
|
||||||
while (running) {
|
while (running) {
|
||||||
node = wapp_str8_list_get(list, node_index);
|
node = wapp_str8_list_get(list, node_index);
|
||||||
wapp_str8_concat_capped(output, node->string);
|
wapp_str8_concat_capped(output, node->item);
|
||||||
if (node_index + 1 < list->node_count) {
|
if (node_index + 1 < list->node_count) {
|
||||||
wapp_str8_concat_capped(output, delimiter);
|
wapp_str8_concat_capped(output, delimiter);
|
||||||
}
|
}
|
||||||
@ -433,3 +433,17 @@ Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8RO *d
|
|||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u64 wapp_str8_list_total_size(const Str8List *list) {
|
||||||
|
if (!list) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 output = 0;
|
||||||
|
for (u64 i = 0; i < list->node_count; ++i) {
|
||||||
|
Str8Node *node = wapp_str8_list_get(list, i);
|
||||||
|
output += node->item->size;
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
@ -91,8 +91,9 @@ Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8R
|
|||||||
/**
|
/**
|
||||||
* Str8 list utilities
|
* Str8 list utilities
|
||||||
*/
|
*/
|
||||||
#define wapp_str8_node_from_cstr(STRING) ((Str8Node){.string = &wapp_str8_lit(STRING)})
|
#define wapp_str8_node_from_cstr(STRING) ((Str8Node){.item = &wapp_str8_lit(STRING)})
|
||||||
#define wapp_str8_node_from_str8(STRING) ((Str8Node){.string = &(STRING)})
|
#define wapp_str8_node_from_str8(STRING) ((Str8Node){.item = &(STRING)})
|
||||||
|
u64 wapp_str8_list_total_size(const Str8List *list);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
END_C_LINKAGE
|
END_C_LINKAGE
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
internal Str8List str8_node_to_list(Str8Node *node);
|
internal Str8List str8_node_to_list(Str8Node *node);
|
||||||
|
|
||||||
Str8Node *wapp_str8_list_get(const Str8List *list, u64 index) {
|
Str8Node *wapp_str8_list_get(const Str8List *list, u64 index) {
|
||||||
if (index >= list->node_count) {
|
if (index >= list->node_count) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,11 +23,10 @@ Str8Node *wapp_str8_list_get(const Str8List *list, u64 index) {
|
|||||||
output = current;
|
output = current;
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wapp_str8_list_push_front(Str8List *list, Str8Node *node) {
|
void wapp_str8_list_push_front(Str8List *list, Str8Node *node) {
|
||||||
if (!list || !node || !(node->string)) {
|
if (!list || !node || !(node->item)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +37,6 @@ void wapp_str8_list_push_front(Str8List *list, Str8Node *node) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
list->total_size += node_list.total_size;
|
|
||||||
list->node_count += node_list.node_count;
|
list->node_count += node_list.node_count;
|
||||||
|
|
||||||
Str8Node *first = list->first;
|
Str8Node *first = list->first;
|
||||||
@ -48,11 +46,10 @@ void wapp_str8_list_push_front(Str8List *list, Str8Node *node) {
|
|||||||
|
|
||||||
list->first = node_list.first;
|
list->first = node_list.first;
|
||||||
node_list.last->next = first;
|
node_list.last->next = first;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wapp_str8_list_push_back(Str8List *list, Str8Node *node) {
|
void wapp_str8_list_push_back(Str8List *list, Str8Node *node) {
|
||||||
if (!list || !node || !(node->string)) {
|
if (!list || !node || !(node->item)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,7 +60,6 @@ void wapp_str8_list_push_back(Str8List *list, Str8Node *node) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
list->total_size += node_list.total_size;
|
|
||||||
list->node_count += node_list.node_count;
|
list->node_count += node_list.node_count;
|
||||||
|
|
||||||
Str8Node *last = list->last;
|
Str8Node *last = list->last;
|
||||||
@ -73,11 +69,10 @@ void wapp_str8_list_push_back(Str8List *list, Str8Node *node) {
|
|||||||
|
|
||||||
list->last = node_list.last;
|
list->last = node_list.last;
|
||||||
node_list.first->prev = last;
|
node_list.first->prev = last;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wapp_str8_list_insert(Str8List *list, Str8Node *node, u64 index) {
|
void wapp_str8_list_insert(Str8List *list, Str8Node *node, u64 index) {
|
||||||
if (!list || !node || !(node->string)) {
|
if (!list || !node || !(node->item)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +91,6 @@ void wapp_str8_list_insert(Str8List *list, Str8Node *node, u64 index) {
|
|||||||
|
|
||||||
Str8List node_list = str8_node_to_list(node);
|
Str8List node_list = str8_node_to_list(node);
|
||||||
|
|
||||||
list->total_size += node_list.total_size;
|
|
||||||
list->node_count += node_list.node_count;
|
list->node_count += node_list.node_count;
|
||||||
|
|
||||||
Str8Node *prev = dst_node->prev;
|
Str8Node *prev = dst_node->prev;
|
||||||
@ -106,11 +100,10 @@ void wapp_str8_list_insert(Str8List *list, Str8Node *node, u64 index) {
|
|||||||
|
|
||||||
node_list.first->prev = prev;
|
node_list.first->prev = prev;
|
||||||
node_list.last->next = dst_node;
|
node_list.last->next = dst_node;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Str8Node *wapp_str8_list_pop_front(Str8List *list) {
|
Str8Node *wapp_str8_list_pop_front(Str8List *list) {
|
||||||
Str8Node *output = NULL;
|
Str8Node *output = NULL;
|
||||||
|
|
||||||
if (!list || list->node_count == 0) {
|
if (!list || list->node_count == 0) {
|
||||||
goto RETURN_STR8_LIST_POP_FRONT;
|
goto RETURN_STR8_LIST_POP_FRONT;
|
||||||
@ -124,18 +117,16 @@ Str8Node *wapp_str8_list_pop_front(Str8List *list) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
--(list->node_count);
|
--(list->node_count);
|
||||||
list->total_size -= output->string->size;
|
|
||||||
list->first = output->next;
|
list->first = output->next;
|
||||||
|
|
||||||
output->prev = output->next = NULL;
|
output->prev = output->next = NULL;
|
||||||
|
|
||||||
RETURN_STR8_LIST_POP_FRONT:
|
RETURN_STR8_LIST_POP_FRONT:
|
||||||
return output;
|
return output;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Str8Node *wapp_str8_list_pop_back(Str8List *list) {
|
Str8Node *wapp_str8_list_pop_back(Str8List *list) {
|
||||||
Str8Node *output = NULL;
|
Str8Node *output = NULL;
|
||||||
|
|
||||||
if (!list || list->node_count == 0) {
|
if (!list || list->node_count == 0) {
|
||||||
goto RETURN_STR8_LIST_POP_BACK;
|
goto RETURN_STR8_LIST_POP_BACK;
|
||||||
@ -149,18 +140,16 @@ Str8Node *wapp_str8_list_pop_back(Str8List *list) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
--(list->node_count);
|
--(list->node_count);
|
||||||
list->total_size -= output->string->size;
|
|
||||||
list->last = output->prev;
|
list->last = output->prev;
|
||||||
|
|
||||||
output->prev = output->next = NULL;
|
output->prev = output->next = NULL;
|
||||||
|
|
||||||
RETURN_STR8_LIST_POP_BACK:
|
RETURN_STR8_LIST_POP_BACK:
|
||||||
return output;
|
return output;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Str8Node *wapp_str8_list_remove(Str8List *list, u64 index) {
|
Str8Node *wapp_str8_list_remove(Str8List *list, u64 index) {
|
||||||
Str8Node *output = NULL;
|
Str8Node *output = NULL;
|
||||||
if (!list) {
|
if (!list) {
|
||||||
goto RETURN_STR8_LIST_REMOVE;
|
goto RETURN_STR8_LIST_REMOVE;
|
||||||
}
|
}
|
||||||
@ -182,17 +171,15 @@ Str8Node *wapp_str8_list_remove(Str8List *list, u64 index) {
|
|||||||
output->next->prev = output->prev;
|
output->next->prev = output->prev;
|
||||||
|
|
||||||
--(list->node_count);
|
--(list->node_count);
|
||||||
list->total_size -= output->string->size;
|
|
||||||
|
|
||||||
output->prev = output->next = NULL;
|
output->prev = output->next = NULL;
|
||||||
|
|
||||||
RETURN_STR8_LIST_REMOVE:
|
RETURN_STR8_LIST_REMOVE:
|
||||||
return output;
|
return output;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wapp_str8_list_empty(Str8List *list) {
|
void wapp_str8_list_empty(Str8List *list) {
|
||||||
if (!list) {
|
if (!list) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,25 +187,21 @@ void wapp_str8_list_empty(Str8List *list) {
|
|||||||
for (u64 i = 0; i < count; ++i) {
|
for (u64 i = 0; i < count; ++i) {
|
||||||
wapp_str8_list_pop_back(list);
|
wapp_str8_list_pop_back(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal Str8List str8_node_to_list(Str8Node *node) {
|
internal Str8List str8_node_to_list(Str8Node *node) {
|
||||||
Str8List output = {.first = node, .last = node, .total_size = node->string->size, .node_count = 1};
|
Str8List output = {.first = node, .last = node, .node_count = 1};
|
||||||
|
|
||||||
while (output.first->prev != NULL) {
|
while (output.first->prev != NULL) {
|
||||||
output.total_size += output.first->prev->string->size;
|
|
||||||
output.first = output.first->prev;
|
output.first = output.first->prev;
|
||||||
++(output.node_count);
|
++(output.node_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (output.last->next != NULL) {
|
while (output.last->next != NULL) {
|
||||||
output.total_size += output.last->next->string->size;
|
|
||||||
output.last = output.last->next;
|
output.last = output.last->next;
|
||||||
++(output.node_count);
|
++(output.node_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ typedef struct str8 Str8;
|
|||||||
|
|
||||||
typedef struct Str8Node Str8Node;
|
typedef struct Str8Node Str8Node;
|
||||||
struct Str8Node {
|
struct Str8Node {
|
||||||
Str8 *string;
|
Str8 *item;
|
||||||
Str8Node *prev;
|
Str8Node *prev;
|
||||||
Str8Node *next;
|
Str8Node *next;
|
||||||
};
|
};
|
||||||
@ -24,7 +24,6 @@ typedef struct Str8List Str8List;
|
|||||||
struct Str8List {
|
struct Str8List {
|
||||||
Str8Node *first;
|
Str8Node *first;
|
||||||
Str8Node *last;
|
Str8Node *last;
|
||||||
u64 total_size;
|
|
||||||
u64 node_count;
|
u64 node_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -438,14 +438,14 @@ TestFuncResult test_str8_split(void) {
|
|||||||
u64 count2 = ARRLEN(splits2);
|
u64 count2 = ARRLEN(splits2);
|
||||||
bool running2 = true;
|
bool running2 = true;
|
||||||
|
|
||||||
result = list1->node_count == count1 && list1->total_size == str.size - 3;
|
result = list1->node_count == count1 && wapp_str8_list_total_size(list1) == str.size - 3;
|
||||||
result = result && list2->node_count == count2 && list2->total_size == str.size - 4;
|
result = result && list2->node_count == count2 && wapp_str8_list_total_size(list2) == str.size - 4;
|
||||||
|
|
||||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||||
// MSVC Spectre mitigation warnings
|
// MSVC Spectre mitigation warnings
|
||||||
while (running1) {
|
while (running1) {
|
||||||
Str8Node *node = wapp_str8_list_get(list1, index1);
|
Str8Node *node = wapp_str8_list_get(list1, index1);
|
||||||
result = result && wapp_str8_equal(node->string, &(splits1[index1]));
|
result = result && wapp_str8_equal(node->item, &(splits1[index1]));
|
||||||
|
|
||||||
++index1;
|
++index1;
|
||||||
running1 = index1 < count1;
|
running1 = index1 < count1;
|
||||||
@ -455,7 +455,7 @@ TestFuncResult test_str8_split(void) {
|
|||||||
// MSVC Spectre mitigation warnings
|
// MSVC Spectre mitigation warnings
|
||||||
while (running2) {
|
while (running2) {
|
||||||
Str8Node *node = wapp_str8_list_get(list2, index2);
|
Str8Node *node = wapp_str8_list_get(list2, index2);
|
||||||
result = result && wapp_str8_equal(node->string, &(splits2[index2]));
|
result = result && wapp_str8_equal(node->item, &(splits2[index2]));
|
||||||
|
|
||||||
++index2;
|
++index2;
|
||||||
running2 = index2 < count2;
|
running2 = index2 < count2;
|
||||||
@ -484,13 +484,13 @@ TestFuncResult test_str8_split_with_max(void) {
|
|||||||
u64 count = ARRLEN(splits);
|
u64 count = ARRLEN(splits);
|
||||||
bool running = true;
|
bool running = true;
|
||||||
|
|
||||||
result = list->node_count == count && list->total_size == str.size - 2;
|
result = list->node_count == count && wapp_str8_list_total_size(list) == str.size - 2;
|
||||||
|
|
||||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||||
// MSVC Spectre mitigation warnings
|
// MSVC Spectre mitigation warnings
|
||||||
while (running) {
|
while (running) {
|
||||||
Str8Node *node = wapp_str8_list_get(list, index);
|
Str8Node *node = wapp_str8_list_get(list, index);
|
||||||
result = result && wapp_str8_equal(node->string, &(splits[index]));
|
result = result && wapp_str8_equal(node->item, &(splits[index]));
|
||||||
|
|
||||||
++index;
|
++index;
|
||||||
running = index < count;
|
running = index < count;
|
||||||
@ -530,14 +530,14 @@ TestFuncResult test_str8_rsplit(void) {
|
|||||||
u64 count2 = ARRLEN(splits2);
|
u64 count2 = ARRLEN(splits2);
|
||||||
bool running2 = true;
|
bool running2 = true;
|
||||||
|
|
||||||
result = list1->node_count == count1 && list1->total_size == str.size - 3;
|
result = list1->node_count == count1 && wapp_str8_list_total_size(list1) == str.size - 3;
|
||||||
result = result && list2->node_count == count2 && list2->total_size == str.size - 4;
|
result = result && list2->node_count == count2 && wapp_str8_list_total_size(list2) == str.size - 4;
|
||||||
|
|
||||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||||
// MSVC Spectre mitigation warnings
|
// MSVC Spectre mitigation warnings
|
||||||
while (running1) {
|
while (running1) {
|
||||||
Str8Node *node = wapp_str8_list_get(list1, index1);
|
Str8Node *node = wapp_str8_list_get(list1, index1);
|
||||||
result = result && wapp_str8_equal(node->string, &(splits1[index1]));
|
result = result && wapp_str8_equal(node->item, &(splits1[index1]));
|
||||||
|
|
||||||
++index1;
|
++index1;
|
||||||
running1 = index1 < count1;
|
running1 = index1 < count1;
|
||||||
@ -547,7 +547,7 @@ TestFuncResult test_str8_rsplit(void) {
|
|||||||
// MSVC Spectre mitigation warnings
|
// MSVC Spectre mitigation warnings
|
||||||
while (running2) {
|
while (running2) {
|
||||||
Str8Node *node = wapp_str8_list_get(list2, index2);
|
Str8Node *node = wapp_str8_list_get(list2, index2);
|
||||||
result = result && wapp_str8_equal(node->string, &(splits2[index2]));
|
result = result && wapp_str8_equal(node->item, &(splits2[index2]));
|
||||||
|
|
||||||
++index2;
|
++index2;
|
||||||
running2 = index2 < count2;
|
running2 = index2 < count2;
|
||||||
@ -576,13 +576,13 @@ TestFuncResult test_str8_rsplit_with_max(void) {
|
|||||||
u64 count = ARRLEN(splits);
|
u64 count = ARRLEN(splits);
|
||||||
bool running = true;
|
bool running = true;
|
||||||
|
|
||||||
result = list->node_count == count && list->total_size == str.size - 2;
|
result = list->node_count == count && wapp_str8_list_total_size(list) == str.size - 2;
|
||||||
|
|
||||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||||
// MSVC Spectre mitigation warnings
|
// MSVC Spectre mitigation warnings
|
||||||
while (running) {
|
while (running) {
|
||||||
Str8Node *node = wapp_str8_list_get(list, index);
|
Str8Node *node = wapp_str8_list_get(list, index);
|
||||||
result = result && wapp_str8_equal(node->string, &(splits[index]));
|
result = result && wapp_str8_equal(node->item, &(splits[index]));
|
||||||
|
|
||||||
++index;
|
++index;
|
||||||
running = index < count;
|
running = index < count;
|
||||||
|
@ -11,11 +11,11 @@ TestFuncResult test_str8_list_get(void) {
|
|||||||
Str8 s5 = wapp_str8_lit("5");
|
Str8 s5 = wapp_str8_lit("5");
|
||||||
|
|
||||||
Str8List list = {0};
|
Str8List list = {0};
|
||||||
Str8Node n1 = { .string = &s1 };
|
Str8Node n1 = { .item = &s1 };
|
||||||
Str8Node n2 = { .string = &s2 };
|
Str8Node n2 = { .item = &s2 };
|
||||||
Str8Node n3 = { .string = &s3 };
|
Str8Node n3 = { .item = &s3 };
|
||||||
Str8Node n4 = { .string = &s4 };
|
Str8Node n4 = { .item = &s4 };
|
||||||
Str8Node n5 = { .string = &s5 };
|
Str8Node n5 = { .item = &s5 };
|
||||||
|
|
||||||
wapp_str8_list_push_back(&list, &n1);
|
wapp_str8_list_push_back(&list, &n1);
|
||||||
wapp_str8_list_push_back(&list, &n2);
|
wapp_str8_list_push_back(&list, &n2);
|
||||||
@ -24,19 +24,19 @@ TestFuncResult test_str8_list_get(void) {
|
|||||||
wapp_str8_list_push_back(&list, &n5);
|
wapp_str8_list_push_back(&list, &n5);
|
||||||
|
|
||||||
Str8Node *node = wapp_str8_list_get(&list, 0);
|
Str8Node *node = wapp_str8_list_get(&list, 0);
|
||||||
result = node->string == &s1 && wapp_str8_equal(node->string, &s1);
|
result = node->item == &s1 && wapp_str8_equal(node->item, &s1);
|
||||||
|
|
||||||
node = wapp_str8_list_get(&list, 1);
|
node = wapp_str8_list_get(&list, 1);
|
||||||
result = result && node->string == &s2 && wapp_str8_equal(node->string, &s2);
|
result = result && node->item == &s2 && wapp_str8_equal(node->item, &s2);
|
||||||
|
|
||||||
node = wapp_str8_list_get(&list, 2);
|
node = wapp_str8_list_get(&list, 2);
|
||||||
result = result && node->string == &s3 && wapp_str8_equal(node->string, &s3);
|
result = result && node->item == &s3 && wapp_str8_equal(node->item, &s3);
|
||||||
|
|
||||||
node = wapp_str8_list_get(&list, 3);
|
node = wapp_str8_list_get(&list, 3);
|
||||||
result = result && node->string == &s4 && wapp_str8_equal(node->string, &s4);
|
result = result && node->item == &s4 && wapp_str8_equal(node->item, &s4);
|
||||||
|
|
||||||
node = wapp_str8_list_get(&list, 4);
|
node = wapp_str8_list_get(&list, 4);
|
||||||
result = result && node->string == &s5 && wapp_str8_equal(node->string, &s5);
|
result = result && node->item == &s5 && wapp_str8_equal(node->item, &s5);
|
||||||
|
|
||||||
return wapp_tester_result(result);
|
return wapp_tester_result(result);
|
||||||
}
|
}
|
||||||
@ -49,18 +49,18 @@ TestFuncResult test_str8_list_push_front(void) {
|
|||||||
Str8 s3 = wapp_str8_lit("3");
|
Str8 s3 = wapp_str8_lit("3");
|
||||||
|
|
||||||
Str8List list = {0};
|
Str8List list = {0};
|
||||||
Str8Node n1 = { .string = &s1 };
|
Str8Node n1 = { .item = &s1 };
|
||||||
Str8Node n2 = { .string = &s2 };
|
Str8Node n2 = { .item = &s2 };
|
||||||
Str8Node n3 = { .string = &s3 };
|
Str8Node n3 = { .item = &s3 };
|
||||||
|
|
||||||
wapp_str8_list_push_front(&list, &n1);
|
wapp_str8_list_push_front(&list, &n1);
|
||||||
result = list.first == list.last && list.first == &n1 && list.first->string == &s1 && list.total_size == 1 && list.node_count == 1;
|
result = list.first == list.last && list.first == &n1 && list.first->item == &s1 && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1;
|
||||||
|
|
||||||
wapp_str8_list_push_front(&list, &n2);
|
wapp_str8_list_push_front(&list, &n2);
|
||||||
result = result && list.first == &n2 && list.first->string == &s2 && list.total_size == 2 && list.node_count == 2;
|
result = result && list.first == &n2 && list.first->item == &s2 && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2;
|
||||||
|
|
||||||
wapp_str8_list_push_front(&list, &n3);
|
wapp_str8_list_push_front(&list, &n3);
|
||||||
result = result && list.first == &n3 && list.first->string == &s3 && list.total_size == 3 && list.node_count == 3;
|
result = result && list.first == &n3 && list.first->item == &s3 && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3;
|
||||||
|
|
||||||
return wapp_tester_result(result);
|
return wapp_tester_result(result);
|
||||||
}
|
}
|
||||||
@ -73,18 +73,18 @@ TestFuncResult test_str8_list_push_back(void) {
|
|||||||
Str8 s3 = wapp_str8_lit("3");
|
Str8 s3 = wapp_str8_lit("3");
|
||||||
|
|
||||||
Str8List list = {0};
|
Str8List list = {0};
|
||||||
Str8Node n1 = { .string = &s1 };
|
Str8Node n1 = { .item = &s1 };
|
||||||
Str8Node n2 = { .string = &s2 };
|
Str8Node n2 = { .item = &s2 };
|
||||||
Str8Node n3 = { .string = &s3 };
|
Str8Node n3 = { .item = &s3 };
|
||||||
|
|
||||||
wapp_str8_list_push_back(&list, &n1);
|
wapp_str8_list_push_back(&list, &n1);
|
||||||
result = list.first == list.last && list.last == &n1 && list.last->string == &s1 && list.total_size == 1 && list.node_count == 1;
|
result = list.first == list.last && list.last == &n1 && list.last->item == &s1 && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1;
|
||||||
|
|
||||||
wapp_str8_list_push_back(&list, &n2);
|
wapp_str8_list_push_back(&list, &n2);
|
||||||
result = result && list.last == &n2 && list.last->string == &s2 && list.total_size == 2 && list.node_count == 2;
|
result = result && list.last == &n2 && list.last->item == &s2 && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2;
|
||||||
|
|
||||||
wapp_str8_list_push_back(&list, &n3);
|
wapp_str8_list_push_back(&list, &n3);
|
||||||
result = result && list.last == &n3 && list.last->string == &s3 && list.total_size == 3 && list.node_count == 3;
|
result = result && list.last == &n3 && list.last->item == &s3 && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3;
|
||||||
|
|
||||||
return wapp_tester_result(result);
|
return wapp_tester_result(result);
|
||||||
}
|
}
|
||||||
@ -101,13 +101,13 @@ TestFuncResult test_str8_list_insert(void) {
|
|||||||
Str8 s7 = wapp_str8_lit("7");
|
Str8 s7 = wapp_str8_lit("7");
|
||||||
|
|
||||||
Str8List list = {0};
|
Str8List list = {0};
|
||||||
Str8Node n1 = { .string = &s1 };
|
Str8Node n1 = { .item = &s1 };
|
||||||
Str8Node n2 = { .string = &s2 };
|
Str8Node n2 = { .item = &s2 };
|
||||||
Str8Node n3 = { .string = &s3 };
|
Str8Node n3 = { .item = &s3 };
|
||||||
Str8Node n4 = { .string = &s4 };
|
Str8Node n4 = { .item = &s4 };
|
||||||
Str8Node n5 = { .string = &s5 };
|
Str8Node n5 = { .item = &s5 };
|
||||||
Str8Node n6 = { .string = &s6 };
|
Str8Node n6 = { .item = &s6 };
|
||||||
Str8Node n7 = { .string = &s7 };
|
Str8Node n7 = { .item = &s7 };
|
||||||
|
|
||||||
wapp_str8_list_push_back(&list, &n1);
|
wapp_str8_list_push_back(&list, &n1);
|
||||||
wapp_str8_list_push_back(&list, &n2);
|
wapp_str8_list_push_back(&list, &n2);
|
||||||
@ -118,10 +118,10 @@ TestFuncResult test_str8_list_insert(void) {
|
|||||||
Str8Node *node;
|
Str8Node *node;
|
||||||
wapp_str8_list_insert(&list, &n6, 2);
|
wapp_str8_list_insert(&list, &n6, 2);
|
||||||
node = wapp_str8_list_get(&list, 2);
|
node = wapp_str8_list_get(&list, 2);
|
||||||
result = node != NULL && node->string == &s6 && list.total_size == 6 && list.node_count == 6;
|
result = node != NULL && node->item == &s6 && wapp_str8_list_total_size(&list) == 6 && list.node_count == 6;
|
||||||
wapp_str8_list_insert(&list, &n7, 5);
|
wapp_str8_list_insert(&list, &n7, 5);
|
||||||
node = wapp_str8_list_get(&list, 5);
|
node = wapp_str8_list_get(&list, 5);
|
||||||
result = result && node != NULL && node->string == &s7 && list.total_size == 7 && list.node_count == 7;
|
result = result && node != NULL && node->item == &s7 && wapp_str8_list_total_size(&list) == 7 && list.node_count == 7;
|
||||||
|
|
||||||
return wapp_tester_result(result);
|
return wapp_tester_result(result);
|
||||||
}
|
}
|
||||||
@ -136,11 +136,11 @@ TestFuncResult test_str8_list_pop_front(void) {
|
|||||||
Str8 s5 = wapp_str8_lit("5");
|
Str8 s5 = wapp_str8_lit("5");
|
||||||
|
|
||||||
Str8List list = {0};
|
Str8List list = {0};
|
||||||
Str8Node n1 = { .string = &s1 };
|
Str8Node n1 = { .item = &s1 };
|
||||||
Str8Node n2 = { .string = &s2 };
|
Str8Node n2 = { .item = &s2 };
|
||||||
Str8Node n3 = { .string = &s3 };
|
Str8Node n3 = { .item = &s3 };
|
||||||
Str8Node n4 = { .string = &s4 };
|
Str8Node n4 = { .item = &s4 };
|
||||||
Str8Node n5 = { .string = &s5 };
|
Str8Node n5 = { .item = &s5 };
|
||||||
|
|
||||||
wapp_str8_list_push_back(&list, &n1);
|
wapp_str8_list_push_back(&list, &n1);
|
||||||
wapp_str8_list_push_back(&list, &n2);
|
wapp_str8_list_push_back(&list, &n2);
|
||||||
@ -149,19 +149,19 @@ TestFuncResult test_str8_list_pop_front(void) {
|
|||||||
wapp_str8_list_push_back(&list, &n5);
|
wapp_str8_list_push_back(&list, &n5);
|
||||||
|
|
||||||
Str8Node *node = wapp_str8_list_pop_front(&list);
|
Str8Node *node = wapp_str8_list_pop_front(&list);
|
||||||
result = node == &n1 && node->string == &s1 && wapp_str8_equal(node->string, &s1) && list.total_size == 4 && list.node_count == 4;
|
result = node == &n1 && node->item == &s1 && wapp_str8_equal(node->item, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4;
|
||||||
|
|
||||||
node = wapp_str8_list_pop_front(&list);
|
node = wapp_str8_list_pop_front(&list);
|
||||||
result = result && node == &n2 && node->string == &s2 && wapp_str8_equal(node->string, &s2) && list.total_size == 3 && list.node_count == 3;
|
result = result && node == &n2 && node->item == &s2 && wapp_str8_equal(node->item, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3;
|
||||||
|
|
||||||
node = wapp_str8_list_pop_front(&list);
|
node = wapp_str8_list_pop_front(&list);
|
||||||
result = result && node == &n3 && node->string == &s3 && wapp_str8_equal(node->string, &s3) && list.total_size == 2 && list.node_count == 2;
|
result = result && node == &n3 && node->item == &s3 && wapp_str8_equal(node->item, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2;
|
||||||
|
|
||||||
node = wapp_str8_list_pop_front(&list);
|
node = wapp_str8_list_pop_front(&list);
|
||||||
result = result && node == &n4 && node->string == &s4 && wapp_str8_equal(node->string, &s4) && list.total_size == 1 && list.node_count == 1;
|
result = result && node == &n4 && node->item == &s4 && wapp_str8_equal(node->item, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1;
|
||||||
|
|
||||||
node = wapp_str8_list_pop_front(&list);
|
node = wapp_str8_list_pop_front(&list);
|
||||||
result = result && node == &n5 && node->string == &s5 && wapp_str8_equal(node->string, &s5) && list.total_size == 0 && list.node_count == 0;
|
result = result && node == &n5 && node->item == &s5 && wapp_str8_equal(node->item, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0;
|
||||||
|
|
||||||
return wapp_tester_result(result);
|
return wapp_tester_result(result);
|
||||||
}
|
}
|
||||||
@ -176,11 +176,11 @@ TestFuncResult test_str8_list_pop_back(void) {
|
|||||||
Str8 s5 = wapp_str8_lit("5");
|
Str8 s5 = wapp_str8_lit("5");
|
||||||
|
|
||||||
Str8List list = {0};
|
Str8List list = {0};
|
||||||
Str8Node n1 = { .string = &s1 };
|
Str8Node n1 = { .item = &s1 };
|
||||||
Str8Node n2 = { .string = &s2 };
|
Str8Node n2 = { .item = &s2 };
|
||||||
Str8Node n3 = { .string = &s3 };
|
Str8Node n3 = { .item = &s3 };
|
||||||
Str8Node n4 = { .string = &s4 };
|
Str8Node n4 = { .item = &s4 };
|
||||||
Str8Node n5 = { .string = &s5 };
|
Str8Node n5 = { .item = &s5 };
|
||||||
|
|
||||||
wapp_str8_list_push_front(&list, &n1);
|
wapp_str8_list_push_front(&list, &n1);
|
||||||
wapp_str8_list_push_front(&list, &n2);
|
wapp_str8_list_push_front(&list, &n2);
|
||||||
@ -189,19 +189,19 @@ TestFuncResult test_str8_list_pop_back(void) {
|
|||||||
wapp_str8_list_push_front(&list, &n5);
|
wapp_str8_list_push_front(&list, &n5);
|
||||||
|
|
||||||
Str8Node *node = wapp_str8_list_pop_back(&list);
|
Str8Node *node = wapp_str8_list_pop_back(&list);
|
||||||
result = node == &n1 && node->string == &s1 && wapp_str8_equal(node->string, &s1) && list.total_size == 4 && list.node_count == 4;
|
result = node == &n1 && node->item == &s1 && wapp_str8_equal(node->item, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4;
|
||||||
|
|
||||||
node = wapp_str8_list_pop_back(&list);
|
node = wapp_str8_list_pop_back(&list);
|
||||||
result = result && node == &n2 && node->string == &s2 && wapp_str8_equal(node->string, &s2) && list.total_size == 3 && list.node_count == 3;
|
result = result && node == &n2 && node->item == &s2 && wapp_str8_equal(node->item, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3;
|
||||||
|
|
||||||
node = wapp_str8_list_pop_back(&list);
|
node = wapp_str8_list_pop_back(&list);
|
||||||
result = result && node == &n3 && node->string == &s3 && wapp_str8_equal(node->string, &s3) && list.total_size == 2 && list.node_count == 2;
|
result = result && node == &n3 && node->item == &s3 && wapp_str8_equal(node->item, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2;
|
||||||
|
|
||||||
node = wapp_str8_list_pop_back(&list);
|
node = wapp_str8_list_pop_back(&list);
|
||||||
result = result && node == &n4 && node->string == &s4 && wapp_str8_equal(node->string, &s4) && list.total_size == 1 && list.node_count == 1;
|
result = result && node == &n4 && node->item == &s4 && wapp_str8_equal(node->item, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1;
|
||||||
|
|
||||||
node = wapp_str8_list_pop_back(&list);
|
node = wapp_str8_list_pop_back(&list);
|
||||||
result = result && node == &n5 && node->string == &s5 && wapp_str8_equal(node->string, &s5) && list.total_size == 0 && list.node_count == 0;
|
result = result && node == &n5 && node->item == &s5 && wapp_str8_equal(node->item, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0;
|
||||||
|
|
||||||
return wapp_tester_result(result);
|
return wapp_tester_result(result);
|
||||||
}
|
}
|
||||||
@ -216,11 +216,11 @@ TestFuncResult test_str8_list_remove(void) {
|
|||||||
Str8 s5 = wapp_str8_lit("5");
|
Str8 s5 = wapp_str8_lit("5");
|
||||||
|
|
||||||
Str8List list = {0};
|
Str8List list = {0};
|
||||||
Str8Node n1 = { .string = &s1 };
|
Str8Node n1 = { .item = &s1 };
|
||||||
Str8Node n2 = { .string = &s2 };
|
Str8Node n2 = { .item = &s2 };
|
||||||
Str8Node n3 = { .string = &s3 };
|
Str8Node n3 = { .item = &s3 };
|
||||||
Str8Node n4 = { .string = &s4 };
|
Str8Node n4 = { .item = &s4 };
|
||||||
Str8Node n5 = { .string = &s5 };
|
Str8Node n5 = { .item = &s5 };
|
||||||
|
|
||||||
wapp_str8_list_push_back(&list, &n1);
|
wapp_str8_list_push_back(&list, &n1);
|
||||||
wapp_str8_list_push_back(&list, &n2);
|
wapp_str8_list_push_back(&list, &n2);
|
||||||
@ -229,19 +229,19 @@ TestFuncResult test_str8_list_remove(void) {
|
|||||||
wapp_str8_list_push_back(&list, &n5);
|
wapp_str8_list_push_back(&list, &n5);
|
||||||
|
|
||||||
Str8Node *node = wapp_str8_list_remove(&list, 0);
|
Str8Node *node = wapp_str8_list_remove(&list, 0);
|
||||||
result = node == &n1 && node->string == &s1 && wapp_str8_equal(node->string, &s1) && list.total_size == 4 && list.node_count == 4;
|
result = node == &n1 && node->item == &s1 && wapp_str8_equal(node->item, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4;
|
||||||
|
|
||||||
node = wapp_str8_list_remove(&list, 0);
|
node = wapp_str8_list_remove(&list, 0);
|
||||||
result = result && node == &n2 && node->string == &s2 && wapp_str8_equal(node->string, &s2) && list.total_size == 3 && list.node_count == 3;
|
result = result && node == &n2 && node->item == &s2 && wapp_str8_equal(node->item, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3;
|
||||||
|
|
||||||
node = wapp_str8_list_remove(&list, 0);
|
node = wapp_str8_list_remove(&list, 0);
|
||||||
result = result && node == &n3 && node->string == &s3 && wapp_str8_equal(node->string, &s3) && list.total_size == 2 && list.node_count == 2;
|
result = result && node == &n3 && node->item == &s3 && wapp_str8_equal(node->item, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2;
|
||||||
|
|
||||||
node = wapp_str8_list_remove(&list, 0);
|
node = wapp_str8_list_remove(&list, 0);
|
||||||
result = result && node == &n4 && node->string == &s4 && wapp_str8_equal(node->string, &s4) && list.total_size == 1 && list.node_count == 1;
|
result = result && node == &n4 && node->item == &s4 && wapp_str8_equal(node->item, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1;
|
||||||
|
|
||||||
node = wapp_str8_list_remove(&list, 0);
|
node = wapp_str8_list_remove(&list, 0);
|
||||||
result = result && node == &n5 && node->string == &s5 && wapp_str8_equal(node->string, &s5) && list.total_size == 0 && list.node_count == 0;
|
result = result && node == &n5 && node->item == &s5 && wapp_str8_equal(node->item, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0;
|
||||||
|
|
||||||
return wapp_tester_result(result);
|
return wapp_tester_result(result);
|
||||||
}
|
}
|
||||||
@ -257,7 +257,7 @@ TestFuncResult test_str8_list_empty(void) {
|
|||||||
|
|
||||||
wapp_str8_list_empty(&list);
|
wapp_str8_list_empty(&list);
|
||||||
|
|
||||||
result = list.first == NULL && list.last == NULL && list.node_count == 0 && list.total_size == 0;
|
result = list.first == NULL && list.last == NULL && list.node_count == 0 && wapp_str8_list_total_size(&list) == 0;
|
||||||
|
|
||||||
return wapp_tester_result(result);
|
return wapp_tester_result(result);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user