LinkedList.h
Go to the documentation of this file.
/*******************************************************************************
*
* Copyright (c) 2000-2003 Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither name of Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************/
#ifndef LINKED_LIST_H
#define LINKED_LIST_H
#include "FreeList.h"
#ifdef __cplusplus
extern "C" {
#endif
#define EOUTOFMEM (-7 & 1<<29)
#define FREELISTSIZE 100
#define LIST_SUCCESS 1
#define LIST_FAIL 0
typedef void (*free_function)(void *arg);
typedef int (*cmp_routine)(void *itemA,void *itemB);
typedef struct LISTNODE
{
struct LISTNODE *prev;
struct LISTNODE *next;
void *item;
} ListNode;
typedef struct LINKEDLIST
{
ListNode head;
ListNode tail;
long size;
FreeList freeNodeList;
free_function free_func;
cmp_routine cmp_func;
} LinkedList;
int ListInit(
LinkedList *list,
cmp_routine cmp_func,
free_function free_func);
ListNode *ListAddHead(
LinkedList *list,
void *item);
ListNode *ListAddTail(
LinkedList *list,
void *item);
ListNode *ListAddAfter(
LinkedList *list,
void *item,
ListNode *bnode);
ListNode *ListAddBefore(
LinkedList *list,
void *item,
ListNode *anode);
void *ListDelNode(
LinkedList *list,
ListNode *dnode,
int freeItem);
int ListDestroy(
LinkedList *list,
int freeItem);
ListNode *ListHead(
LinkedList *list);
ListNode *ListTail(
LinkedList *list);
ListNode *ListNext(
LinkedList *list,
ListNode *node);
ListNode *ListPrev(
LinkedList *list,
ListNode *node);
ListNode* ListFind(
LinkedList *list,
ListNode *start,
void *item);
long ListSize(
LinkedList* list);
#ifdef __cplusplus
}
#endif
#endif /* LINKED_LIST_H */
FreeList.h
ListHead
ListNode * ListHead(LinkedList *list)
Returns the head of the list.
Definition: LinkedList.c:219
ListAddHead
ListNode * ListAddHead(LinkedList *list, void *item)
Adds a node to the head of the list. Node gets immediately after list head.
Definition: LinkedList.c:109
ListDestroy
int ListDestroy(LinkedList *list, int freeItem)
Removes all memory associated with list nodes. Does not free LinkedList *list.
Definition: LinkedList.c:200
ListAddTail
ListNode * ListAddTail(LinkedList *list, void *item)
Adds a node to the tail of the list. Node gets added immediately before list.tail.
Definition: LinkedList.c:119
LINKEDLIST::size
long size
Definition: LinkedList.h:90
ListFind
ListNode * ListFind(LinkedList *list, ListNode *start, void *item)
Finds the specified item in the list.
Definition: LinkedList.c:272
ListInit
int ListInit(LinkedList *list, cmp_routine cmp_func, free_function free_func)
Initializes LinkedList. Must be called first and only once for List.
Definition: LinkedList.c:84
ListAddAfter
ListNode * ListAddAfter(LinkedList *list, void *item, ListNode *bnode)
Adds a node after the specified node. Node gets added immediately after bnode.
Definition: LinkedList.c:129
ListAddBefore
ListNode * ListAddBefore(LinkedList *list, void *item, ListNode *anode)
Adds a node before the specified node. Node gets added immediately before anode.
Definition: LinkedList.c:153
LISTNODE
Definition: LinkedList.h:60
LINKEDLIST::freeNodeList
FreeList freeNodeList
Definition: LinkedList.h:92
ListPrev
ListNode * ListPrev(LinkedList *list, ListNode *node)
Returns the previous item in the list.
Definition: LinkedList.c:258
free_function
void(* free_function)(void *arg)
Definition: LinkedList.h:52
ListNext
ListNode * ListNext(LinkedList *list, ListNode *node)
Returns the next item in the list.
Definition: LinkedList.c:245
FREELIST
Definition: FreeList.h:61
LinkedList
struct LINKEDLIST LinkedList
LINKEDLIST::head
ListNode head
Definition: LinkedList.h:86
LINKEDLIST::tail
ListNode tail
Definition: LinkedList.h:88
LINKEDLIST::free_func
free_function free_func
Definition: LinkedList.h:94
LINKEDLIST::cmp_func
cmp_routine cmp_func
Definition: LinkedList.h:96
ListSize
long ListSize(LinkedList *list)
Returns the size of the list.
Definition: LinkedList.c:301
cmp_routine
int(* cmp_routine)(void *itemA, void *itemB)
Definition: LinkedList.h:55
ListDelNode
void * ListDelNode(LinkedList *list, ListNode *dnode, int freeItem)
Removes a node from the list. The memory for the node is freed.
Definition: LinkedList.c:177
ListTail
ListNode * ListTail(LinkedList *list)
Returns the tail of the list.
Definition: LinkedList.c:232
LINKEDLIST
Definition: LinkedList.h:83
ListNode
struct LISTNODE ListNode