Annotation of libwww/Library/src/HTArray.html, revision 2.1

2.1     ! frystyk     1: <HTML>
        !             2: <HEAD>
        !             3: <TITLE>Dynamic Array Pointer Class</TITLE>
        !             4: <!-- Changed by: Henrik Frystyk Nielsen,  3-Oct-1995 -->
        !             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) &amp;&amp; ((data)=(me)-&gt;data) ? *(data)++ : NULL)
        !            87: #define HTArray_nextObject(me, data) \
        !            88:        ((me) &amp;&amp; (data) ? *(data)++ : NULL)
        !            89: </PRE>
        !            90: 
        !            91: <H2>Sort an Array</H2>
        !            92: 
        !            93: Arrays are ment to be sorted :-) Here's a function using qsort. It
        !            94: returns YES if sorting OK, else NO.
        !            95: 
        !            96: <PRE>
        !            97: extern BOOL HTArray_sort (HTArray * array,
        !            98:                          int (*compar) (CONST void *, CONST void *));
        !            99: </PRE>
        !           100: 
        !           101: <H2>Returns Data Vector</H2>
        !           102: 
        !           103: Returns a pointer to the actual data
        !           104: 
        !           105: <PRE>
        !           106: #define HTArray_data(me)       ((me) ? (me)-&gt;data : NULL)
        !           107: </PRE>
        !           108: 
        !           109: 
        !           110: <H2>Return Current Size</H2>
        !           111: 
        !           112: Returns the current size of the chunk
        !           113: 
        !           114: <PRE>
        !           115: #define HTArray_size(me)       ((me) ? (me)-&gt;size : -1)
        !           116: </PRE>
        !           117: 
        !           118: <PRE>
        !           119: #endif
        !           120: </PRE>
        !           121: 
        !           122: End of Declaration
        !           123: 
        !           124: </BODY>
        !           125: </HTML>

Webmaster