summaryrefslogtreecommitdiff
path: root/rdoff/collectn.c
diff options
context:
space:
mode:
Diffstat (limited to 'rdoff/collectn.c')
-rw-r--r--rdoff/collectn.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/rdoff/collectn.c b/rdoff/collectn.c
new file mode 100644
index 0000000..317c528
--- /dev/null
+++ b/rdoff/collectn.c
@@ -0,0 +1,45 @@
+/*
+ * collectn.c - implements variable length pointer arrays [collections].
+ *
+ * This file is public domain.
+ */
+
+#include "compiler.h"
+#include <stdlib.h>
+#include "collectn.h"
+
+void collection_init(Collection * c)
+{
+ int i;
+
+ for (i = 0; i < 32; i++)
+ c->p[i] = NULL;
+ c->next = NULL;
+}
+
+void **colln(Collection * c, int index)
+{
+ while (index >= 32) {
+ index -= 32;
+ if (c->next == NULL) {
+ c->next = malloc(sizeof(Collection));
+ collection_init(c->next);
+ }
+ c = c->next;
+ }
+ return &(c->p[index]);
+}
+
+void collection_reset(Collection * c)
+{
+ int i;
+
+ if (c->next) {
+ collection_reset(c->next);
+ free(c->next);
+ }
+
+ c->next = NULL;
+ for (i = 0; i < 32; i++)
+ c->p[i] = NULL;
+}