summaryrefslogtreecommitdiff
path: root/src/backend/tioga/Varray.c
diff options
context:
space:
mode:
authorMarc G. Fournier1996-07-09 06:22:35 +0000
committerMarc G. Fournier1996-07-09 06:22:35 +0000
commit24a952fe4a27c6c66dc46ee3b2d860755fe063e1 (patch)
tree9c669cd24c4dbcf57f03c278f3169dcb971a2151 /src/backend/tioga/Varray.c
Postgres95 1.01 Distribution - Virgin SourcesPG95_DIST
Diffstat (limited to 'src/backend/tioga/Varray.c')
-rw-r--r--src/backend/tioga/Varray.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/backend/tioga/Varray.c b/src/backend/tioga/Varray.c
new file mode 100644
index 0000000000..3ed45c6656
--- /dev/null
+++ b/src/backend/tioga/Varray.c
@@ -0,0 +1,48 @@
+/* ************************************************************************
+ *
+ * Varray.c --
+ *
+ * routines to provide a generic set of functions to handle variable sized
+ * arrays. originally by Jiang Wu
+ * ************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "Varray.h"
+
+Varray *NewVarray(size_t nobj, size_t size)
+/*
+ * NewVarray -- allocate a Varray to contain an array of val each of which
+ * is size valSize. Returns the Varray if successful,
+ * returns NULL otherwise.
+ */
+{
+ Varray *result;
+
+ if (nobj == 0)
+ nobj = VARRAY_INITIAL_SIZE;
+ result = (Varray *) malloc(sizeof(Varray));
+ result->val = (void *) calloc(nobj, size);
+ if (result == NULL)
+ return NULL;
+ result->size = size;
+ result->nobj = 0;
+ result->maxObj = nobj;
+ return result;
+}
+
+int AppendVarray(Varray *array, void *value, CopyingFunct copy)
+/*
+ * AppendVarray -- append value to the end of array. This function
+ * returns the size of the array after the addition of
+ * the new element.
+ */
+{
+ copy(value, VARRAY_NTH(array->val, array->size, array->nobj));
+ array->nobj++;
+ if (array->nobj >= array->maxObj) {
+ ENLARGE_VARRAY(array, array->maxObj / 2);
+ }
+ return array->nobj;
+}
+