CoCoALib-0.9905 date: 23 May 2007


DivMask.H

Go to the documentation of this file.
00001 #ifndef CoCoA_DivMask_H
00002 #define CoCoA_DivMask_H
00003 
00004 //   Copyright (c)  2005  John Abbott
00005 
00006 //   This file is part of the source of CoCoALib, the CoCoA Library.
00007 
00008 //   CoCoALib is free software; you can redistribute it and/or modify
00009 //   it under the terms of the GNU General Public License (version 2)
00010 //   as published by the Free Software Foundation.  A copy of the full
00011 //   licence may be found in the file COPYING in this directory.
00012 
00013 //   CoCoALib is distributed in the hope that it will be useful,
00014 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 //   GNU General Public License for more details.
00017 
00018 //   You should have received a copy of the GNU General Public License
00019 //   along with CoCoA; if not, write to the Free Software
00020 //   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 
00022 
00023 #include "CoCoA/config.H"
00024 #include "CoCoA/SmartPtrIRC.H"
00025 
00026 #include <cstddef>
00027 // using std::size_t;
00028 #include <bitset>
00029 //using std::bitset;
00030 #include <iosfwd>
00031 //using std::ostream;
00032 
00033 namespace CoCoA
00034 {
00035 
00036   class DivMaskRuleBase; // forward declaration for use in friend declaration
00037 
00038   //-- class DivMask -----------------------------------------
00039   /**
00040 
00041   \brief Implementation of DivMask for fast divisibility test
00042 
00043   DivMask implements a generalization of the present/absent bitset of a PP
00044   for fast divisibility tests.
00045   It is represented as a bitset whose size must be defined at compile-time
00046   for efficiency (its main reason for existence!) and it must satisfy:
00047 
00048       pp1 | pp2  ==> dm1 | dm2      ( lcm(pp1,pp2)=pp2  ==> dm1 && dm2 = dm2 )
00049 
00050   See DivMaskRuleBase.
00051   */
00052   //-----------------------------------------------------------------
00053 
00054   class DivMask
00055   {
00056   public:
00057     static const std::size_t MaskWidth = 32;  // MaskWidth must be a power of 2.
00058     typedef std::bitset<MaskWidth> mask_t;
00059   public:
00060     // Default ctor, copy ctor, assignment and dtor are OK.
00061     friend const mask_t bits(const DivMask& dm);
00062   private: // data members
00063     friend class DivMaskRuleBase; // see mem.fn. DivMaskRuleBase::myBits
00064     mask_t myBits;
00065   };
00066 
00067   std::ostream& operator<<(std::ostream& out, const DivMask& dm);
00068 
00069   /*-----------------------------------------------------------------*/
00070   /** \include DivMask.txt  */
00071   /*-----------------------------------------------------------------*/
00072   class DivMaskRule
00073   {
00074   public:
00075     explicit DivMaskRule(const DivMaskRuleBase* DMRPtr): mySmartPtr(DMRPtr) {}
00076     // assignment disabled because SmartPtrIRC has no assignment
00077     const DivMaskRuleBase* operator->() const { return mySmartPtr.operator->(); }  ///< Allow const member fns to be called.
00078     bool operator==(const DivMaskRule& DMR) const { return mySmartPtr==DMR.mySmartPtr; }
00079   private: // data members
00080     SmartPtrIRC<const DivMaskRuleBase> mySmartPtr;
00081   };
00082 
00083 
00084   class DivMaskRuleBase: protected IntrusiveReferenceCount
00085   {
00086     friend class SmartPtrIRC<const DivMaskRuleBase>; // morally "friend DivMaskRule", so it can alter reference count
00087   protected:
00088     DivMaskRuleBase(): IntrusiveReferenceCount() {};
00089     // Copy ctor and assignment disabled (see below).
00090     virtual ~DivMaskRuleBase() {};
00091   public:
00092     virtual void myAssignFromExpv(DivMask& dm, const SmallExponent_t* expv, std::size_t NumIndets) const = 0;
00093 //???    virtual void myAssignFromExpv(DivMask& dm, const std::vector<long>& expv) const = 0;
00094 //???    virtual void myAssignFromExpv(DivMask& dm, const std::vector<ZZ>& EXPV) const = 0;
00095     virtual void myOutputSelf(std::ostream& out) const = 0;
00096 //????    virtual void myOutputSelf(OpenMath::OutputChannel& OMOut) const = 0;
00097   private: // Disable copy ctor and assignment.
00098     DivMaskRuleBase(const DivMaskRuleBase&);            ///< NEVER DEFINED -- copy ctor disabled
00099     DivMaskRuleBase& operator=(const DivMaskRuleBase&); ///< NEVER DEFINED -- assignment disabled
00100   protected:
00101     DivMask::mask_t& myBits(DivMask& dm) const; ///< WRITE ACCESS to the bitset for derived concrete classes
00102   };
00103 
00104 
00105   std::ostream& operator<<(std::ostream& out, const DivMaskRule& DMR);
00106 
00107   DivMaskRule NewDivMaskNull();
00108   DivMaskRule NewDivMaskSingleBit();
00109   DivMaskRule NewDivMaskSingleBitWrap();
00110   DivMaskRule NewDivMaskEvenPowers();
00111   DivMaskRule NewDivMaskHashing();
00112 
00113 
00114   //----------------------------------------------------------------------
00115   // Inline functions -- as always, be wary of changing the order!
00116 
00117   inline const DivMask::mask_t bits(const DivMask& dm)
00118   {
00119     return dm.myBits;
00120   }
00121 
00122   inline bool operator==(const DivMask& dm1, const DivMask& dm2)
00123   {
00124     return bits(dm1) == bits(dm2);
00125   }
00126 
00127   inline bool operator!=(const DivMask& dm1, const DivMask& dm2)
00128   {
00129     return !(dm1 == dm2);
00130   }
00131 
00132 
00133   inline bool IsSubset(const DivMask& dm1, const DivMask& dm2)  // is dm1 subset of dm2?
00134   {
00135     return (bits(dm1) & bits(dm2)) == bits(dm1);
00136   }
00137 
00138 
00139   // This is like bits(dm) but gives write access to the bitset.
00140   inline DivMask::mask_t& DivMaskRuleBase::myBits(DivMask& dm) const
00141   {
00142     return dm.myBits;
00143   }
00144 
00145 
00146 } // end of namespace CoCoA
00147 
00148 
00149 
00150 // RCS header/log in the next few lines
00151 // $Header: /Volumes/Home/cocoa/cvs-repository/CoCoALib-0.99/include/CoCoA/DivMask.H,v 1.1.1.1 2007/03/09 15:16:11 abbott Exp $
00152 // $Log: DivMask.H,v $
00153 // Revision 1.1.1.1  2007/03/09 15:16:11  abbott
00154 // Imported files
00155 //
00156 // Revision 1.8  2007/03/08 18:42:06  cocoa
00157 // Cleaned up whitespace.
00158 //
00159 // Revision 1.7  2006/11/29 17:26:58  cocoa
00160 // -- just shortened the log
00161 //
00162 // Revision 1.6  2006/11/23 17:06:55  cocoa
00163 // -- changed: DivMaskRule is now a class (instead of typedef)
00164 //
00165 // Revision 1.5  2006/11/16 16:08:21  cocoa
00166 // -- changed: DivMaskRuleBase ctor and dtor are now protected
00167 //
00168 // Revision 1.4  2006/11/02 13:25:44  cocoa
00169 // Simplification of header files: the OpenMath classes have been renamed.
00170 // Many minor consequential changes.
00171 //
00172 // Revision 1.3  2006/10/06 14:04:16  cocoa
00173 // Corrected position of #ifndef in header files.
00174 // Separated CoCoA_ASSERT into assert.H from config.H;
00175 // many minor consequential changes (have to #include assert.H).
00176 // A little tidying of #include directives (esp. in Max's code).
00177 //
00178 // Revision 1.2  2006/08/07 21:23:25  cocoa
00179 // Removed almost all publicly visible references to SmallExponent_t;
00180 // changed to long in all PPMonoid functions and SparsePolyRing functions.
00181 // DivMask remains to sorted out.
00182 //
00183 // Revision 1.1.1.1  2006/05/30 11:39:36  cocoa
00184 // Imported files
00185 //
00186 
00187 #endif

Generated on Wed May 23 13:45:22 2007 for CoCoALib by  doxygen 1.4.6