XCrAssoc.c 1.5 KB

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