Algorithm
Development Kit 1.0

algs.model.searchtree.states
Class StateQueue

java.lang.Object
  extended by algs.model.searchtree.states.StateQueue
All Implemented Interfaces:
INodeSet

public class StateQueue
extends java.lang.Object
implements INodeSet

Provide storage that behaves like a queue. INodeSet.insert(INode) and INodeSet.remove() are constant time operations. However, INodeSet.contains(INode) becomes O(n) since the entire queue must be inspected. Finally, INodeSet.remove(INode) is O(n) since whole queue must be searched.

Since:
1.0
Version:
1.0, 6/15/08
Author:
George Heineman

Constructor Summary
StateQueue()
           
 
Method Summary
 INode contains(INode n)
          Return the actual node in storage that is equal to the given node.
 void insert(INode n)
          Insert node places at end of queue.
 boolean isEmpty()
          Is collection empty.
 java.util.Iterator<INode> iterator()
          Return iterator to the existing board states.
 INode remove()
          Remove a node by taking the first one from the queue.
 boolean remove(INode n)
          Remove actual value from the set.
 int size()
          Return the number of states in the set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StateQueue

public StateQueue()
Method Detail

isEmpty

public boolean isEmpty()
Description copied from interface: INodeSet
Is collection empty.

Specified by:
isEmpty in interface INodeSet

size

public int size()
Description copied from interface: INodeSet
Return the number of states in the set.

Specified by:
size in interface INodeSet

iterator

public java.util.Iterator<INode> iterator()
Description copied from interface: INodeSet
Return iterator to the existing board states.

Specified by:
iterator in interface INodeSet

insert

public void insert(INode n)
Insert node places at end of queue.

Specified by:
insert in interface INodeSet
Parameters:
n - INode to be inserted into the set.

remove

public INode remove()
Remove a node by taking the first one from the queue.

Specified by:
remove in interface INodeSet

contains

public INode contains(INode n)
Description copied from interface: INodeSet
Return the actual node in storage that is equal to the given node.

The signature of this method may look odd. Recall that If the node doesn't exist then return null.

Specified by:
contains in interface INodeSet
Parameters:
n - Board state to be inspected

remove

public boolean remove(INode n)
Remove actual value from the set.

An existing INode in the set that .equals(n) is selected for removal.

Specified by:
remove in interface INodeSet
Parameters:
n - the node representing the value to be removed from the list.
See Also:
INodeSet.remove(INode)

Algorithm Development Kit 1.0

This code supports the Algorithms in a Nutshell book, published by O'Reilly Media, Inc. in November 2008. Please visit the book web page to learn of any changes to the code repository or to record a potential defect.