Annotation of libwww/Library/src/HTList.html, revision 2.21
2.6 timbl 1: <HTML>
2: <HEAD>
2.15 frystyk 3: <TITLE>Linked List Class</TITLE>
2.21 ! frystyk 4: <!-- Changed by: Henrik Frystyk Nielsen, 15-Nov-1995 -->
2.6 timbl 5: <NEXTID N="z3">
6: </HEAD>
7: <BODY>
2.7 frystyk 8:
9: <H1>List object</H1>
10:
11: <PRE>
12: /*
2.13 frystyk 13: ** (c) COPYRIGHT MIT 1995.
2.7 frystyk 14: ** Please first read the full copyright statement in the file COPYRIGH.
15: */
16: </PRE>
17:
18: The list object is a generic container for storing collections of
19: things in order. In principle it could be implemented in many ways,
20: but in practice knowing that it is a linked list is important for
2.19 frystyk 21: speed.<P>
2.7 frystyk 22:
23: This module is implemented by <A HREF="HTList.c">HTList.c</A>, and it
2.19 frystyk 24: is a part of the <A HREF="http://www.w3.org/pub/WWW/Library/"> W3C
25: Reference Library</A>.
2.7 frystyk 26:
2.1 timbl 27: <PRE>
28: #ifndef HTLIST_H
29: #define HTLIST_H
30:
31: typedef struct _HTList HTList;
32:
33: struct _HTList {
34: void * object;
35: HTList * next;
36: };
2.19 frystyk 37: </PRE>
38:
39: <H2>Creation and Deletion Methods</H2>
40:
41: These two functions create and deletes a list
2.1 timbl 42:
2.19 frystyk 43: <PRE>
44: extern HTList * HTList_new (void);
2.20 frystyk 45: extern BOOL HTList_delete (HTList *me);
2.12 frystyk 46: </PRE>
2.1 timbl 47:
2.19 frystyk 48: <H2>Add an Element to List</H2>
49:
50: A new list element is added to the beginning of the list so that it is
51: first element just after the head element.
2.12 frystyk 52:
2.6 timbl 53: <PRE>
2.19 frystyk 54: extern BOOL HTList_addObject (HTList *me, void *newObject);
2.21 ! frystyk 55: </PRE>
! 56:
! 57: You can also append an element to the end of the list (the end is the
! 58: first entered object) by using the following function:
! 59:
! 60: <PRE>
! 61: extern BOOL HTList_appendObject (HTList * me, void * newObject);
2.19 frystyk 62: </PRE>
63:
64: <H2>Remove List Elements</H2>
65:
66: <PRE>
67: extern BOOL HTList_removeObject (HTList *me, void *oldObject);
68: extern void * HTList_removeLastObject (HTList *me);
69: extern void * HTList_removeFirstObject (HTList *me);
70: </PRE>
71:
72: <H2>Size of a List</H2>
73:
74: Two small function to ask for the size
75:
76: <PRE>
77: #define HTList_isEmpty(me) (me ? me->next == NULL : YES)
78: extern int HTList_count (HTList *me);
79: </PRE>
80:
81: <H2>Reference List Elements By Index</H2>
82:
83: In some situations is is required to use an index in order to refer to
84: a list element. This is for example the case if an element can be
85: registered multiple times.
86:
87: <PRE>
88: extern int HTList_indexOf (HTList *me, void *object);
89: extern void * HTList_objectAt (HTList *me, int position);
90: </PRE>
91:
92: <H2>Find Last Element Added</H2>
93:
94: <PRE>
95: #define HTList_lastObject(me) \
2.16 frystyk 96: ((me) && (me)->next ? (me)->next->object : NULL)
2.12 frystyk 97: </PRE>
98:
2.19 frystyk 99: <H2>Traverse list</H2>
2.12 frystyk 100:
101: Fast macro to traverse the list. Call it first with copy of list
102: header: it returns the first object and increments the passed list
103: pointer. Call it with the same variable until it returns NULL.
2.1 timbl 104:
2.19 frystyk 105: <PRE>
106: #define HTList_nextObject(me) \
107: ((me) && ((me) = (me)->next) ? (me)->object : NULL)
2.12 frystyk 108: </PRE>
2.6 timbl 109:
2.19 frystyk 110: <H2>Free list</H2>
2.12 frystyk 111:
112: <PRE>
113: #define HTList_free(x) FREE(x)
2.1 timbl 114:
115: #endif /* HTLIST_H */
2.6 timbl 116:
117: </PRE>end</A></BODY>
118: </HTML>
Webmaster