Annotation of libwww/Library/src/HTArray.html, revision 2.3
2.1 frystyk 1: <HTML>
2: <HEAD>
3: <TITLE>Dynamic Array Pointer Class</TITLE>
2.2 frystyk 4: <!-- Changed by: Henrik Frystyk Nielsen, 11-Nov-1995 -->
2.1 frystyk 5: </HEAD>
6: <BODY>
7:
8: <H1>Dynamic Array Pointer Class</H1>
9:
10: <PRE>
11: /*
12: ** (c) COPYRIGHT MIT 1995.
13: ** Please first read the full copyright statement in the file COPYRIGH.
14: */
15: </PRE>
16:
17: This module implements a flexible array of pointers. It is a general
18: utility module. An array is a structure which may be extended. These
19: routines create and append data to arrays, automatically reallocating
20: them as necessary. It is garanteed that the last entry in an array is
21: <B>NULL</B>
22:
23: This module is implemented by <A HREF="HTArray.c">HTArray.c</A>, and
24: it is a part of the <A HREF="http://www.w3.org/pub/WWW/Library/"> W3C
25: Reference Library</A>.
26:
27: <PRE>
28: #ifndef HTARRAY_H
29: #define HTARRAY_H
30: </PRE>
31:
32: <H2>Private Data Structure</H2>
33:
34: This structure should not be referenced outside this module. If I find
35: out I'll make it private ;-)
36:
37: <PRE>
38: typedef struct {
39: int size; /* In numbers of elements */
40: int growby; /* Allocation unit in elements */
41: int allocated; /* Current size of *data */
42: void ** data; /* Pointer to malloced area or 0 */
43: } HTArray;
44: </PRE>
45:
46: <H2>Create a new Array</H2>
47:
48: Create a new array and specify the number of bytes to allocate at a
49: time when the array is later extended. Arbitrary but normally a
50: trade-off time vs. memory
51:
52: <PRE>
53: extern HTArray * HTArray_new (int grow);
54: </PRE>
55:
56: <H2>Delete an Array</H2>
57:
58: Delete an array created by HTArray_new
59:
60: <PRE>
61: extern BOOL HTArray_delete (HTArray * array);
62: </PRE>
63:
64: <H2>Clear an Array</H2>
65:
66: Clears an array but keeps it around
67:
68: <PRE>
69: extern BOOL HTArray_clear (HTArray * array);
70: </PRE>
71:
72: <H2>Append an element to the Array</H2>
73:
74: Add the element to the array.
75:
76: <PRE>
77: extern BOOL HTArray_addObject (HTArray * array, void * object);
78: </PRE>
79:
80: <H2>Traverse an Array</H2>
81:
82: Fast macros to traverse a macro ending in a NULL element.
83:
84: <PRE>
85: #define HTArray_firstObject(me, data) \
86: ((me) && ((data)=(me)->data) ? *(data)++ : NULL)
87: #define HTArray_nextObject(me, data) \
88: ((me) && (data) ? *(data)++ : NULL)
89: </PRE>
90:
91: <H2>Sort an Array</H2>
92:
2.2 frystyk 93: An array can be sorted in any way you like, for example with
94: qsort(). This module provides an easy interface to the qsort()
95: function using where you can define you own comparison routine as a
96: function of the type:
2.1 frystyk 97:
98: <PRE>
2.3 ! frystyk 99: typedef int HTComparer (const void * a, const void * b);
2.2 frystyk 100: </PRE>
101:
102: The sort function returns YES if sorting OK, else NO.
103:
104: <PRE>
105: extern BOOL HTArray_sort (HTArray * array, HTComparer * comp);
2.1 frystyk 106: </PRE>
107:
108: <H2>Returns Data Vector</H2>
109:
110: Returns a pointer to the actual data
111:
112: <PRE>
113: #define HTArray_data(me) ((me) ? (me)->data : NULL)
114: </PRE>
115:
116:
117: <H2>Return Current Size</H2>
118:
119: Returns the current size of the chunk
120:
121: <PRE>
122: #define HTArray_size(me) ((me) ? (me)->size : -1)
123: </PRE>
124:
125: <PRE>
126: #endif
127: </PRE>
128:
129: End of Declaration
130:
131: </BODY>
132: </HTML>
Webmaster