File indexing completed on 2025-02-21 10:03:47
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
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
0037 # define __END_DECLS
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))
0081 {
0082 GSL_ERROR_VAL ("index out of range", GSL_EINVAL, 0);
0083 }
0084 #endif
0085 return c->data[i];
0086 }
0087
0088 #endif
0089
0090 __END_DECLS
0091
0092 #endif