container::SortedArrayList Class Reference

An array implementation of SortedList. More...

#include <sortedarraylist.h>

Inheritance diagram for container::SortedArrayList:

Inheritance graph
[legend]
Collaboration diagram for container::SortedArrayList:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 SortedArrayList ()
 SortedArrayList (const SortedArrayList &pattern)
virtual ~SortedArrayList ()
virtual ostream & renderState (ostream &os) const
 Write the state of an Object for debugging and demonstration.
virtual const InfotypeInfo () const
 Return the instance of Object::Info that describes the class of this object.
virtual Objectclone (bool deepCopy=false) const
 A polymorphic copy constructor.

Static Public Attributes

static const Info *const TYPE_INFO

Protected Member Functions

virtual bool insertSorted_impl (Entity *entity)
 Called by a template method.
virtual void locateEntity (const Entity &key, int &index, Entity *&entity)
 Uses a binary search to locate the Entity object with the given key.
virtual bool add_impl (Entity *entity)
 Called by a template method.

Private Member Functions

bool binarySearch (const Entity &key, int &index) const
 Locate the Entity with the matching key using a binary search algorithm.


Detailed Description

An array implementation of SortedList.

Constructor & Destructor Documentation

container::SortedArrayList::SortedArrayList (  ) 

00048 { }

container::SortedArrayList::SortedArrayList ( const SortedArrayList pattern  ) 

00050 { }

container::SortedArrayList::~SortedArrayList (  )  [virtual]

00052 { }


Member Function Documentation

bool container::SortedArrayList::add_impl ( Entity entity  )  [protected, virtual]

Called by a template method.

See also:
Details documented in List::add

Implements container::List.

00104                                              {
00105    return insertSorted_impl(entity);
00106 }

Here is the call graph for this function:

bool container::SortedArrayList::binarySearch ( const Entity key,
int &  index 
) const [private]

Locate the Entity with the matching key using a binary search algorithm.

Returns:
true if found, false other wise

index will point to the Entity if found, otherwise index will point to where the key belongs if the corresponding Entity object were to be inserted

00056                                                                       {
00057    int tIndex = BASE_INDEX;
00058    int bIndex = getCount() - 1;
00059    index = BASE_INDEX; // default to first element for empty list
00060 
00061    for (int range = bIndex - tIndex; range >= 0; range = bIndex - tIndex) {
00062       index = (range / 2) + tIndex;
00063 
00064       int delta = key.compareKeyTo(*array[index]);
00065       if (delta > 0) {
00066          tIndex = ++index;
00067       } else if (delta < 0) {
00068          bIndex = index - 1;
00069       } else {
00070          return true;
00071       }
00072    }
00073 
00074    return false;
00075 }

Here is the call graph for this function:

Here is the caller graph for this function:

Object * container::SortedArrayList::clone ( bool  deepCopy = false  )  const [virtual]

A polymorphic copy constructor.

Implements container::ArrayList.

00118 { }

bool container::SortedArrayList::insertSorted_impl ( Entity entity  )  [protected, virtual]

Called by a template method.

See also:
Details documented in SortedList::insertSorted

Implements container::SortedList.

00079                                                       {
00080    int targetIndex = 0;
00081    if (binarySearch(*entity, targetIndex)) {
00082       return false;
00083    }
00084    openGap(targetIndex);
00085    array[targetIndex] = entity;
00086    return true;
00087 }

Here is the call graph for this function:

Here is the caller graph for this function:

void container::SortedArrayList::locateEntity ( const Entity key,
int &  index,
Entity *&  entity 
) [protected, virtual]

Uses a binary search to locate the Entity object with the given key.

Overrides the implementation in ArrayList. Uses a binary search for optimization.

See also:
List::locateEntity for method contract

Reimplemented from container::ArrayList.

00091                                                                                  {
00092    int i = 0;
00093    if (binarySearch(key, i)) {
00094       index = i;
00095       entity = array[i];
00096    } else {
00097       index = NO_MATCHING_ENTITY_INDEX_FLAG;
00098       entity = NULL;
00099    }
00100 }

Here is the call graph for this function:

ostream & container::SortedArrayList::renderState ( ostream &  os  )  const [virtual]

Write the state of an Object for debugging and demonstration.

This method must not change the state of an Object; adding or removing debug statements should not change the behavior of a class. The implementation must be robust, e.g., NULL safe, etc. and work without an unrecoverable error for any state, excluding an Object's time of construction and destruction. It is not required for the implementation to be thread safe.

Precondition:
The Object has been fully constructed and is not in the process of destruction
Postcondition:
The state of the Object is unchanged

Reimplemented from container::ArrayList.

00110                                                         {
00111    return this->ArrayList::renderState(os);
00112 }

const Object::Info * container::SortedArrayList::typeInfo (  )  const [virtual]

Return the instance of Object::Info that describes the class of this object.

Instantiation of Object::Info is controlled by the protected method Object::typeInfoFactory(const string&). Each sub-class of Object should create one and only one instance of Object::Info.

Reimplemented from container::ArrayList.

00114                                                   {
00115    return TYPE_INFO;
00116 }


Member Data Documentation

Initial value:

      Object::typeInfoFactory("SortedArrayList")

Reimplemented from container::ArrayList.


The documentation for this class was generated from the following files:

Generated on Tue Jun 16 23:13:00 2009 by  doxygen 1.5.9