Combinatorics.h

Go to the documentation of this file.
00001 //# Smooth.h: smooth vectors and arrays 
00002 //# Copyright (C) 2010 by ESO (in the framework of the ALMA collaboration)
00003 //# Copyright (C) 1996,1997,1998,1999,2000,2001
00004 //# Associated Universities, Inc. Washington DC, USA.
00005 //#
00006 //# This library is free software; you can redistribute it and/or modify it
00007 //# under the terms of the GNU Library General Public License as published by
00008 //# the Free Software Foundation; either version 2 of the License, or (at your
00009 //# option) any later version.
00010 //#
00011 //# This library is distributed in the hope that it will be useful, but WITHOUT
00012 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00014 //# License for more details.
00015 //#
00016 //# You should have received a copy of the GNU Library General Public License
00017 //# along with this library; if not, write to the Free Software Foundation,
00018 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00019 //#
00020 //# Correspondence concerning AIPS++ should be addressed as follows:
00021 //#        Internet email: aips2-request@nrao.edu.
00022 //#        Postal address: AIPS++ Project Office
00023 //#                        National Radio Astronomy Observatory
00024 //#                        520 Edgemont Road
00025 //#                        Charlottesville, VA 22903-2475 USA
00026 //#
00027 //# $Id$
00028 
00029 #ifndef SCIMATH_COMBINATORICS_H
00030 #define SCIMATH_COMBINATORICS_H
00031 
00032 
00033 //# Includes
00034 #include <casacore/casa/aips.h>
00035 #include <casacore/casa/Arrays/Vector.h>
00036 #include <casacore/casa/OS/Mutex.h>
00037 
00038 namespace casacore { //# NAMESPACE CASACORE - BEGIN
00039 
00040 // <summary>
00041 // Combinatorics related functions.
00042 // </summary>
00043 
00044 // <use visibility=export>
00045 
00046 //# <author>Dave Mehringer</author>
00047 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00048 // </reviewed>
00049 
00050 // <prerequisite>
00051 //   <li> <linkto class="Vector">Vector</linkto>
00052 //   <li> <linkto class="Array">Array</linkto>
00053 // </prerequisite>
00054 
00055 // <etymology>
00056 // self-explanatory
00057 // </etymology>
00058 
00059 // <synopsis>
00060 // Various factorial and combinatorical functions.
00061 // </synopsis>
00062 
00063 // <motivation>
00064 // Binomial coefficients needed for Images/ImageProfileFitter
00065 // </motivation>
00066 
00067 class Combinatorics {
00068   
00069   public:
00070  
00071   // Get n!
00072   static uInt factorial(const uInt n)
00073   {
00074     //# This test is thread-safe.
00075     if (n >= _factorialCacheSize) fillCache(n);
00076     return _factorialCache[n];
00077   }
00078   
00079   // "n choose k" = n!/(k!(n-k)!)
00080   // Exception is thrown if k > n.
00081   static uInt choose(const uInt n, const uInt k);
00082 
00083   private:
00084   static void fillCache(const uInt n);
00085 
00086   static Vector<uInt> _factorialCache;
00087   static volatile uInt _factorialCacheSize; //# volatile for double checked lock
00088   static Mutex theirMutex;
00089 };
00090 } //# NAMESPACE CASACORE - END
00091 
00092 #endif
00093 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1