Файл src/list.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "allheaders.h"

Функции

void listDestroy (DLLIST **phead)
l_int32 listAddToHead (DLLIST **phead, void *data)
l_int32 listAddToTail (DLLIST **phead, DLLIST **ptail, void *data)
l_int32 listInsertBefore (DLLIST **phead, DLLIST *elem, void *data)
l_int32 listInsertAfter (DLLIST **phead, DLLIST *elem, void *data)
void * listRemoveElement (DLLIST **phead, DLLIST *elem)
void * listRemoveFromHead (DLLIST **phead)
void * listRemoveFromTail (DLLIST **phead, DLLIST **ptail)
DLLISTlistFindElement (DLLIST *head, void *data)
DLLISTlistFindTail (DLLIST *head)
l_int32 listGetCount (DLLIST *head)
l_int32 listReverse (DLLIST **phead)
l_int32 listJoin (DLLIST **phead1, DLLIST **phead2)

Функции

l_int32 listAddToHead ( DLLIST **  phead,
void *  data 
)

listAddToHead()

Input: &head (<optional> input head) data (void* ptr, to be added) Return: 0 if OK; 1 on error

Notes: (1) This makes a new cell, attaches the data, and adds the cell to the head of the list. (2) When consing from NULL, be sure to initialize head to NULL before calling this function.

l_int32 listAddToTail ( DLLIST **  phead,
DLLIST **  ptail,
void *  data 
)

listAddToTail()

Input: &head (<may be="" updated>="">, head can be null) &tail (<updated>, tail can be null) data (void* ptr, to be hung on tail cons cell) Return: 0 if OK; 1 on error

Notes: (1) This makes a new cell, attaches the data, and adds the cell to the tail of the list. (2) &head is input to allow the list to be "cons'd" up from NULL. (3) &tail is input to allow the tail to be updated for efficient sequential operation with this function. (4) We assume that if *phead and/or *ptail are not NULL, then they are valid addresses. Therefore: (a) when consing from NULL, be sure to initialize both head and tail to NULL. (b) when tail == NULL for an existing list, the tail will be found and updated.

void listDestroy ( DLLIST **  phead  ) 

listDestroy()

Input: &head (<to be="" nulled>=""> head of list) Return: void

Notes: (1) This only destroys the cons cells. Before destroying the list, it is necessary to remove all data and set the data pointers in each cons cell to NULL. (2) listDestroy() will give a warning message for each data ptr that is not NULL.

DLLIST* listFindElement ( DLLIST head,
void *  data 
)

listFindElement()

Input: head (list head) data (void* address, to be searched for) Return: cell (the containing cell, or null if not found or on error)

Notes: (1) This returns a ptr to the cell, which is still embedded in the list. (2) This handle and the attached data have not been copied or reference counted, so they must not be destroyed. This violates our basic rule that every handle returned from a function is owned by that function and must be destroyed, but if rules aren't there to be broken, why have them?

DLLIST* listFindTail ( DLLIST head  ) 

listFindTail()

Input: head Return: tail, or null on error

l_int32 listGetCount ( DLLIST head  ) 

listGetCount()

Input: head (of list) Return: number of elements; 0 if no list or on error

l_int32 listInsertAfter ( DLLIST **  phead,
DLLIST elem,
void *  data 
)

listInsertAfter()

Input: &head (<optional> input head) elem (list element to be inserted after; must be null if head is null) data (void* ptr, to be added) Return: 0 if OK; 1 on error

Notes: (1) This can be called on a null list, in which case both head and elem must be null. The head is included in the call to allow "consing" up from NULL. (2) If you are searching through a list, looking for a condition to add an element, you can do something like this: L_BEGIN_LIST_FORWARD(head, elem) <identify an="" elem="" to="" insert="" after>=""> listInsertAfter(&head, elem, data); L_END_LIST

l_int32 listInsertBefore ( DLLIST **  phead,
DLLIST elem,
void *  data 
)

listInsertBefore()

Input: &head (<optional> input head) elem (list element to be inserted in front of; must be null if head is null) data (void* address, to be added) Return: 0 if OK; 1 on error

Notes: (1) This can be called on a null list, in which case both head and elem must be null. (2) If you are searching through a list, looking for a condition to add an element, you can do something like this: L_BEGIN_LIST_FORWARD(head, elem) <identify an="" elem="" to="" insert="" before>=""> listInsertBefore(&head, elem, data); L_END_LIST

l_int32 listJoin ( DLLIST **  phead1,
DLLIST **  phead2 
)

listJoin()

Input: &head1 (<may be="" changed>=""> head of first list) &head2 (<to be="" nulled>=""> head of second list) Return: 0 if OK, 1 on error

Notes: (1) The concatenated list is returned with head1 as the new head. (2) Both input ptrs must exist, though either can have the value NULL.

void* listRemoveElement ( DLLIST **  phead,
DLLIST elem 
)

listRemoveElement()

Input: &head (<can be="" changed>=""> input head) elem (list element to be removed) Return: data (void* struct on cell)

Notes: (1) in ANSI C, it is not necessary to cast return to actual type; e.g., pix = listRemoveElement(&head, elem); but in ANSI C++, it is necessary to do the cast: pix = (Pix *)listRemoveElement(&head, elem);

void* listRemoveFromHead ( DLLIST **  phead  ) 

listRemoveFromHead()

Input: &head (<to be="" updated>=""> head of list) Return: data (void* struct on cell), or null on error

Notes: (1) in ANSI C, it is not necessary to cast return to actual type; e.g., pix = listRemoveFromHead(&head); but in ANSI C++, it is necessary to do the cast; e.g., pix = (Pix *)listRemoveFromHead(&head);

void* listRemoveFromTail ( DLLIST **  phead,
DLLIST **  ptail 
)

listRemoveFromTail()

Input: &head (<may be="" changed>="">, head must NOT be null) &tail (<always updated>="">, tail may be null) Return: data (void* struct on cell) or null on error

Notes: (1) We include &head so that it can be set to NULL if if the only element in the list is removed. (2) The function is relying on the fact that if tail is not NULL, then is is a valid address. You can use this function with tail == NULL for an existing list, in which case the tail is found and updated, and the removed element is returned. (3) In ANSI C, it is not necessary to cast return to actual type; e.g., pix = listRemoveFromTail(&head, &tail); but in ANSI C++, it is necessary to do the cast; e.g., pix = (Pix *)listRemoveFromTail(&head, &tail);

l_int32 listReverse ( DLLIST **  phead  ) 

listReverse()

Input: &head (<may be="" changed>=""> list head) Return: 0 if OK, 1 on error

Notes: (1) This reverses the list in-place.


Документация по Leptonica. Последние изменения: Fri Aug 7 20:31:37 2009. Создано системой  doxygen 1.5.9