|
|
1.1 root 1: #include "copyright.h"
2:
3: /* $Header: XCrAssoc.c,v 10.15 87/09/11 07:56:32 toddb Exp $ */
4: /* Copyright Massachusetts Institute of Technology 1985 */
5:
6: #include "Xlibint.h"
7: #include "X10.h"
8:
9: /*
10: * XCreateAssocTable - Create an XAssocTable. The size argument should be
11: * a power of two for efficiency reasons. Some size suggestions: use 32
12: * buckets per 100 objects; a reasonable maximum number of object per
13: * buckets is 8. If there is an error creating the XAssocTable, a NULL
14: * pointer is returned.
15: */
16: XAssocTable *XCreateAssocTable(size)
17: register int size; /* Desired size of the table. */
18: {
19: register XAssocTable *table; /* XAssocTable to be initialized. */
20: register XAssoc *buckets; /* Pointer to the first bucket in */
21: /* the bucket array. */
22:
23: /* XMalloc the XAssocTable. */
24: if ((table = (XAssocTable *)Xmalloc(sizeof(XAssocTable))) == NULL) {
25: /* XMalloc call failed! */
26: errno = ENOMEM;
27: return(NULL);
28: }
29:
30: /* XMalloc the buckets (actually just their headers). */
31: buckets = (XAssoc *)Xcalloc((unsigned)size, (unsigned)sizeof(XAssoc));
32: if (buckets == NULL) {
33: /* XCalloc call failed! */
34: errno = ENOMEM;
35: return(NULL);
36: }
37:
38: /* Insert table data into the XAssocTable structure. */
39: table->buckets = buckets;
40: table->size = size;
41:
42: while (--size >= 0) {
43: /* Initialize each bucket. */
44: buckets->prev = buckets;
45: buckets->next = buckets;
46: buckets++;
47: }
48:
49: return(table);
50: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.