Annotation of libwww/Library/src/HTArray.html, revision 2.9
2.1 frystyk 1: <HTML>
2: <HEAD>
2.6 frystyk 3: <TITLE>W3C Sample Code Library libwww Dynamic Array Pointer Class</TITLE>
2.5 frystyk 4: <!-- Changed by: Henrik Frystyk Nielsen, 23-Mar-1996 -->
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
2.7 frystyk 24: it is a part of the <A HREF="http://www.w3.org/Library/"> W3C
2.6 frystyk 25: Sample Code Library</A>.
2.1 frystyk 26:
27: <PRE>
28: #ifndef HTARRAY_H
29: #define HTARRAY_H
2.9 ! vbancrof 30:
! 31: #ifdef __cplusplus
! 32: extern "C" {
! 33: #endif
2.1 frystyk 34: </PRE>
35:
36: <H2>Private Data Structure</H2>
37:
38: This structure should not be referenced outside this module. If I find
39: out I'll make it private ;-)
40:
41: <PRE>
42: typedef struct {
43: int size; /* In numbers of elements */
44: int growby; /* Allocation unit in elements */
45: int allocated; /* Current size of *data */
46: void ** data; /* Pointer to malloced area or 0 */
47: } HTArray;
48: </PRE>
49:
50: <H2>Create a new Array</H2>
51:
52: Create a new array and specify the number of bytes to allocate at a
53: time when the array is later extended. Arbitrary but normally a
54: trade-off time vs. memory
55:
56: <PRE>
57: extern HTArray * HTArray_new (int grow);
58: </PRE>
59:
60: <H2>Delete an Array</H2>
61:
62: Delete an array created by HTArray_new
63:
64: <PRE>
65: extern BOOL HTArray_delete (HTArray * array);
66: </PRE>
67:
68: <H2>Clear an Array</H2>
69:
70: Clears an array but keeps it around
71:
72: <PRE>
73: extern BOOL HTArray_clear (HTArray * array);
74: </PRE>
75:
76: <H2>Append an element to the Array</H2>
77:
78: Add the element to the array.
79:
80: <PRE>
81: extern BOOL HTArray_addObject (HTArray * array, void * object);
82: </PRE>
83:
84: <H2>Traverse an Array</H2>
85:
86: Fast macros to traverse a macro ending in a NULL element.
87:
88: <PRE>
2.8 kahan 89: #define HTArray_firstObject(me, dp) \
90: ((me) && ((dp)=(me)->data) ? *(dp)++ : NULL)
91: #define HTArray_nextObject(me, dp) \
92: ((me) && (dp) ? *(dp)++ : NULL)
2.1 frystyk 93: </PRE>
94:
95: <H2>Sort an Array</H2>
96:
2.2 frystyk 97: An array can be sorted in any way you like, for example with
98: qsort(). This module provides an easy interface to the qsort()
99: function using where you can define you own comparison routine as a
100: function of the type:
2.1 frystyk 101:
102: <PRE>
2.3 frystyk 103: typedef int HTComparer (const void * a, const void * b);
2.2 frystyk 104: </PRE>
105:
106: The sort function returns YES if sorting OK, else NO.
107:
108: <PRE>
109: extern BOOL HTArray_sort (HTArray * array, HTComparer * comp);
2.1 frystyk 110: </PRE>
111:
112: <H2>Returns Data Vector</H2>
113:
114: Returns a pointer to the actual data
115:
116: <PRE>
117: #define HTArray_data(me) ((me) ? (me)->data : NULL)
118: </PRE>
119:
120:
121: <H2>Return Current Size</H2>
122:
123: Returns the current size of the chunk
124:
125: <PRE>
126: #define HTArray_size(me) ((me) ? (me)->size : -1)
127: </PRE>
128:
129: <PRE>
2.9 ! vbancrof 130: #ifdef __cplusplus
! 131: }
! 132: #endif
! 133:
2.1 frystyk 134: #endif
135: </PRE>
136:
2.5 frystyk 137: <HR>
138: <ADDRESS>
2.9 ! vbancrof 139: @(#) $Id: HTArray.html,v 2.8 2000/08/07 10:38:05 kahan Exp $
2.5 frystyk 140: </ADDRESS>
2.1 frystyk 141: </BODY>
142: </HTML>
Webmaster