File indexing completed on 2025-02-21 10:03:52
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #ifndef __GSL_PERMUTATION_H__
0021 #define __GSL_PERMUTATION_H__
0022
0023 #include <stdlib.h>
0024 #include <gsl/gsl_types.h>
0025 #include <gsl/gsl_errno.h>
0026 #include <gsl/gsl_inline.h>
0027 #include <gsl/gsl_check_range.h>
0028
0029 #undef __BEGIN_DECLS
0030 #undef __END_DECLS
0031 #ifdef __cplusplus
0032 # define __BEGIN_DECLS extern "C" {
0033 # define __END_DECLS }
0034 #else
0035 # define __BEGIN_DECLS
0036 # define __END_DECLS
0037 #endif
0038
0039 __BEGIN_DECLS
0040
0041 struct gsl_permutation_struct
0042 {
0043 size_t size;
0044 size_t *data;
0045 };
0046
0047 typedef struct gsl_permutation_struct gsl_permutation;
0048
0049 gsl_permutation *gsl_permutation_alloc (const size_t n);
0050 gsl_permutation *gsl_permutation_calloc (const size_t n);
0051 void gsl_permutation_init (gsl_permutation * p);
0052 void gsl_permutation_free (gsl_permutation * p);
0053 int gsl_permutation_memcpy (gsl_permutation * dest, const gsl_permutation * src);
0054
0055 int gsl_permutation_fread (FILE * stream, gsl_permutation * p);
0056 int gsl_permutation_fwrite (FILE * stream, const gsl_permutation * p);
0057 int gsl_permutation_fscanf (FILE * stream, gsl_permutation * p);
0058 int gsl_permutation_fprintf (FILE * stream, const gsl_permutation * p, const char *format);
0059
0060 size_t gsl_permutation_size (const gsl_permutation * p);
0061 size_t * gsl_permutation_data (const gsl_permutation * p);
0062
0063 int gsl_permutation_swap (gsl_permutation * p, const size_t i, const size_t j);
0064
0065 int gsl_permutation_valid (const gsl_permutation * p);
0066 void gsl_permutation_reverse (gsl_permutation * p);
0067 int gsl_permutation_inverse (gsl_permutation * inv, const gsl_permutation * p);
0068 int gsl_permutation_next (gsl_permutation * p);
0069 int gsl_permutation_prev (gsl_permutation * p);
0070 int gsl_permutation_mul (gsl_permutation * p, const gsl_permutation * pa, const gsl_permutation * pb);
0071
0072 int gsl_permutation_linear_to_canonical (gsl_permutation * q, const gsl_permutation * p);
0073 int gsl_permutation_canonical_to_linear (gsl_permutation * p, const gsl_permutation * q);
0074
0075 size_t gsl_permutation_inversions (const gsl_permutation * p);
0076 size_t gsl_permutation_linear_cycles (const gsl_permutation * p);
0077 size_t gsl_permutation_canonical_cycles (const gsl_permutation * q);
0078
0079 INLINE_DECL size_t gsl_permutation_get (const gsl_permutation * p, const size_t i);
0080
0081 #ifdef HAVE_INLINE
0082
0083 INLINE_FUN
0084 size_t
0085 gsl_permutation_get (const gsl_permutation * p, const size_t i)
0086 {
0087 #if GSL_RANGE_CHECK
0088 if (GSL_RANGE_COND(i >= p->size))
0089 {
0090 GSL_ERROR_VAL ("index out of range", GSL_EINVAL, 0);
0091 }
0092 #endif
0093 return p->data[i];
0094 }
0095
0096 #endif
0097
0098 __END_DECLS
0099
0100 #endif