Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 10:03:47

0001 /* combination/gsl_combination.h
0002  * based on permutation/gsl_permutation.h by Brian Gough
0003  * 
0004  * Copyright (C) 2001 Szymon Jaroszewicz
0005  * 
0006  * This program is free software; you can redistribute it and/or modify
0007  * it under the terms of the GNU General Public License as published by
0008  * the Free Software Foundation; either version 3 of the License, or (at
0009  * your option) any later version.
0010  * 
0011  * This program is distributed in the hope that it will be useful, but
0012  * WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014  * General Public License for more details.
0015  * 
0016  * You should have received a copy of the GNU General Public License
0017  * along with this program; if not, write to the Free Software
0018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0019  */
0020 
0021 #ifndef __GSL_COMBINATION_H__
0022 #define __GSL_COMBINATION_H__
0023 
0024 #include <stdlib.h>
0025 #include <gsl/gsl_errno.h>
0026 #include <gsl/gsl_types.h>
0027 #include <gsl/gsl_inline.h>
0028 #include <gsl/gsl_check_range.h>
0029 
0030 #undef __BEGIN_DECLS
0031 #undef __END_DECLS
0032 #ifdef __cplusplus
0033 # define __BEGIN_DECLS extern "C" {
0034 # define __END_DECLS }
0035 #else
0036 # define __BEGIN_DECLS /* empty */
0037 # define __END_DECLS /* empty */
0038 #endif
0039 
0040 __BEGIN_DECLS
0041 
0042 struct gsl_combination_struct
0043 {
0044   size_t n;
0045   size_t k;
0046   size_t *data;
0047 };
0048 
0049 typedef struct gsl_combination_struct gsl_combination;
0050 
0051 gsl_combination *gsl_combination_alloc (const size_t n, const size_t k);
0052 gsl_combination *gsl_combination_calloc (const size_t n, const size_t k);
0053 void gsl_combination_init_first (gsl_combination * c);
0054 void gsl_combination_init_last (gsl_combination * c);
0055 void gsl_combination_free (gsl_combination * c);
0056 int gsl_combination_memcpy (gsl_combination * dest, const gsl_combination * src); 
0057 
0058 int gsl_combination_fread (FILE * stream, gsl_combination * c);
0059 int gsl_combination_fwrite (FILE * stream, const gsl_combination * c);
0060 int gsl_combination_fscanf (FILE * stream, gsl_combination * c);
0061 int gsl_combination_fprintf (FILE * stream, const gsl_combination * c, const char *format);
0062 
0063 size_t gsl_combination_n (const gsl_combination * c);
0064 size_t gsl_combination_k (const gsl_combination * c);
0065 size_t * gsl_combination_data (const gsl_combination * c);
0066 
0067 int gsl_combination_valid (gsl_combination * c);
0068 int gsl_combination_next (gsl_combination * c);
0069 int gsl_combination_prev (gsl_combination * c);
0070 
0071 INLINE_DECL size_t gsl_combination_get (const gsl_combination * c, const size_t i);
0072 
0073 #ifdef HAVE_INLINE
0074 
0075 INLINE_FUN
0076 size_t
0077 gsl_combination_get (const gsl_combination * c, const size_t i)
0078 {
0079 #if GSL_RANGE_CHECK
0080   if (GSL_RANGE_COND(i >= c->k)) /* size_t is unsigned, can't be negative */
0081     {
0082       GSL_ERROR_VAL ("index out of range", GSL_EINVAL, 0);
0083     }
0084 #endif
0085   return c->data[i];
0086 }
0087 
0088 #endif /* HAVE_INLINE */
0089 
0090 __END_DECLS
0091 
0092 #endif /* __GSL_COMBINATION_H__ */