Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /* permutation/gsl_permutation.h
0002  * 
0003  * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2004, 2007 Brian Gough
0004  * 
0005  * This program is free software; you can redistribute it and/or modify
0006  * it under the terms of the GNU General Public License as published by
0007  * the Free Software Foundation; either version 3 of the License, or (at
0008  * your option) any later version.
0009  * 
0010  * This program is distributed in the hope that it will be useful, but
0011  * WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013  * General Public License for more details.
0014  * 
0015  * You should have received a copy of the GNU General Public License
0016  * along with this program; if not, write to the Free Software
0017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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 /* empty */
0036 # define __END_DECLS /* empty */
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 /* HAVE_INLINE */
0097 
0098 __END_DECLS
0099 
0100 #endif /* __GSL_PERMUTATION_H__ */