1 /* Copyright Massachusetts Institute of Technology 1985 */
16 * XCreateAssocTable - Create an XAssocTable. The size argument should be
17 * a power of two for efficiency reasons. Some size suggestions: use 32
18 * buckets per 100 objects; a reasonable maximum number of object per
19 * buckets is 8. If there is an error creating the XAssocTable, a NULL
20 * pointer is returned.
22 XAssocTable
*XCreateAssocTable(register int size
)
23 /* Desired size of the table. */
25 register XAssocTable
*table
; /* XAssocTable to be initialized. */
26 register XAssoc
*buckets
; /* Pointer to the first bucket in */
27 /* the bucket array. */
29 /* Malloc the XAssocTable. */
30 if ((table
= (XAssocTable
*)malloc(sizeof(XAssocTable
))) == NULL
) {
31 /* malloc call failed! */
36 /* calloc the buckets (actually just their headers). */
37 buckets
= (XAssoc
*)calloc((unsigned)size
, (unsigned)sizeof(XAssoc
));
38 if (buckets
== NULL
) {
39 /* calloc call failed! */
44 /* Insert table data into the XAssocTable structure. */
45 table
->buckets
= buckets
;
49 /* Initialize each bucket. */
50 buckets
->prev
= buckets
;
51 buckets
->next
= buckets
;