aboutsummaryrefslogtreecommitdiff
path: root/src/backend/tioga/Varray.h
diff options
context:
space:
mode:
authorMarc G. Fournier <scrappy@hub.org>1996-07-09 06:22:35 +0000
committerMarc G. Fournier <scrappy@hub.org>1996-07-09 06:22:35 +0000
commitd31084e9d1118b25fd16580d9d8c2924b5740dff (patch)
tree3179e66307d54df9c7b966543550e601eb55e668 /src/backend/tioga/Varray.h
downloadpostgresql-PG95-1_01.tar.gz
postgresql-PG95-1_01.zip
Postgres95 1.01 Distribution - Virgin SourcesPG95-1_01
Diffstat (limited to 'src/backend/tioga/Varray.h')
-rw-r--r--src/backend/tioga/Varray.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/backend/tioga/Varray.h b/src/backend/tioga/Varray.h
new file mode 100644
index 00000000000..f6d01c23db4
--- /dev/null
+++ b/src/backend/tioga/Varray.h
@@ -0,0 +1,45 @@
+/* ********************************************************************
+ *
+ * Varray.h -- header file for varray.c which provides a generic
+ * set of functions to handle variable sized arrays.
+ *
+ * originally by Jiang Wu
+ * ********************************************************************/
+
+#ifndef _VARRAY_H_
+#define _VARRAY_H_
+
+typedef struct _varray {
+ size_t nobj; /* number of objects in this array */
+ size_t maxObj; /* max. number of objects in this array */
+ size_t size; /* size of each element in the array */
+ void *val; /* array of elements */
+} Varray;
+
+/* type for custom copying function */
+typedef void (*CopyingFunct) (void *from, void *to);
+
+#define VARRAY_INITIAL_SIZE 32
+
+#define ENLARGE_VARRAY(ARRAY, INC) \
+ (ARRAY)->maxObj += (INC); \
+ (ARRAY)->val = (void *) realloc((ARRAY)->val, \
+ (ARRAY)->size * (ARRAY)->maxObj)
+
+#define VARRAY_NTH(VAL, SIZE, N) (((char *) (VAL)) + (SIZE) * (N))
+
+#define FreeVarray(ARRAY) \
+ if ((ARRAY) != NULL) { free((ARRAY)->val); free((ARRAY)); (ARRAY) = NULL ; }
+
+#define ModifyVarray(ARRAY, N, NEW, COPY) \
+ if ((N) < (ARRAY)->nobj) \
+ (COPY)(VARRAY_NTH((ARRAY)->val, (ARRAY)->size, (N)), (NEW))
+
+#define GetVarray(ARRAY, N) \
+ ((N) < (ARRAY)->nobj ? VARRAY_NTH((ARRAY)->val, (ARRAY)->size, (N)) \
+ : NULL)
+
+extern Varray *NewVarray(size_t nobj, size_t size);
+extern int AppendVarray(Varray *array, void *value, CopyingFunct copy);
+
+#endif /* _VARRAY_H_ */