Add macros to use a pdeq as a stack
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Mon, 29 May 2006 13:33:26 +0000 (13:33 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Mon, 29 May 2006 13:33:26 +0000 (13:33 +0000)
[r7813]

ir/adt/pdeq.h

index e2107bc..d15c458 100644 (file)
@@ -212,4 +212,47 @@ typedef pdeq waitq;
  */
 #define waitq_empty(wq) pdeq_empty(wq)
 
+/**
+ * The pdeq can be used as a stack. A helper
+ * type to support this.
+ */
+typedef pdeq stack;
+
+/**
+ * Creates a new pointer stack (lifo).
+ *
+ * @return A new stack.
+ */
+#define new_stack()  new_pdeq()
+
+/**
+ * Pop a pointer from the stack (lifo).
+ *
+ * @param st   The stack.
+ *
+ * @return The pointer element.
+ *
+ * @remark This function will fail if the stack is empty.
+ */
+#define stack_pop(st)  pdeq_getr(st)
+
+/**
+ * Push a pointer to the stack (lifo).
+ *
+ * @param st  The stack.
+ * @param x   The pointer element to be added
+ *
+ * @return The stack.
+ */
+#define stack_push(st, x) pdeq_putr((st), (x))
+
+/**
+ * Checks if a stack is empty.
+ *
+ * @param st   The stack.
+ *
+ * @return  non-zero if the stack is empty.
+ */
+#define stack_empty(st) pdeq_empty(wq)
+
 #endif /* _PDEQ_H_ */