## -*-Makefile-*-
##
-## $Id: Makefile.am,v 1.31 2001/02/03 18:43:56 mdw Exp $
+## $Id: Makefile.am,v 1.32 2001/03/03 12:20:23 mdw Exp $
##
## Building the distribution
##
##----- Revision history ----------------------------------------------------
##
## $Log: Makefile.am,v $
+## Revision 1.32 2001/03/03 12:20:23 mdw
+## New macros @DA_FIRST@ and @DA_LAST@ for stack/queue peeking.
+##
## Revision 1.31 2001/02/03 18:43:56 mdw
## New feature: watch a file for changes.
##
da_test_LDADD = libmLib.la
da_test_LDFLAGS = -static
-da-test.in:
+da-test.in: $(srcdir)/da-gtest
perl $(srcdir)/da-gtest 10000 >da-test.in
-da-test.ref: da-test.in
+da-test.ref: da-test.in $(srcdir)/da-ref
perl $(srcdir)/da-ref <da-test.in >da-test.ref
da-test.test: da-test da-test.in da-test.ref
./da-test <da-test.in >da-test.test
sym_test_LDADD = libmLib.la
sym_test_LDFLAGS = -static
-sym-test.in:
+sym-test.in: $(srcdir)/sym-gtest
perl $(srcdir)/sym-gtest 10000 >sym-test.in
-sym-test.ref: sym-test.in
+sym-test.ref: sym-test.in $(srcdir)/sym-ref
perl $(srcdir)/sym-ref <sym-test.in >sym-test.ref
sym-test.test: sym-test sym-test.in sym-test.ref
./sym-test <sym-test.in >sym-test.test
# reduce n -- remove n items from end
# set i n -- assign item at index i to be n
# get i -- display item at index i
+# first, last -- show first or last item
# show -- write entire array to stdout, space separated on one line
sub random ($) {
$max = 0; # Estimate of size of array
$serial = 1;
while ($lines) {
- $what = random(17);
+ $what = random(21);
if ($what < 8) {
my $op = (qw(push pop shift unshift))[$what % 4];
if ($op eq "push" || $op eq "unshift") {
} else {
print "get $i\n";
}
+ } elsif ($what < 20) {
+ my $op = (qw(first last))[$what % 2];
+ print "$op\n" if $max;
} elsif (random(10) == 0) {
print "show\n";
} else { next; }
} else {
print int($a[$F[1]]), "\n";
}
+ } elsif ($F[0] eq "first") {
+ print int($a[0]), "\n";
+ } elsif ($F[0] eq "last") {
+ print int($a[$#a]), "\n";
} elsif ($F[0] eq "show") {
if (@a) {
print join(" ", map int, @a), "\n";
puts("*RANGE*");
else
printf("%i\n", DA(&v)[i]);
+ } else if (strcmp(p, "first") == 0) {
+ printf("%i\n", DA_FIRST(&v));
+ } else if (strcmp(p, "last") == 0) {
+ printf("%i\n", DA_LAST(&v));
} else if (strcmp(p, "show") == 0) {
if (DA_LEN(&v) == 0)
puts("*EMPTY*");
/* -*-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
*
/*----- 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.
*
/*----- 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)
*/
#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++, \
.\" @DA_UNSAFE_SHRINK
.\" @DA_UNSLIDE
.\" @DA_UNSAFE_UNSLIDE
+.\" @DA_FIRST
+.\" @DA_LAST
.\" @DA_PUSH
.\" @DA_POP
.\" @DA_UNSHIFT
.BI "void DA_UNSAFE_SLIDE(" type_v " *" a ", long " n );
.BI "void DA_UNSAFE_UNSLIDE(" type_v " *" a ", long " n );
+.IB type " DA_FIRST(" type_v " *" a );
+.IB type " DA_LAST(" type_v " *" a );
.BI "void DA_PUSH(" type_v " *" a ", " type " " x );
.IB type " DA_POP(" type_v " *" a );
.BI "void DA_UNSHIFT(" type_v " *" a ", " type " " x );
can fail because the array is empty, in which case
.B DAEXC_UFLOW
is thrown.
+.PP
+The operations
+.B DA_FIRST
+and
+.B DA_LAST
+are lvalues referring to the first and last elements in the array
+respectively. They are unsafe if the array is empty.
.SS "Low-level details"
This section describes low-level details of the dynamic array
implementation. You should try to avoid making use of this information