/* -*- Mode: C; tab-width: 4 -*-
*
* Copyright (c) 2003-2011 Apple Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "GenLinkedList.h"
// Return the link pointer contained within element e at offset o.
#define GETLINK( e, o) ( *(void**)((char*) (e) + (o)) )
// Assign the link pointer l to element e at offset o.
#define ASSIGNLINK( e, l, o) ( *((void**)((char*) (e) + (o))) = (l))
// GenLinkedList /////////////////////////////////////////////////////////////
/* Initialize the block of memory pointed to by pList as a linked list. */
{
}
/* Add a linked list element to the tail of the list. */
{
} else
}
/* Add a linked list element to the head of the list. */
{
}
/* Remove a linked list element from the list. Return 0 if it was not found. */
/* If the element is removed, its link will be set to NULL. */
{
if ( lastElem) { // somewhere past the head
} else { // at the head
}
return 1;
}
}
return 0;
}
/* Replace an element in the list with a new element, in the same position. */
{
return 0;
{
if ( iElem == elemInList)
{
if ( lastElem) // somewhere past the head
{
}
else // at the head
{
}
return 1;
}
}
return 0;
}
// GenDoubleLinkedList /////////////////////////////////////////////////////////
/* Initialize the block of memory pointed to by pList as a double linked list. */
{
}
/* Add a linked list element to the head of the list. */
{
void *pNext;
// fix up the forward links
// fix up the backward links
if ( pNext) {
} else
}
/* Remove a linked list element from the list. */
/* When the element is removed, its link will be set to NULL. */
{
// fix up the forward links
if ( pPrev)
else
// fix up the backward links
if ( pNext)
else
}
// GenLinkedOffsetList /////////////////////////////////////////////////////
// Extract the Next offset from element
// Assign link to elem as an offset from elem. Assign 0 to elem if link is NULL.
{
}
/* Return a pointer to the head element of a list, or NULL if none. */
{
}
/* Return a pointer to the tail element of a list, or NULL if none. */
{
}
/* Return the link pointer contained within element e for pList, or NULL if it is 0. */
{
}
/* Initialize the block of memory pointed to by pList as a linked list. */
{
}
/* Add a linked list element to the tail of the list. */
{
} else
}
/* Add a linked list element to the head of the list. */
{
}
/* Remove a linked list element from the list. Return 0 if it was not found. */
/* If the element is removed, its link will be set to NULL. */
{
{
if ( lastElem) { // somewhere past the head
} else { // at the head
}
return 1;
}
}
return 0;
}
/* Replace an element in the list with a new element, in the same position. */
{
return 0;
{
if ( iElem == elemInList)
{
if ( lastElem) // somewhere past the head
{
}
else // at the head
{
}
return 1;
}
}
return 0;
}