Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of azure_c_shared_utility by
doublylinkedlist.c
00001 // Copyright (c) Microsoft. All rights reserved. 00002 // Licensed under the MIT license. See LICENSE file in the project root for full license information. 00003 00004 #include "azure_c_shared_utility/doublylinkedlist.h" 00005 00006 void 00007 DList_InitializeListHead( 00008 PDLIST_ENTRY ListHead 00009 ) 00010 { 00011 /* Codes_SRS_DLIST_06_005: [DList_InitializeListHead will initialize the Flink & Blink to the address of the DLIST_ENTRY.] */ 00012 ListHead->Flink = ListHead->Blink = ListHead; 00013 return; 00014 } 00015 00016 int 00017 DList_IsListEmpty( 00018 const PDLIST_ENTRY ListHead 00019 ) 00020 { 00021 /* Codes_SRS_DLIST_06_003: [DList_IsListEmpty shall return a non-zero value if there are no DLIST_ENTRY's on this list other than the list head.] */ 00022 /* Codes_SRS_DLIST_06_004: [DList_IsListEmpty shall return 0 if there is one or more items in the list.] */ 00023 return (ListHead->Flink == ListHead); 00024 } 00025 00026 int 00027 DList_RemoveEntryList( 00028 PDLIST_ENTRY Entry 00029 ) 00030 { 00031 /* Codes_SRS_DLIST_06_008: [DList_RemoveEntryList shall remove a listEntry from whatever list it is properly part of.] */ 00032 /* Codes_SRS_DLIST_06_009: [The remaining list is properly formed.] */ 00033 /* Codes_SRS_DLIST_06_010: [DList_RemoveEntryList shall return non-zero if the remaining list is empty.] */ 00034 /* Codes_SRS_DLIST_06_011: [DList_RemoveEntryList shall return zero if the remaining list is NOT empty.] */ 00035 PDLIST_ENTRY Blink; 00036 PDLIST_ENTRY Flink; 00037 00038 Flink = Entry->Flink; 00039 Blink = Entry->Blink; 00040 Blink->Flink = Flink; 00041 Flink->Blink = Blink; 00042 return (Flink == Blink); 00043 } 00044 00045 PDLIST_ENTRY 00046 DList_RemoveHeadList( 00047 PDLIST_ENTRY ListHead 00048 ) 00049 { 00050 /* Codes_SRS_DLIST_06_012: [DList_RemoveHeadList removes the oldest entry from the list defined by the listHead parameter and returns a pointer to that entry.] */ 00051 /* Codes_SRS_DLIST_06_013: [DList_RemoveHeadList shall return listHead if that's the only item in the list.] */ 00052 00053 PDLIST_ENTRY Flink; 00054 PDLIST_ENTRY Entry; 00055 00056 Entry = ListHead->Flink; 00057 Flink = Entry->Flink; 00058 ListHead->Flink = Flink; 00059 Flink->Blink = ListHead; 00060 return Entry; 00061 } 00062 00063 00064 00065 void 00066 DList_InsertTailList( 00067 PDLIST_ENTRY ListHead, 00068 PDLIST_ENTRY Entry 00069 ) 00070 { 00071 PDLIST_ENTRY Blink; 00072 00073 /* Codes_SRS_DLIST_06_006: [DListInsertTailList shall place the DLIST_ENTRY at the end of the list defined by the listHead parameter.] */ 00074 Blink = ListHead->Blink; 00075 Entry->Flink = ListHead; 00076 Entry->Blink = Blink; 00077 Blink->Flink = Entry; 00078 ListHead->Blink = Entry; 00079 return; 00080 } 00081 00082 00083 void 00084 DList_AppendTailList( 00085 PDLIST_ENTRY ListHead, 00086 PDLIST_ENTRY ListToAppend 00087 ) 00088 { 00089 /* Codes_SRS_DLIST_06_007: [DList_AppendTailList shall place the list defined by listToAppend at the end of the list defined by the listHead parameter.] */ 00090 PDLIST_ENTRY ListEnd = ListHead->Blink; 00091 00092 ListHead->Blink->Flink = ListToAppend; 00093 ListHead->Blink = ListToAppend->Blink; 00094 ListToAppend->Blink->Flink = ListHead; 00095 ListToAppend->Blink = ListEnd; 00096 return; 00097 } 00098 00099 00100 /*Codes_SRS_DLIST_02_002: [DList_InsertHeadList inserts a singular entry in the list having as head listHead after "head".]*/ 00101 void DList_InsertHeadList(PDLIST_ENTRY listHead, PDLIST_ENTRY entry) 00102 { 00103 entry->Blink = listHead; 00104 entry->Flink = listHead->Flink; 00105 listHead->Flink->Blink = entry; 00106 listHead->Flink = entry; 00107 }
Generated on Tue Jul 12 2022 19:14:38 by
