Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

SortedArray< Elem > Class Template Reference

#include <SortedArray.h>

Inheritance diagram for SortedArray< Elem >:

SortableResizeArray< Elem > ResizeArray< Elem > UniqueSortedArray< Elem > List of all members.

Public Member Functions

 SortedArray (void)
 SortedArray (int s)
 SortedArray (SortedArray< Elem > &sa)
 SortedArray (SortableResizeArray< Elem > &ra)
SortedArray< Elem > & operator= (SortedArray< Elem > &sa)
SortedArray< Elem > & operator= (SortableResizeArray< Elem > &ra)
int load (const Elem &elem)
int add (const Elem &elem)
int del (const Elem &elem)
void sort (void)
int bsearch (const Elem &elem)
int insert (const Elem &elem)
int index (const Elem &elem)
Elem * find (const Elem &elem)
Elem * find (void)

Protected Attributes

int found
int isSorted

Detailed Description

template<class Elem>
class SortedArray< Elem >

Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000 by The Board of Trustees of the University of Illinois. All rights reserved.

Definition at line 12 of file SortedArray.h.


Constructor & Destructor Documentation

template<class Elem>
SortedArray< Elem >::SortedArray void   )  [inline]
 

Definition at line 21 of file SortedArray.h.

00021                       : SortableResizeArray<Elem>() { 
00022       found = -1; isSorted = 1;
00023     }

template<class Elem>
SortedArray< Elem >::SortedArray int  s  )  [inline]
 

Definition at line 25 of file SortedArray.h.

00025                        : SortableResizeArray<Elem>(s) { 
00026       found = -1; isSorted = 1;
00027     }

template<class Elem>
SortedArray< Elem >::SortedArray SortedArray< Elem > &  sa  )  [inline]
 

Definition at line 29 of file SortedArray.h.

00029                                        : SortableResizeArray<Elem>(sa) { 
00030       found = -1; if(!(isSorted = sa.isSorted)) sort();
00031       isSorted = 1;
00032     }

template<class Elem>
SortedArray< Elem >::SortedArray SortableResizeArray< Elem > &  ra  )  [inline]
 

Definition at line 34 of file SortedArray.h.

00034                                                : 
00035         SortableResizeArray<Elem>(ra) {
00036       found = -1; sort(); isSorted = 1;
00037     }


Member Function Documentation

template<class Elem>
int SortedArray< Elem >::add const Elem &  elem  )  [inline]
 

Reimplemented from ResizeArray< Elem >.

Reimplemented in UniqueSortedArray< Elem >, and UniqueSortedArray< PatchElem >.

Definition at line 56 of file SortedArray.h.

Referenced by Patch::registerForceDeposit(), and Patch::registerPositionPickup().

00056                               {
00057       return(insert(elem));
00058     }

template<class Elem>
int SortedArray< Elem >::bsearch const Elem &  elem  )  [inline]
 

Definition at line 72 of file SortedArray.h.

Referenced by SortedArray< PatchElem >::del(), SortedArray< Elem >::find(), SortedArray< PatchElem >::index(), UniqueSortedArray< Elem >::insert(), and SortedArray< Elem >::insert().

00072                                   { 
00073       if (!isSorted) sort();
00074       return (SortableResizeArray<Elem>::bsearch(elem));
00075     }

template<class Elem>
int SortedArray< Elem >::del const Elem &  elem  )  [inline]
 

Definition at line 60 of file SortedArray.h.

Referenced by GlobalMasterIMD::get_vmd_forces(), PatchMgr::sendMovePatches(), PatchMgr::sendOneHomePatch(), Patch::unregisterForceDeposit(), and Patch::unregisterPositionPickup().

00060                                {
00061       found = bsearch(elem);
00062       if (this->size() != 0 && (*(this->rep))[found] == elem) {
00063         return(SortableResizeArray<Elem>::del(found,1));
00064       } else {
00065         found = -1;
00066         return(-1);
00067       }
00068     }

template<class Elem>
Elem* SortedArray< Elem >::find void   )  [inline]
 

Definition at line 83 of file SortedArray.h.

00083                       {
00084       if (found < 0 || ++found >= this->size()) {
00085         return((Elem *)NULL);
00086       }
00087       else if ((*(this->rep))[found] == (*(this->rep))[found-1]) {
00088          return (&(*(this->rep))[found]);
00089       } else {
00090         return ((Elem *)NULL);
00091       }
00092     }

