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

DenseIntVectSet.H

Go to the documentation of this file.
00001 /* _______              __
00002   / ___/ /  ___  __ _  / /  ___
00003  / /__/ _ \/ _ \/  ' \/ _ \/ _ \
00004  \___/_//_/\___/_/_/_/_.__/\___/ 
00005 */
00006 //
00007 // This software is copyright (C) by the Lawrence Berkeley
00008 // National Laboratory.  Permission is granted to reproduce
00009 // this software for non-commercial purposes provided that
00010 // this notice is left intact.
00011 // 
00012 // It is acknowledged that the U.S. Government has rights to
00013 // this software under Contract DE-AC03-765F00098 between
00014 // the U.S.  Department of Energy and the University of
00015 // California.
00016 //
00017 // This software is provided as a professional and academic
00018 // contribution for joint exchange. Thus it is experimental,
00019 // is provided ``as is'', with no warranties of any kind
00020 // whatsoever, no support, no promise of updates, or printed
00021 // documentation. By using this software, you acknowledge
00022 // that the Lawrence Berkeley National Laboratory and
00023 // Regents of the University of California shall have no
00024 // liability with respect to the infringement of other
00025 // copyrights by any part of this software.
00026 //
00027 
00028 #include "BitSet.H"
00029 #include "IntVect.H"
00030 #include "Box.H"
00031 #include "Vector.H"
00032 #include "ProblemDomain.H"
00033 
00034 class ProblemDomain;
00035 class DenseIntVectSetIterator;
00037 
00041 class DenseIntVectSet
00042 {
00043 public:
00045   DenseIntVectSet(){;}
00046 
00048 
00049   DenseIntVectSet(const Box& a_domain, bool init = true);
00050   // copy, and operator= should be fine
00051 
00053 
00056   DenseIntVectSet& operator-=(const Box& box);
00057 
00059 
00062   DenseIntVectSet& operator-=(const IntVect& intvect);
00063 
00065 
00068   DenseIntVectSet& operator-=(const DenseIntVectSet& ivs);
00069 
00071 
00074   DenseIntVectSet& operator&=(const Box& box);
00075  
00077 
00080   DenseIntVectSet& operator&=(const ProblemDomain& domain);
00081 
00083 
00088   DenseIntVectSet& operator|=(const IntVect& intvect);
00089 
00091 
00096   DenseIntVectSet& operator|=(const Box& b);
00097 
00099 
00104   DenseIntVectSet& operator|=(const DenseIntVectSet& b);
00105 
00107 
00110   DenseIntVectSet& operator&=(const DenseIntVectSet& ivs);
00111 
00113 
00116   void shift(const IntVect& iv);
00117 
00118   //
00119   /* slower, constant time pointwise access.
00120      You should not build a BoxIterator, then access this
00121      method if you intend to iterate over the objects true
00122      or false terms.  you should build a DenseIntVectSetIterator */
00123   bool operator[](const IntVect& index) const;
00124 
00126 
00128   bool contains(const Box& box) const;
00129 
00131 
00134   void coarsen(int iref);
00135 
00137 
00140   void refine(int iref);
00141 
00143 
00146   void grow(int igrow);
00147 
00149 
00152   void grow(int idir, int igrow);
00153 
00155 
00160   DenseIntVectSet chop(int dir, int chop_pnt);
00161 
00162   inline const Box& box() const;
00163 
00165 
00167   void nestingRegion(int a_radius, const Box& a_domain);
00168 
00170 
00172   void nestingRegion(int a_radius, const ProblemDomain& a_domain);
00173 
00175 
00178   bool isEmpty() const; //cheaper than numPts by wide margin
00179 
00181 
00184   bool isFull() const;  // cheaper than numPts, bu significant margin
00185 
00187 
00190   int  numPts() const;
00191 
00193 
00196   Vector<Box> createBoxes() const;
00198 
00202   void compact() const ; 
00203 
00204 private:
00205 
00206   void grow(const IntVect& iv);
00207   // version without checking intersect or empty
00208   DenseIntVectSet& intersect(const DenseIntVectSet& rhs);
00209   Box m_domain;
00210   BitSet m_bits;
00211   friend class DenseIntVectSetIterator;
00212 };
00213 
00215 
00217 class DenseIntVectSetIterator
00218 {
00219 public:
00220 
00222   DenseIntVectSetIterator();
00223 
00225   DenseIntVectSetIterator(const DenseIntVectSet& ivs);
00226 
00228   void define(const DenseIntVectSet& ivs);
00229   //default null, assignment, copy and destructor should work fine.
00230 
00232   const IntVect& operator()() const ;
00233 
00235   bool ok() const;
00236 
00238   void operator++();
00239 
00241   void begin();
00242 
00244   void end();
00245 
00246   static DenseIntVectSet    emptyDenseIntVectSet;
00247 
00248 private:
00249   BitSetIterator m_iterator;
00250   IntVect        m_current;
00251   const DenseIntVectSet*    m_ivsPtr;
00252   int isize, ijsize, bigi, bigj;
00253 
00254   void nextIntVect();
00255   void nextIntVect(int skip);
00256 
00257 };
00258 
00259 //===================================================================
00260 
00261 // inline functions
00262 
00263 
00264 inline
00265 const Box& DenseIntVectSet::box() const { return m_domain;}
00266 
00267 
00268 
00269 inline
00270 DenseIntVectSet& DenseIntVectSet::operator-=(const IntVect& intvect)
00271 {
00272   if(m_domain.contains(intvect))
00273     m_bits.setFalse(m_domain.index(intvect));
00274   return *this;
00275 }
00276 
00277 inline void DenseIntVectSet::shift(const IntVect& iv)
00278 {
00279   m_domain.shift(iv);
00280 }
00281 
00282 inline
00283 DenseIntVectSetIterator::DenseIntVectSetIterator()
00284   : m_ivsPtr(&emptyDenseIntVectSet)
00285 {
00286   ;
00287 }
00288 
00289 inline
00290 void DenseIntVectSetIterator::define(const DenseIntVectSet& ivs)
00291 {
00292   m_ivsPtr = &ivs;
00293   begin();
00294 }
00295 
00296 inline
00297 DenseIntVectSetIterator::DenseIntVectSetIterator(const DenseIntVectSet& ivs)
00298   : m_ivsPtr(&ivs)
00299 {
00300   begin();
00301 }
00302 
00303 inline
00304 const IntVect& DenseIntVectSetIterator::operator()() const
00305 {
00306   return m_current;
00307 }
00308 
00309 inline
00310 bool DenseIntVectSetIterator::ok() const
00311 {
00312   return m_iterator.ok();
00313 }
00314 
00315 
00316 inline 
00317 void DenseIntVectSetIterator::end()
00318 {
00319   m_iterator.end();
00320 }
00321 
00322 //  inline 
00323 //  void DenseIntVectSetIterator::operator++()
00324 //  {
00325 //    ++m_iterator;
00326 //    nextIntVect();
00327 //    while(!m_iterator() && m_iterator.ok())
00328 //      {
00329 //        ++m_iterator; // next bit please
00330 //        nextIntVect();
00331 //      }
00332 //  }
00333 inline 
00334 void DenseIntVectSetIterator::operator++()
00335 {
00336   ++m_iterator;
00337   int i=1;
00338   while(m_iterator.ok() && !m_iterator())
00339     {
00340       ++m_iterator; // next bit please
00341       ++i;
00342     }
00343   nextIntVect(i);
00344 }

Generated on Thu Aug 29 11:05:44 2002 for Chombo&INS by doxygen1.2.16