1 /********************************************************************/
2 /* STRIPE: converting a polygonal model to triangle strips
5 Advisors: Steven Skiena and Amitabh Varshney
7 /********************************************************************/
9 /*---------------------------------------------------------------------*/
11 This file contains the routines used in the data structures lists, which
14 /*---------------------------------------------------------------------*/
20 /*----------------------------------------------------------------------------
23 BOOL InitList (PLISTHEAD LHead)
26 if (LHead == NULL) return(FALSE);
28 LHead->LHeaders[LISTHEAD] = LHead->LHeaders[LISTTAIL] = NULL;
33 /*----------------------------------------------------------------------------
36 BOOL AddHead(PLISTHEAD LHead, PLISTINFO LInfo)
38 if (LHead == NULL || LInfo == NULL)
41 LHead->LHeaders[LISTTAIL] = LInfo;
42 else LHead->LHeaders[LISTHEAD]->ListNode.Previous = (void *) LInfo;
44 LInfo->ListNode.Next = (void *) LHead->LHeaders[LISTHEAD];
45 LHead->LHeaders[LISTHEAD] = LInfo;
46 LInfo->ListNode.Previous = NULL;
51 /*----------------------------------------------------------------------------
54 BOOL AddTail(PLISTHEAD LHead, PLISTINFO LInfo)
56 if (LHead == NULL || LInfo == NULL)
59 LHead->LHeaders[LISTHEAD] = LInfo;
60 else LHead->LHeaders[LISTTAIL]->ListNode.Next = (void *) LInfo;
62 LInfo->ListNode.Previous = (void *) LHead->LHeaders[LISTTAIL];
63 LHead->LHeaders[LISTTAIL] = LInfo;
64 LInfo->ListNode.Next = NULL;
70 BOOL InsertNode( PLISTHEAD LHead, int nPos, PLISTINFO LInfo )
74 if ( LHead == NULL || LInfo == NULL || nPos > NumOnList( LHead ) )
78 AddHead( LHead, LInfo );
79 else if ( nPos == NumOnList( LHead ) )
80 AddTail( LHead, LInfo );
83 if ( (LAddNode = PeekList( LHead, LISTHEAD, nPos - 1 )) == NULL )
86 ((PLISTINFO)LAddNode->ListNode.Next)->ListNode.Previous = LInfo;
87 LInfo->ListNode.Next = LAddNode->ListNode.Next;
88 LInfo->ListNode.Previous = LAddNode;
89 LAddNode->ListNode.Next = LInfo;
100 /*----------------------------------------------------------------------------
103 PLISTINFO RemHead(PLISTHEAD LHead)
107 if ( LHead == NULL || EMPTYLIST(LHead) )
110 t = LHead->LHeaders[LISTHEAD];
111 LHead->LHeaders[LISTHEAD] = (PLISTINFO) t->ListNode.Next;
113 if (LHead->LHeaders[LISTHEAD] != NULL)
115 t1 = (PLISTINFO) t->ListNode.Next;
116 t1->ListNode.Previous = NULL;
119 LHead->LHeaders[LISTTAIL] = NULL;
126 /*----------------------------------------------------------------------------
129 PLISTINFO RemTail(PLISTHEAD LHead)
133 if ( LHead == NULL || EMPTYLIST(LHead) )
136 t = LHead->LHeaders[LISTTAIL];
137 LHead->LHeaders[LISTTAIL] = (PLISTINFO) t->ListNode.Previous;
138 if (LHead->LHeaders[LISTTAIL] != NULL)
140 t1 = (PLISTINFO) t->ListNode.Previous;
141 t1->ListNode.Next = NULL;
144 LHead->LHeaders[LISTHEAD] = NULL;
150 /*----------------------------------------------------------------------------
153 PLISTINFO PeekList(PLISTHEAD LHead, int wch, int index )
159 if ( (t = LHead->LHeaders[wch]) == NULL )
162 for (; t != NULL && index > 0; index-- )
163 t = (wch == LISTHEAD) ? (PLISTINFO) t->ListNode.Next :
164 (PLISTINFO) t->ListNode.Previous;
169 /*----------------------------------------------------------------------------
172 PLISTINFO RemoveList( PLISTHEAD LHead, PLISTINFO LInfo )
179 if (LHead->LHeaders[LISTHEAD] == t)
180 t = (PLISTINFO) RemHead(LHead);
181 else if (LHead->LHeaders[LISTTAIL] == t)
182 t = (PLISTINFO) RemTail(LHead);
185 t1 = (PLISTINFO) t->ListNode.Previous;
186 t1->ListNode.Next = t->ListNode.Next;
187 t1 = (PLISTINFO) t->ListNode.Next;
188 t1->ListNode.Previous = t->ListNode.Previous;
195 /*----------------------------------------------------------------------------
197 * Try to find a specific node in the queue whose key matches with
198 * searching key. Return the pointer to that node if found, return NULL
202 * lpHashTbl => a far pointer to the hash table
203 * lpKey => a far poniter to searching key
204 * CompareCallBack => comparision function
206 * Output: a far pointer to the node to be found
209 PLISTINFO SearchList(
210 PLISTHEAD lpListHead,
212 int (* CompareCallBack) ( PVOID, PVOID ) )
214 PLISTINFO lpListInfo;
216 lpListInfo = PeekList( lpListHead, LISTHEAD, 0);
217 while ( lpListInfo != NULL )
219 if ( CompareCallBack( lpListInfo, lpSKey ) )
221 lpListInfo = GetNextNode( lpListInfo );
224 return( lpListInfo );