gsl_combination.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* combination/gsl_combination.h
  2. * based on permutation/gsl_permutation.h by Brian Gough
  3. *
  4. * Copyright (C) 2001 Szymon Jaroszewicz
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. #ifndef __GSL_COMBINATION_H__
  21. #define __GSL_COMBINATION_H__
  22. #include <stdlib.h>
  23. #include "gsl_errno.h"
  24. #include "gsl_types.h"
  25. #include "gsl_check_range.h"
  26. #undef __BEGIN_DECLS
  27. #undef __END_DECLS
  28. #ifdef __cplusplus
  29. # define __BEGIN_DECLS extern "C" {
  30. # define __END_DECLS }
  31. #else
  32. # define __BEGIN_DECLS /* empty */
  33. # define __END_DECLS /* empty */
  34. #endif
  35. __BEGIN_DECLS
  36. struct gsl_combination_struct
  37. {
  38. size_t n;
  39. size_t k;
  40. size_t *data;
  41. };
  42. typedef struct gsl_combination_struct gsl_combination;
  43. gsl_combination *gsl_combination_alloc (const size_t n, const size_t k);
  44. gsl_combination *gsl_combination_calloc (const size_t n, const size_t k);
  45. void gsl_combination_init_first (gsl_combination * c);
  46. void gsl_combination_init_last (gsl_combination * c);
  47. void gsl_combination_free (gsl_combination * c);
  48. int gsl_combination_memcpy (gsl_combination * dest, const gsl_combination * src);
  49. int gsl_combination_fread (FILE * stream, gsl_combination * c);
  50. int gsl_combination_fwrite (FILE * stream, const gsl_combination * c);
  51. int gsl_combination_fscanf (FILE * stream, gsl_combination * c);
  52. int gsl_combination_fprintf (FILE * stream, const gsl_combination * c, const char *format);
  53. size_t gsl_combination_n (const gsl_combination * c);
  54. size_t gsl_combination_k (const gsl_combination * c);
  55. size_t * gsl_combination_data (const gsl_combination * c);
  56. size_t gsl_combination_get (const gsl_combination * c, const size_t i);
  57. int gsl_combination_valid (gsl_combination * c);
  58. int gsl_combination_next (gsl_combination * c);
  59. int gsl_combination_prev (gsl_combination * c);
  60. #ifdef HAVE_INLINE
  61. extern inline
  62. size_t
  63. gsl_combination_get (const gsl_combination * c, const size_t i)
  64. {
  65. #if GSL_RANGE_CHECK
  66. if (i >= c->k)
  67. {
  68. GSL_ERROR_VAL ("index out of range", GSL_EINVAL, 0);
  69. }
  70. #endif
  71. return c->data[i];
  72. }
  73. #endif /* HAVE_INLINE */
  74. __END_DECLS
  75. #endif /* __GSL_COMBINATION_H__ */