next up previous
Next: About this document ...

A Z Specification for a Queue
Eric C. Cyr (ecyr@clemson.edu)

Let $ELEMENT$ be the set of all possible items you want in your queue. Boolean is a place holder for boolean values.
\begin{zed}[ELEMENT]\\
Boolean ::= True \vert False
\end{zed}

This is the schema for Queue. All that Queue contains is a set of partial functione mapping the natural numbers to the items in the queue. The predicate gurantees that the doman of "items" is the emptyset or {1..n} where n is an integer greater then or equal to 1.
\begin{schema}{Queue}
items: \nat \pfun ELEMENT
\where
\forall x:\nat \vert x > 1 @ x \in \dom items \implies x-1 \in \dom items
\end{schema}

The initialize for a Queue, make sure it is empty to begin with.
\begin{schema}{InitQueue}
Queue'
\where
items' = \emptyset
\end{schema}

Return "True" if the priority queue is empty and "False" otherwise.
\begin{schema}{IsEmpty}
\Xi Queue \\
result!: Boolean
\where
result!=True \iff \char93 items = 0 \\
result!=False \iff \char93 items > 0
\end{schema}

The join operation is the similar to what enqueue typically does.
\begin{schema}{Join}
\Delta Queue \\
theItem?: ELEMENT
\where
items' = items \cup \{ \char93 items+1 \mapsto theItem? \}
\end{schema}

The Leave operation is the same as dequeue, it simply returns the value with index 1 and shifts everything down.
\begin{schema}{Leave}
\Delta Queue \\
theItem!: ELEMENT
\where
items \neq \...
...vert x \mapsto y \in items \land x > 1 @ \\
\t1 x-1 \mapsto y ~\}
\end{schema}




Brian Malloy 2002-04-22