Debian Codegraph @

external/gsl/gsl_combination__init.c

raw symbols SCIP
1 /* combination/init.c
2 * based on permutation/init.c 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
21 #include "gsl__config.h"cxx . . $ `<file>/external/gsl/gsl__config.h`/
22 #include <stdlib.h>
23 #include "gsl_errno.h"cxx . . $ `<file>/external/gsl/gsl_errno.h`/
24 #include "gsl_combination.h"cxx . . $ `<file>/external/gsl/gsl_combination.h`/
25
26 gsl_combinationcxx . . $ gsl_combination# *
27 gsl_combination_alloccxx . . $ gsl_combination_alloc(6b184067857f7842). (const size_t n, const size_t k)
28 {
29 gsl_combinationcxx . . $ gsl_combination# * c;
30
31 if (n == 0)
32 {
33 GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("combination parameter n must be positive integer",
34 GSL_EDOM, 0);
35 }
36 if (k > n)
37 {
38 GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("combination length k must be an integer less than or equal to n",
39 GSL_EDOM, 0);
40 }
41 c = (gsl_combinationcxx . . $ gsl_combination# *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (sizeof (gsl_combinationcxx . . $ gsl_combination#));
42
43 if (c == 0)
44 {
45 GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("failed to allocate space for combination struct",
46 GSL_ENOMEM, 0);
47 }
48
49 if (k > 0)
50 {
51 c->datacxx . . $ gsl_combination_struct#data. = (size_t *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (k * sizeof (size_t));
52
53 if (c->datacxx . . $ gsl_combination_struct#data. == 0)
54 {
55 freecxx . . $ free(5d22bdacc48458e8). (c); /* exception in constructor, avoid memory leak */
56
57 GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("failed to allocate space for combination data",
58 GSL_ENOMEM, 0);
59 }
60 }
61 else
62 {
63 c->datacxx . . $ gsl_combination_struct#data. = 0;
64 }
65
66 c->ncxx . . $ gsl_combination_struct#n. = n;
67 c->kcxx . . $ gsl_combination_struct#k. = k;
68
69 return c;
70 }
71
72 gsl_combinationcxx . . $ gsl_combination# *
73 gsl_combination_calloccxx . . $ gsl_combination_calloc(6b184067857f7842). (const size_t n, const size_t k)
74 {
75 size_t i;
76
77 gsl_combinationcxx . . $ gsl_combination# * c = gsl_combination_alloccxx . . $ gsl_combination_alloc(6b184067857f7842). (n, k);
78
79 if (c == 0)
80 return 0;
81
82 /* initialize combination to identity */
83
84 for (i = 0; i < k; i++)
85 {
86 c->datacxx . . $ gsl_combination_struct#data.[i] = i;
87 }
88
89 return c;
90 }
91
92 void
93 gsl_combination_init_firstcxx . . $ gsl_combination_init_first(ce74e54de15c98cd). (gsl_combinationcxx . . $ gsl_combination# * c)
94 {
95 const size_t k = c->kcxx . . $ gsl_combination_struct#k. ;
96 size_t i;
97
98 /* initialize combination to identity */
99
100 for (i = 0; i < k; i++)
101 {
102 c->datacxx . . $ gsl_combination_struct#data.[i] = i;
103 }
104 }
105
106 void
107 gsl_combination_init_lastcxx . . $ gsl_combination_init_last(ce74e54de15c98cd). (gsl_combinationcxx . . $ gsl_combination# * c)
108 {
109 const size_t k = c->kcxx . . $ gsl_combination_struct#k. ;
110 size_t i;
111 size_t n = c->ncxx . . $ gsl_combination_struct#n.;
112
113 /* initialize combination to identity */
114
115 for (i = 0; i < k; i++)
116 {
117 c->datacxx . . $ gsl_combination_struct#data.[i] = n - k + i;
118 }
119 }
120
121 void
122 gsl_combination_freecxx . . $ gsl_combination_free(ce74e54de15c98cd). (gsl_combinationcxx . . $ gsl_combination# * c)
123 {
124 if (c->kcxx . . $ gsl_combination_struct#k. > 0) freecxx . . $ free(5d22bdacc48458e8). (c->datacxx . . $ gsl_combination_struct#data.);
125 freecxx . . $ free(5d22bdacc48458e8). (c);
126 }