Back to home page

EIC code displayed by LXR

 
 

    


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

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