|
|
1.1 ! root 1: #include <X/mit-copyright.h> ! 2: ! 3: /* $Header: XCreateAssoc.c,v 10.7 86/12/16 17:12:11 tony Exp $ */ ! 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 *buckets; /* Pointer to the first bucket in */ ! 22: /* the bucket array. */ ! 23: ! 24: /* Malloc the XAssocTable. */ ! 25: if ((table = (XAssocTable *)malloc(sizeof(XAssocTable))) == NULL) { ! 26: /* Malloc call failed! */ ! 27: errno = ENOMEM; ! 28: return(NULL); ! 29: } ! 30: ! 31: /* Malloc the buckets (actually just their headers). */ ! 32: buckets = (XAssoc *)calloc(size, sizeof(XAssoc)); ! 33: if (buckets == NULL) { ! 34: /* Calloc call failed! */ ! 35: errno = ENOMEM; ! 36: return(NULL); ! 37: } ! 38: ! 39: /* Insert table data into the XAssocTable structure. */ ! 40: table->buckets = buckets; ! 41: table->size = size; ! 42: ! 43: while (--size >= 0) { ! 44: /* Initialize each bucket. */ ! 45: buckets->prev = buckets; ! 46: buckets->next = buckets; ! 47: buckets++; ! 48: } ! 49: ! 50: return(table); ! 51: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.