casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Combinatorics.h
Go to the documentation of this file.
1 //# Smooth.h: smooth vectors and arrays
2 //# Copyright (C) 2010 by ESO (in the framework of the ALMA collaboration)
3 //# Copyright (C) 1996,1997,1998,1999,2000,2001
4 //# Associated Universities, Inc. Washington DC, USA.
5 //#
6 //# This library is free software; you can redistribute it and/or modify it
7 //# under the terms of the GNU Library General Public License as published by
8 //# the Free Software Foundation; either version 2 of the License, or (at your
9 //# option) any later version.
10 //#
11 //# This library is distributed in the hope that it will be useful, but WITHOUT
12 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14 //# License for more details.
15 //#
16 //# You should have received a copy of the GNU Library General Public License
17 //# along with this library; if not, write to the Free Software Foundation,
18 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
19 //#
20 //# Correspondence concerning AIPS++ should be addressed as follows:
21 //# Internet email: aips2-request@nrao.edu.
22 //# Postal address: AIPS++ Project Office
23 //# National Radio Astronomy Observatory
24 //# 520 Edgemont Road
25 //# Charlottesville, VA 22903-2475 USA
26 //#
27 //# $Id$
28 
29 #ifndef SCIMATH_COMBINATORICS_H
30 #define SCIMATH_COMBINATORICS_H
31 
32 
33 //# Includes
34 #include <casacore/casa/aips.h>
36 #include <casacore/casa/OS/Mutex.h>
37 
38 namespace casacore { //# NAMESPACE CASACORE - BEGIN
39 
40 // <summary>
41 // Combinatorics related functions.
42 // </summary>
43 
44 // <use visibility=export>
45 
46 //# <author>Dave Mehringer</author>
47 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
48 // </reviewed>
49 
50 // <prerequisite>
51 // <li> <linkto class="Vector">Vector</linkto>
52 // <li> <linkto class="Array">Array</linkto>
53 // </prerequisite>
54 
55 // <etymology>
56 // self-explanatory
57 // </etymology>
58 
59 // <synopsis>
60 // Various factorial and combinatorical functions.
61 // </synopsis>
62 
63 // <motivation>
64 // Binomial coefficients needed for Images/ImageProfileFitter
65 // </motivation>
66 
68 
69  public:
70 
71  // Get n!
72  static uInt factorial(const uInt n)
73  {
74  fillCache(n);
75  return _factorialCache[n];
76  }
77 
78  // "n choose k" = n!/(k!(n-k)!)
79  // Exception is thrown if k > n.
80  static uInt choose(const uInt n, const uInt k);
81 
82  private:
83  static void fillCache(const uInt n);
84 
86  static volatile uInt _factorialCacheSize; //# volatile for double checked lock
87  static Mutex theirMutex;
88 };
89 } //# NAMESPACE CASACORE - END
90 
91 #endif
92 
Combinatorics related functions.
Definition: Combinatorics.h:67
static uInt choose(const uInt n, const uInt k)
&quot;n choose k&quot; = n!/(k!(n-k)!) Exception is thrown if k &gt; n.
static void fillCache(const uInt n)
Wrapper around a pthreads mutex.
Definition: Mutex.h:58
static uInt factorial(const uInt n)
Get n!
Definition: Combinatorics.h:72
static volatile uInt _factorialCacheSize
Definition: Combinatorics.h:86
static Vector< uInt > _factorialCache
Definition: Combinatorics.h:85
unsigned int uInt
Definition: aipstype.h:51
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42