chiark / gitweb /
Version bump.
[mLib] / darray.h
index b8f17eb0499bf5418b23346b46c828abf00242d2..003c6d7aa5d4aeaeaa2b12126f8bcef088ac5510 100644 (file)
--- a/darray.h
+++ b/darray.h
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: darray.h,v 1.5 2000/06/17 10:37:39 mdw Exp $
+ * $Id: darray.h,v 1.6 2001/03/03 12:20:23 mdw Exp $
  *
  * Dynamically growing dense arrays
  *
@@ -30,6 +30,9 @@
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: darray.h,v $
+ * Revision 1.6  2001/03/03 12:20:23  mdw
+ * New macros @DA_FIRST@ and @DA_LAST@ for stack/queue peeking.
+ *
  * Revision 1.5  2000/06/17 10:37:39  mdw
  * Add support for arena management.
  *
@@ -410,6 +413,26 @@ typedef struct da_base {
 
 /*----- Stack-like operations ---------------------------------------------*/
 
+/* --- @DA_FIRST@ --- *
+ *
+ * Arguments:  @a@ = pointer to an array block (multiply evaluated)
+ *
+ * Use:                Evaluates to the initial element in array @a@.  It is unsafe
+ *             to do this if the array is empty.  The array is not changed. 
+ */
+
+#define DA_FIRST(a) (DA(a)[0])
+
+/* --- @DA_LAST@ --- *
+ *
+ * Arguments:  @a@ = pointer to an array block (multiply evaluated)
+ *
+ * Use:                Evaluates to the final element in array @a@.  It is unsafe
+ *             to do this if the array is empty.  The array is not changed.
+ */
+
+#define DA_LAST(a) (DA(a)[(a)->b.len - 1])
+
 /* --- @DA_PUSH@ --- *
  *
  * Arguments:  @a@ = pointer to an array block (multiply evaluated)
@@ -462,7 +485,7 @@ typedef struct da_base {
  */
 
 #define DA_SHIFT(a)                                                    \
-  ((a)->b.len ? ((void)0) : THROW(DAEXC_UFLOW),                        \
+  ((a)->b.len ? ((void)0) : THROW(DAEXC_UFLOW),                                \
    (a)->b.len--,                                                       \
    (a)->b.sz--,                                                                \
    (a)->b.off++,                                                       \