version 1.49, 2020/08/28 04:28:45 |
version 1.50, 2020/08/28 04:48:57 |
|
|
* If copyProc is given, that function is used to create the new datum from the |
* If copyProc is given, that function is used to create the new datum from the |
* old datum, usually by creating a copy of it. */ |
* old datum, usually by creating a copy of it. */ |
Lst |
Lst |
Lst_CopyS(Lst list, LstCopyProc copyProc) |
Lst_Copy(Lst list, LstCopyProc copyProc) |
{ |
{ |
Lst newList; |
Lst newList; |
LstNode node; |
LstNode node; |
Line 136 Lst_CopyS(Lst list, LstCopyProc copyProc |
|
Line 136 Lst_CopyS(Lst list, LstCopyProc copyProc |
|
|
|
for (node = list->first; node != NULL; node = node->next) { |
for (node = list->first; node != NULL; node = node->next) { |
void *datum = copyProc != NULL ? copyProc(node->datum) : node->datum; |
void *datum = copyProc != NULL ? copyProc(node->datum) : node->datum; |
Lst_AppendS(newList, datum); |
Lst_Append(newList, datum); |
} |
} |
|
|
return newList; |
return newList; |
Line 144 Lst_CopyS(Lst list, LstCopyProc copyProc |
|
Line 144 Lst_CopyS(Lst list, LstCopyProc copyProc |
|
|
|
/* Free a list and all its nodes. The list data itself are not freed though. */ |
/* Free a list and all its nodes. The list data itself are not freed though. */ |
void |
void |
Lst_FreeS(Lst list) |
Lst_Free(Lst list) |
{ |
{ |
LstNode node; |
LstNode node; |
LstNode next; |
LstNode next; |
Line 162 Lst_FreeS(Lst list) |
|
Line 162 Lst_FreeS(Lst list) |
|
/* Destroy a list and free all its resources. If the freeProc is given, it is |
/* Destroy a list and free all its resources. If the freeProc is given, it is |
* called with the datum from each node in turn before the node is freed. */ |
* called with the datum from each node in turn before the node is freed. */ |
void |
void |
Lst_DestroyS(Lst list, LstFreeProc freeProc) |
Lst_Destroy(Lst list, LstFreeProc freeProc) |
{ |
{ |
LstNode node; |
LstNode node; |
LstNode next; |
LstNode next; |
Line 186 Lst_DestroyS(Lst list, LstFreeProc freeP |
|
Line 186 Lst_DestroyS(Lst list, LstFreeProc freeP |
|
/* Insert a new node with the given piece of data before the given node in the |
/* Insert a new node with the given piece of data before the given node in the |
* given list. */ |
* given list. */ |
void |
void |
Lst_InsertBeforeS(Lst list, LstNode node, void *datum) |
Lst_InsertBefore(Lst list, LstNode node, void *datum) |
{ |
{ |
LstNode newNode; |
LstNode newNode; |
|
|
Line 211 Lst_InsertBeforeS(Lst list, LstNode node |
|
Line 211 Lst_InsertBeforeS(Lst list, LstNode node |
|
|
|
/* Add a piece of data at the start of the given list. */ |
/* Add a piece of data at the start of the given list. */ |
void |
void |
Lst_PrependS(Lst list, void *datum) |
Lst_Prepend(Lst list, void *datum) |
{ |
{ |
LstNode node; |
LstNode node; |
|
|
Line 233 Lst_PrependS(Lst list, void *datum) |
|
Line 233 Lst_PrependS(Lst list, void *datum) |
|
|
|
/* Add a piece of data at the end of the given list. */ |
/* Add a piece of data at the end of the given list. */ |
void |
void |
Lst_AppendS(Lst list, void *datum) |
Lst_Append(Lst list, void *datum) |
{ |
{ |
LstNode node; |
LstNode node; |
|
|
Line 256 Lst_AppendS(Lst list, void *datum) |
|
Line 256 Lst_AppendS(Lst list, void *datum) |
|
/* Remove the given node from the given list. |
/* Remove the given node from the given list. |
* The datum stored in the node must be freed by the caller, if necessary. */ |
* The datum stored in the node must be freed by the caller, if necessary. */ |
void |
void |
Lst_RemoveS(Lst list, LstNode node) |
Lst_Remove(Lst list, LstNode node) |
{ |
{ |
assert(LstIsValid(list)); |
assert(LstIsValid(list)); |
assert(LstNodeIsValid(node)); |
assert(LstNodeIsValid(node)); |
Line 308 Lst_RemoveS(Lst list, LstNode node) |
|
Line 308 Lst_RemoveS(Lst list, LstNode node) |
|
|
|
/* Replace the datum in the given node with the new datum. */ |
/* Replace the datum in the given node with the new datum. */ |
void |
void |
LstNode_SetS(LstNode node, void *datum) |
LstNode_Set(LstNode node, void *datum) |
{ |
{ |
assert(LstNodeIsValid(node)); |
assert(LstNodeIsValid(node)); |
assert(datum != NULL); |
assert(datum != NULL); |
Line 318 LstNode_SetS(LstNode node, void *datum) |
|
Line 318 LstNode_SetS(LstNode node, void *datum) |
|
|
|
/* Replace the datum in the given node to NULL. */ |
/* Replace the datum in the given node to NULL. */ |
void |
void |
LstNode_SetNullS(LstNode node) |
LstNode_SetNull(LstNode node) |
{ |
{ |
assert(LstNodeIsValid(node)); |
assert(LstNodeIsValid(node)); |
|
|
Line 332 LstNode_SetNullS(LstNode node) |
|
Line 332 LstNode_SetNullS(LstNode node) |
|
|
|
/* Return the first node from the given list, or NULL if the list is empty. */ |
/* Return the first node from the given list, or NULL if the list is empty. */ |
LstNode |
LstNode |
Lst_FirstS(Lst list) |
Lst_First(Lst list) |
{ |
{ |
assert(LstIsValid(list)); |
assert(LstIsValid(list)); |
|
|
Line 341 Lst_FirstS(Lst list) |
|
Line 341 Lst_FirstS(Lst list) |
|
|
|
/* Return the last node from the given list, or NULL if the list is empty. */ |
/* Return the last node from the given list, or NULL if the list is empty. */ |
LstNode |
LstNode |
Lst_LastS(Lst list) |
Lst_Last(Lst list) |
{ |
{ |
assert(LstIsValid(list)); |
assert(LstIsValid(list)); |
|
|
Line 350 Lst_LastS(Lst list) |
|
Line 350 Lst_LastS(Lst list) |
|
|
|
/* Return the successor to the given node on its list, or NULL. */ |
/* Return the successor to the given node on its list, or NULL. */ |
LstNode |
LstNode |
Lst_SuccS(LstNode node) |
Lst_Succ(LstNode node) |
{ |
{ |
assert(LstNodeIsValid(node)); |
assert(LstNodeIsValid(node)); |
|
|
Line 359 Lst_SuccS(LstNode node) |
|
Line 359 Lst_SuccS(LstNode node) |
|
|
|
/* Return the predecessor to the given node on its list, or NULL. */ |
/* Return the predecessor to the given node on its list, or NULL. */ |
LstNode |
LstNode |
Lst_PrevS(LstNode node) |
Lst_Prev(LstNode node) |
{ |
{ |
assert(LstNodeIsValid(node)); |
assert(LstNodeIsValid(node)); |
return node->prev; |
return node->prev; |
Line 367 Lst_PrevS(LstNode node) |
|
Line 367 Lst_PrevS(LstNode node) |
|
|
|
/* Return the datum stored in the given node. */ |
/* Return the datum stored in the given node. */ |
void * |
void * |
Lst_DatumS(LstNode node) |
Lst_Datum(LstNode node) |
{ |
{ |
assert(LstNodeIsValid(node)); |
assert(LstNodeIsValid(node)); |
return node->datum; |
return node->datum; |
Line 380 Lst_DatumS(LstNode node) |
|
Line 380 Lst_DatumS(LstNode node) |
|
|
|
/* Return TRUE if the given list is empty. */ |
/* Return TRUE if the given list is empty. */ |
Boolean |
Boolean |
Lst_IsEmptyS(Lst list) |
Lst_IsEmpty(Lst list) |
{ |
{ |
assert(LstIsValid(list)); |
assert(LstIsValid(list)); |
|
|
Line 390 Lst_IsEmptyS(Lst list) |
|
Line 390 Lst_IsEmptyS(Lst list) |
|
/* Return the first node from the given list for which the given comparison |
/* Return the first node from the given list for which the given comparison |
* function returns 0, or NULL if none of the nodes matches. */ |
* function returns 0, or NULL if none of the nodes matches. */ |
LstNode |
LstNode |
Lst_FindS(Lst list, LstFindProc cmp, const void *cmpData) |
Lst_Find(Lst list, LstFindProc cmp, const void *cmpData) |
{ |
{ |
if (LstIsEmpty(list)) |
if (LstIsEmpty(list)) |
return NULL; |
return NULL; |
return Lst_FindFromS(list, Lst_FirstS(list), cmp, cmpData); |
return Lst_FindFrom(list, Lst_First(list), cmp, cmpData); |
} |
} |
|
|
/* Return the first node from the given list, starting at the given node, for |
/* Return the first node from the given list, starting at the given node, for |
* which the given comparison function returns 0, or NULL if none of the nodes |
* which the given comparison function returns 0, or NULL if none of the nodes |
* matches. */ |
* matches. */ |
LstNode |
LstNode |
Lst_FindFromS(Lst list, LstNode node, LstFindProc cmp, const void *cmpData) |
Lst_FindFrom(Lst list, LstNode node, LstFindProc cmp, const void *cmpData) |
{ |
{ |
LstNode tln; |
LstNode tln; |
|
|
Line 419 Lst_FindFromS(Lst list, LstNode node, Ls |
|
Line 419 Lst_FindFromS(Lst list, LstNode node, Ls |
|
|
|
/* Return the first node that contains the given datum, or NULL. */ |
/* Return the first node that contains the given datum, or NULL. */ |
LstNode |
LstNode |
Lst_MemberS(Lst list, void *datum) |
Lst_Member(Lst list, void *datum) |
{ |
{ |
LstNode node; |
LstNode node; |
|
|
Line 439 Lst_MemberS(Lst list, void *datum) |
|
Line 439 Lst_MemberS(Lst list, void *datum) |
|
* should return 0 if traversal should continue and non-zero if it should |
* should return 0 if traversal should continue and non-zero if it should |
* abort. */ |
* abort. */ |
int |
int |
Lst_ForEachS(Lst list, LstActionProc proc, void *procData) |
Lst_ForEach(Lst list, LstActionProc proc, void *procData) |
{ |
{ |
if (LstIsEmpty(list)) |
if (LstIsEmpty(list)) |
return 0; /* XXX: Document what this value means. */ |
return 0; /* XXX: Document what this value means. */ |
return Lst_ForEachFromS(list, Lst_FirstS(list), proc, procData); |
return Lst_ForEachFrom(list, Lst_First(list), proc, procData); |
} |
} |
|
|
/* Apply the given function to each element of the given list, starting from |
/* Apply the given function to each element of the given list, starting from |
* the given node. The function should return 0 if traversal should continue, |
* the given node. The function should return 0 if traversal should continue, |
* and non-zero if it should abort. */ |
* and non-zero if it should abort. */ |
int |
int |
Lst_ForEachFromS(Lst list, LstNode node, |
Lst_ForEachFrom(Lst list, LstNode node, |
LstActionProc proc, void *procData) |
LstActionProc proc, void *procData) |
{ |
{ |
LstNode tln = node; |
LstNode tln = node; |
Line 504 Lst_ForEachFromS(Lst list, LstNode node, |
|
Line 504 Lst_ForEachFromS(Lst list, LstNode node, |
|
/* Move all nodes from list2 to the end of list1. |
/* Move all nodes from list2 to the end of list1. |
* List2 is destroyed and freed. */ |
* List2 is destroyed and freed. */ |
void |
void |
Lst_MoveAllS(Lst list1, Lst list2) |
Lst_MoveAll(Lst list1, Lst list2) |
{ |
{ |
assert(LstIsValid(list1)); |
assert(LstIsValid(list1)); |
assert(LstIsValid(list2)); |
assert(LstIsValid(list2)); |
Line 523 Lst_MoveAllS(Lst list1, Lst list2) |
|
Line 523 Lst_MoveAllS(Lst list1, Lst list2) |
|
|
|
/* Copy the element data from src to the start of dst. */ |
/* Copy the element data from src to the start of dst. */ |
void |
void |
Lst_PrependAllS(Lst dst, Lst src) |
Lst_PrependAll(Lst dst, Lst src) |
{ |
{ |
LstNode node; |
LstNode node; |
for (node = src->last; node != NULL; node = node->prev) |
for (node = src->last; node != NULL; node = node->prev) |
Lst_PrependS(dst, node->datum); |
Lst_Prepend(dst, node->datum); |
} |
} |
|
|
/* Copy the element data from src to the end of dst. */ |
/* Copy the element data from src to the end of dst. */ |
void |
void |
Lst_AppendAllS(Lst dst, Lst src) |
Lst_AppendAll(Lst dst, Lst src) |
{ |
{ |
LstNode node; |
LstNode node; |
for (node = src->first; node != NULL; node = node->next) |
for (node = src->first; node != NULL; node = node->next) |
Lst_AppendS(dst, node->datum); |
Lst_Append(dst, node->datum); |
} |
} |
|
|
/* |
/* |
Line 552 Lst_AppendAllS(Lst dst, Lst src) |
|
Line 552 Lst_AppendAllS(Lst dst, Lst src) |
|
/* Open a list for sequential access. A list can still be searched, etc., |
/* Open a list for sequential access. A list can still be searched, etc., |
* without confusing these functions. */ |
* without confusing these functions. */ |
void |
void |
Lst_OpenS(Lst list) |
Lst_Open(Lst list) |
{ |
{ |
assert(LstIsValid(list)); |
assert(LstIsValid(list)); |
|
|
Line 570 Lst_OpenS(Lst list) |
|
Line 570 Lst_OpenS(Lst list) |
|
/* Return the next node for the given list, or NULL if the end has been |
/* Return the next node for the given list, or NULL if the end has been |
* reached. */ |
* reached. */ |
LstNode |
LstNode |
Lst_NextS(Lst list) |
Lst_Next(Lst list) |
{ |
{ |
LstNode node; |
LstNode node; |
|
|
Line 614 Lst_NextS(Lst list) |
|
Line 614 Lst_NextS(Lst list) |
|
|
|
/* Close a list which was opened for sequential access. */ |
/* Close a list which was opened for sequential access. */ |
void |
void |
Lst_CloseS(Lst list) |
Lst_Close(Lst list) |
{ |
{ |
assert(LstIsValid(list)); |
assert(LstIsValid(list)); |
assert(list->isOpen); |
assert(list->isOpen); |
Line 630 Lst_CloseS(Lst list) |
|
Line 630 Lst_CloseS(Lst list) |
|
|
|
/* Add the datum to the tail of the given list. */ |
/* Add the datum to the tail of the given list. */ |
void |
void |
Lst_EnqueueS(Lst list, void *datum) |
Lst_Enqueue(Lst list, void *datum) |
{ |
{ |
Lst_AppendS(list, datum); |
Lst_Append(list, datum); |
} |
} |
|
|
/* Remove and return the datum at the head of the given list. */ |
/* Remove and return the datum at the head of the given list. */ |
void * |
void * |
Lst_DequeueS(Lst list) |
Lst_Dequeue(Lst list) |
{ |
{ |
void *datum; |
void *datum; |
|
|
Line 645 Lst_DequeueS(Lst list) |
|
Line 645 Lst_DequeueS(Lst list) |
|
assert(!LstIsEmpty(list)); |
assert(!LstIsEmpty(list)); |
|
|
datum = list->first->datum; |
datum = list->first->datum; |
Lst_RemoveS(list, list->first); |
Lst_Remove(list, list->first); |
assert(datum != NULL); |
assert(datum != NULL); |
return datum; |
return datum; |
} |
} |