Merge from emacs--devo--0
[bpt/emacs.git] / oldXMenu / XCrAssoc.c
1 /* Copyright Massachusetts Institute of Technology 1985 */
2 /* Copyright (C) 2001, 2002, 2003, 2004, 2005,
3 2006, 2007 Free Software Foundation, Inc. */
4
5 #include "copyright.h"
6
7
8 #include <config.h>
9 #include <X11/Xlib.h>
10 #include <errno.h>
11 #include "X10.h"
12
13 #ifndef NULL
14 #define NULL 0
15 #endif
16
17 extern int errno;
18
19 /*
20 * XCreateAssocTable - Create an XAssocTable. The size argument should be
21 * a power of two for efficiency reasons. Some size suggestions: use 32
22 * buckets per 100 objects; a reasonable maximum number of object per
23 * buckets is 8. If there is an error creating the XAssocTable, a NULL
24 * pointer is returned.
25 */
26 XAssocTable *XCreateAssocTable(size)
27 register int size; /* Desired size of the table. */
28 {
29 register XAssocTable *table; /* XAssocTable to be initialized. */
30 register XAssoc *buckets; /* Pointer to the first bucket in */
31 /* the bucket array. */
32
33 /* Malloc the XAssocTable. */
34 if ((table = (XAssocTable *)malloc(sizeof(XAssocTable))) == NULL) {
35 /* malloc call failed! */
36 errno = ENOMEM;
37 return(NULL);
38 }
39
40 /* calloc the buckets (actually just their headers). */
41 buckets = (XAssoc *)calloc((unsigned)size, (unsigned)sizeof(XAssoc));
42 if (buckets == NULL) {
43 /* calloc call failed! */
44 errno = ENOMEM;
45 return(NULL);
46 }
47
48 /* Insert table data into the XAssocTable structure. */
49 table->buckets = buckets;
50 table->size = size;
51
52 while (--size >= 0) {
53 /* Initialize each bucket. */
54 buckets->prev = buckets;
55 buckets->next = buckets;
56 buckets++;
57 }
58
59 return(table);
60 }
61
62 /* arch-tag: 5df3237d-ada0-4345-a3ab-282cafb397aa
63 (do not change this comment) */