Annotation of 43BSD/contrib/X/Xlib/XCreateAssoc.c, revision 1.1

1.1     ! root        1: #include <X/mit-copyright.h>
        !             2: 
        !             3: /* $Header: XCreateAssoc.c,v 10.5 86/02/01 15:31:04 tony Rel $ */
        !             4: /* Copyright    Massachusetts Institute of Technology    1985  */
        !             5: 
        !             6: #include "XlibInternal.h"
        !             7: 
        !             8: char *malloc();
        !             9: char *calloc();
        !            10: /*
        !            11:  * XCreateAssocTable - Create an XAssocTable.  The size argument should be
        !            12:  * a power of two for efficiency reasons.  Some size suggestions: use 32
        !            13:  * buckets per 100 objects;  a reasonable maximum number of object per
        !            14:  * buckets is 8.  If there is an error creating the XAssocTable, a NULL
        !            15:  * pointer is returned.
        !            16:  */
        !            17: XAssocTable *XCreateAssocTable(size)
        !            18:        register int size;              /* Desired size of the table. */
        !            19: {
        !            20:        register XAssocTable *table;    /* XAssocTable to be initialized. */
        !            21:        register XAssoc *bucket;        /* Pointer to a bucket in the table. */
        !            22:        
        !            23:        /* Malloc the XAssocTable. */
        !            24:        if ((table = (XAssocTable *)malloc(sizeof(XAssocTable))) == NULL) {
        !            25:                /* Malloc call failed! */
        !            26:                errno = ENOMEM;
        !            27:                return(NULL);
        !            28:        }
        !            29:        
        !            30:        /* Malloc the bucket headers. */
        !            31:        bucket = (XAssoc *)calloc(size, sizeof(XAssoc));
        !            32:        if (bucket == NULL) {
        !            33:                /* Calloc call failed! */
        !            34:                errno = ENOMEM;
        !            35:                return(NULL);
        !            36:        }
        !            37: 
        !            38:        /* Insert table data into the XAssocTable structure. */
        !            39:        table->table = (XAssoc (*)[])bucket;
        !            40:        table->size = size;
        !            41: 
        !            42:        while (--size >= 0) {
        !            43:                /* Initialize each bucket. */
        !            44:                bucket->prev = bucket;
        !            45:                bucket->next = bucket;
        !            46:                bucket++;
        !            47:        }
        !            48: 
        !            49:        return(table);
        !            50: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.