collectn.c 783 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * collectn.c - implements variable length pointer arrays [collections].
  3. *
  4. * This file is public domain.
  5. */
  6. #include "rdfutils.h"
  7. #include "collectn.h"
  8. void collection_init(Collection * c)
  9. {
  10. int i;
  11. for (i = 0; i < 32; i++)
  12. c->p[i] = NULL;
  13. c->next = NULL;
  14. }
  15. void **colln(Collection * c, int index)
  16. {
  17. while (index >= 32) {
  18. index -= 32;
  19. if (c->next == NULL) {
  20. c->next = nasm_malloc(sizeof(Collection));
  21. collection_init(c->next);
  22. }
  23. c = c->next;
  24. }
  25. return &(c->p[index]);
  26. }
  27. void collection_reset(Collection * c)
  28. {
  29. int i;
  30. if (c->next) {
  31. collection_reset(c->next);
  32. nasm_free(c->next);
  33. }
  34. c->next = NULL;
  35. for (i = 0; i < 32; i++)
  36. c->p[i] = NULL;
  37. }