template<class Elem>
Elem * SortedArray< Elem >::find const Elem &  elem  )  [inline]
 

Reimplemented from ResizeArray< Elem >.

Definition at line 109 of file SortedArray.h.

References SortedArray< Elem >::bsearch(), and SortedArray< Elem >::found.

Referenced by GlobalMasterIMD::get_vmd_forces(), PatchMgr::homePatch(), and PatchMgr::~PatchMgr().

00109                                                       {
00110   if ( (found = bsearch(elem)) < 0) 
00111     return ((Elem *)NULL);
00112   if ((*(this->rep))[found] == elem) {
00113     return (&(*(this->rep))[found]);
00114   } else {
00115     found = -1;
00116     return ((Elem *)NULL);
00117   }
00118 }

template<class Elem>
int SortedArray< Elem >::index const Elem &  elem  )  [inline]
 

Definition at line 79 of file SortedArray.h.

Referenced by GlobalMasterIMD::calculate().

00079 { return(found = bsearch(elem)); }

template<class Elem>
int SortedArray< Elem >::insert const Elem &  elem  )  [inline]
 

Reimplemented in UniqueSortedArray< Elem >, and UniqueSortedArray< PatchElem >.

Definition at line 96 of file SortedArray.h.

References SortedArray< Elem >::bsearch(), SortedArray< Elem >::found, ResizeArray< Elem >::insert(), and ResizeArray< Elem >::size().

Referenced by SortedArray< PatchElem >::add().

00096                                                      {
00097   found = bsearch(elem);
00098   if (found == -1) {
00099     return (ResizeArray<Elem>::insert(elem, 0));
00100   }
00101   if (found == (this->size()-1) && (*(this->rep))[found] < elem) {
00102     return (ResizeArray<Elem>::insert(elem, this->size()));
00103   } else {
00104     return (ResizeArray<Elem>::insert(elem, found));
00105   }
00106 }

template<class Elem>
int SortedArray< Elem >::load const Elem &  elem  )  [inline]
 

Definition at line 51 of file SortedArray.h.

Referenced by PatchMgr::createHomePatch(), PatchMgr::movePatch(), and PatchMgr::preCreateHomePatch().

00051                                {
00052       isSorted = 0;
00053       return(ResizeArray<Elem>::add(elem));
00054     }

template<class Elem>
SortedArray<Elem>& SortedArray< Elem >::operator= SortableResizeArray< Elem > &  ra  )  [inline]
 

Reimplemented from SortableResizeArray< Elem >.

Definition at line 45 of file SortedArray.h.

00045                                                                  {
00046       SortableResizeArray<Elem>::operator=(ra);
00047       found = -1; sort(); isSorted = 1;
00048       return(*this);
00049     }

template<class Elem>
SortedArray<Elem>& SortedArray< Elem >::operator= SortedArray< Elem > &  sa  )  [inline]
 

Reimplemented in UniqueSortedArray< Elem >, and UniqueSortedArray< PatchElem >.

Definition at line 39 of file SortedArray.h.

Referenced by UniqueSortedArray< PatchElem >::operator=().

00039                                                           {
00040       SortableResizeArray<Elem>::operator=(sa);
00041       found = -1; isSorted = sa.isSorted;
00042       return(*this);
00043     }

template<class Elem>
void SortedArray< Elem >::sort void   )  [inline]
 

Reimplemented from SortableResizeArray< Elem >.

Definition at line 70 of file SortedArray.h.

Referenced by SortedArray< PatchElem >::bsearch(), SortedArray< PatchElem >::operator=(), and SortedArray< PatchElem >::SortedArray().


Member Data Documentation

template<class Elem>
int SortedArray< Elem >::found [protected]
 

Definition at line 16 of file SortedArray.h.

Referenced by SortedArray< Elem >::find(), and SortedArray< Elem >::insert().

template<class Elem>
int SortedArray< Elem >::isSorted [protected]
 

Definition at line 17 of file SortedArray.h.

Referenced by SortedArray< PatchElem >::operator=(), and SortedArray< PatchElem >::SortedArray().


The documentation for this class was generated from the following file:
Generated on Sun Jul 6 04:07:48 2008 for NAMD by  doxygen 1.3.9.1