6#define GET_OBJ_NODE(list, obj) ((Link*)(((u32)(obj)) + (list)->mOffset))
8void List_Init(List *list, u16 offset) {
9 list->mpHead =
nullptr;
10 list->mpTail =
nullptr;
12 list->mOffset = offset;
15void List_Append(List *list,
void *obj) {
18 if (list->mpHead ==
nullptr) {
19 Link *node = GET_OBJ_NODE(list, obj);
20 node->mpNext =
nullptr;
21 node->mpPrev =
nullptr;
27 Link *node = GET_OBJ_NODE(list, obj);
28 node->mpPrev = list->mpTail;
29 node->mpNext =
nullptr;
32 GET_OBJ_NODE(list, list->mpTail)->mpNext = obj;
40void List_Remove(List *list,
void *obj) {
41 Link *node = GET_OBJ_NODE(list, obj);
45 if (node->mpPrev ==
nullptr) {
46 list->mpHead = node->mpNext;
48 GET_OBJ_NODE(list, node->mpPrev)->mpNext = node->mpNext;
53 if (node->mpNext ==
nullptr) {
54 list->mpTail = node->mpPrev;
56 GET_OBJ_NODE(list, node->mpNext)->mpPrev = node->mpPrev;
60 node->mpPrev =
nullptr;
61 node->mpNext =
nullptr;
67void *List_GetNext(
const List *list,
const void *obj) {
72 return GET_OBJ_NODE(list, obj)->mpNext;
75void *List_GetNth(
const List *list, u16 n) {
79 for (i = 0, node =
nullptr; node = List_GetNext(list, node); i++) {