chiark / gitweb /
Allow more characters to start words in test vector files.
[mLib] / darray.h
index 93a806f7454f23eeb3bc5c7e6eb1ee999aa21c21..f2ebe1f7f01ff6258b0737cc5a79db95128a816b 100644 (file)
--- a/darray.h
+++ b/darray.h
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: darray.h,v 1.1 1999/10/22 22:37:26 mdw Exp $
+ * $Id: darray.h,v 1.3 1999/11/05 14:32:43 mdw Exp $
  *
  * Dynamically growing dense arrays
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: darray.h,v $
+ * Revision 1.3  1999/11/05 14:32:43  mdw
+ * Minor change in argument naming.
+ *
+ * Revision 1.2  1999/10/29 22:59:22  mdw
+ * New array adjustment macros for unsigned arguments.
+ *
  * Revision 1.1  1999/10/22 22:37:26  mdw
  * New dynamic array implementation replaces `dynarray.h'.
  *
@@ -105,8 +111,8 @@ typedef struct da_base {
  * Use:                Declares a structure for decribing a dynamic array.
  */
 
-#define DA_DECL(atype, type)                                           \
-  typedef struct atype { da_base b; type *v; } atype
+#define DA_DECL(type_v, type)                                          \
+  typedef struct type_v { da_base b; type *v; } type_v
 
 /*----- Initialization, creation and destruction --------------------------*/
 
@@ -185,6 +191,16 @@ typedef struct da_base {
 
 #define DA_TIDY(a) ((a)->v = da_tidy(&(a)->b, (a)->v, sizeof((a)->v[0])))
 
+/* --- @DA_RESET@ --- *
+ *
+ * Arguments:  @a@ = pointer to array block
+ *
+ * Use:                Removes all the items from the named array.  This might not
+ *             be a good idea.  No storage is freed.
+ */
+
+#define DA_RESET(a) ((a)->b.len = 0)
+
 /*----- Access operations -------------------------------------------------*/
 
 /* --- @DA@ --- *
@@ -269,7 +285,7 @@ typedef struct da_base {
   DA_UNSAFE_EXTEND(a, n);                                              \
 } while (0)
 
-/* --- @DA_EXTEND@ --- *
+/* --- @DA_UNSAFE_EXTEND@ --- *
  *
  * Arguments:  @a@ = pointer to array block (multiply evaluated)
  *             @n@ = number of slots to add (multiply evaluated)
@@ -322,6 +338,68 @@ typedef struct da_base {
   (a)->b.off -= (n);                                                   \
 } while (0)
 
+/* --- @DA_SHRINK@ --- *
+ *
+ * Arguments:  @a@ = pointer to array block (multiply evaluated)
+ *             @n@ = number of slots to remove (multiply evaluated)
+ *
+ * Use:                As for @DA_EXTEND@, with the sense of the argument reversed.
+ */
+
+#define DA_SHRINK(a, n) do {                                           \
+  if ((n) > 0 && (n) > DA_LEN(a))                                      \
+    THROW(DAEXC_UFLOW);                                                        \
+  else if ((n) < 0 && -(n) > DA_SPARE(a))                              \
+    THROW(DAEXC_OFLOW);                                                        \
+  DA_UNSAFE_SHRINK(a, n);                                              \
+} while (0)
+
+/* --- @DA_UNSAFE_SHRINK@ --- *
+ *
+ * Arguments:  @a@ = pointer to array block (multiply evaluated)
+ *             @n@ = number of slots to add (multiply evaluated)
+ *
+ * Use:                As for @DA_SHRINK@, only it doesn't check for errors.
+ */
+
+#define DA_UNSAFE_SHRINK(a, n) do {                                    \
+  (a)->b.len -= (n);                                                   \
+} while (0)
+
+/* --- @DA_UNSLIDE@ --- *
+ *
+ * Arguments:  @a@ = pointer to array block (multiply evaluated)
+ *             @n@ = number of positions to slide the array (multiply
+ *                     evaluated)
+ *
+ *
+ * Use:                As for @DA_SLIDE@, only in the other direction.
+ */
+
+#define DA_UNSLIDE(a, n) do {                                          \
+  if ((n) > 0 && (n) > DA_LEN(a))                                      \
+    THROW(DAEXC_UFLOW);                                                        \
+  else if ((n) < 0 && -(n) > DA_OFFSET(a))                             \
+    THROW(DAEXC_OFLOW);                                                        \
+  DA_UNSAFE_UNSLIDE((a), (n));                                         \
+} while (0)
+
+/* --- @DA_UNSAFE_UNSLIDE@ --- *
+ *
+ * Arguments:  @a@ = pointer to array block (multiply evaluated)
+ *             @n@ = number of positions to slide the array (multiply
+ *                     evaluated)
+ *
+ * Use:                As for @DA_UNSLIDE@, only it doesn't check for errors.
+ */
+
+#define DA_UNSAFE_UNSLIDE(a, n) do {                                   \
+  (a)->v += (n);                                                       \
+  (a)->b.len -= (n);                                                   \
+  (a)->b.sz -= (n);                                                    \
+  (a)->b.off += (n);                                                   \
+} while (0)
+
 /*----- Stack-like operations ---------------------------------------------*/
 
 /* --- @DA_PUSH@ --- *