| 1 | # This file was automatically generated by SWIG (https://www.swig.org). | ||
| 2 | # Version 4.2.0 | ||
| 3 | # | ||
| 4 | # Do not make changes to this file unless you know what you are doing - modify | ||
| 5 | # the SWIG interface file instead. | ||
| 6 | |||
| 7 | package Math::GSL::Combination; | ||
| 8 | use base qw(Exporter); | ||
| 9 | use base qw(DynaLoader); | ||
| 10 | package Math::GSL::Combinationc; | ||
| 11 | bootstrap Math::GSL::Combination; | ||
| 12 | package Math::GSL::Combination; | ||
| 13 | @EXPORT = qw(); | ||
| 14 | |||
| 15 | # ---------- BASE METHODS ------------- | ||
| 16 | |||
| 17 | package Math::GSL::Combination; | ||
| 18 | |||
| 19 | sub TIEHASH { | ||
| 20 | my ($classname,$obj) = @_; | ||
| 21 | return bless $obj, $classname; | ||
| 22 | } | ||
| 23 | |||
| 24 | sub CLEAR { } | ||
| 25 | |||
| 26 | sub FIRSTKEY { } | ||
| 27 | |||
| 28 | sub NEXTKEY { } | ||
| 29 | |||
| 30 | sub FETCH { | ||
| 31 | my ($self,$field) = @_; | ||
| 32 | my $member_func = "swig_${field}_get"; | ||
| 33 | $self->$member_func(); | ||
| 34 | } | ||
| 35 | |||
| 36 | sub STORE { | ||
| 37 | my ($self,$field,$newval) = @_; | ||
| 38 | my $member_func = "swig_${field}_set"; | ||
| 39 | $self->$member_func($newval); | ||
| 40 | } | ||
| 41 | |||
| 42 | sub this { | ||
| 43 | my $ptr = shift; | ||
| 44 | return tied(%$ptr); | ||
| 45 | } | ||
| 46 | |||
| 47 | |||
| 48 | # ------- FUNCTION WRAPPERS -------- | ||
| 49 | |||
| 50 | package Math::GSL::Combination; | ||
| 51 | |||
| 52 | *gsl_error = *Math::GSL::Combinationc::gsl_error; | ||
| 53 | *gsl_stream_printf = *Math::GSL::Combinationc::gsl_stream_printf; | ||
| 54 | *gsl_strerror = *Math::GSL::Combinationc::gsl_strerror; | ||
| 55 | *gsl_set_error_handler = *Math::GSL::Combinationc::gsl_set_error_handler; | ||
| 56 | *gsl_set_error_handler_off = *Math::GSL::Combinationc::gsl_set_error_handler_off; | ||
| 57 | *gsl_set_stream_handler = *Math::GSL::Combinationc::gsl_set_stream_handler; | ||
| 58 | *gsl_set_stream = *Math::GSL::Combinationc::gsl_set_stream; | ||
| 59 | *gsl_combination_alloc = *Math::GSL::Combinationc::gsl_combination_alloc; | ||
| 60 | *gsl_combination_calloc = *Math::GSL::Combinationc::gsl_combination_calloc; | ||
| 61 | *gsl_combination_init_first = *Math::GSL::Combinationc::gsl_combination_init_first; | ||
| 62 | *gsl_combination_init_last = *Math::GSL::Combinationc::gsl_combination_init_last; | ||
| 63 | *gsl_combination_free = *Math::GSL::Combinationc::gsl_combination_free; | ||
| 64 | *gsl_combination_memcpy = *Math::GSL::Combinationc::gsl_combination_memcpy; | ||
| 65 | *gsl_combination_fread = *Math::GSL::Combinationc::gsl_combination_fread; | ||
| 66 | *gsl_combination_fwrite = *Math::GSL::Combinationc::gsl_combination_fwrite; | ||
| 67 | *gsl_combination_fscanf = *Math::GSL::Combinationc::gsl_combination_fscanf; | ||
| 68 | *gsl_combination_fprintf = *Math::GSL::Combinationc::gsl_combination_fprintf; | ||
| 69 | *gsl_combination_n = *Math::GSL::Combinationc::gsl_combination_n; | ||
| 70 | *gsl_combination_k = *Math::GSL::Combinationc::gsl_combination_k; | ||
| 71 | *gsl_combination_data = *Math::GSL::Combinationc::gsl_combination_data; | ||
| 72 | *gsl_combination_valid = *Math::GSL::Combinationc::gsl_combination_valid; | ||
| 73 | *gsl_combination_next = *Math::GSL::Combinationc::gsl_combination_next; | ||
| 74 | *gsl_combination_prev = *Math::GSL::Combinationc::gsl_combination_prev; | ||
| 75 | *gsl_combination_get = *Math::GSL::Combinationc::gsl_combination_get; | ||
| 76 | |||
| 77 | ############# Class : Math::GSL::Combination::gsl_combination_struct ############## | ||
| 78 | |||
| 79 | package Math::GSL::Combination::gsl_combination_struct; | ||
| 80 | use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS); | ||
| 81 | @ISA = qw( Math::GSL::Combination ); | ||
| 82 | %OWNER = (); | ||
| 83 | %ITERATORS = (); | ||
| 84 | *swig_n_get = *Math::GSL::Combinationc::gsl_combination_struct_n_get; | ||
| 85 | *swig_n_set = *Math::GSL::Combinationc::gsl_combination_struct_n_set; | ||
| 86 | *swig_k_get = *Math::GSL::Combinationc::gsl_combination_struct_k_get; | ||
| 87 | *swig_k_set = *Math::GSL::Combinationc::gsl_combination_struct_k_set; | ||
| 88 | *swig_data_get = *Math::GSL::Combinationc::gsl_combination_struct_data_get; | ||
| 89 | *swig_data_set = *Math::GSL::Combinationc::gsl_combination_struct_data_set; | ||
| 90 | sub new { | ||
| 91 | my $pkg = shift; | ||
| 92 | my $self = Math::GSL::Combinationc::new_gsl_combination_struct(@_); | ||
| 93 | bless $self, $pkg if defined($self); | ||
| 94 | } | ||
| 95 | |||
| 96 | sub DESTROY { | ||
| 97 | return unless $_[0]->isa('HASH'); | ||
| 98 | my $self = tied(%{$_[0]}); | ||
| 99 | return unless defined $self; | ||
| 100 | delete $ITERATORS{$self}; | ||
| 101 | if (exists $OWNER{$self}) { | ||
| 102 | Math::GSL::Combinationc::delete_gsl_combination_struct($self); | ||
| 103 | delete $OWNER{$self}; | ||
| 104 | } | ||
| 105 | } | ||
| 106 | |||
| 107 | sub DISOWN { | ||
| 108 | my $self = shift; | ||
| 109 | my $ptr = tied(%$self); | ||
| 110 | delete $OWNER{$ptr}; | ||
| 111 | } | ||
| 112 | |||
| 113 | sub ACQUIRE { | ||
| 114 | my $self = shift; | ||
| 115 | my $ptr = tied(%$self); | ||
| 116 | $OWNER{$ptr} = 1; | ||
| 117 | } | ||
| 118 | |||
| 119 | |||
| 120 | # ------- VARIABLE STUBS -------- | ||
| 121 | |||
| 122 | package Math::GSL::Combination; | ||
| 123 | |||
| 124 | *GSL_VERSION = *Math::GSL::Combinationc::GSL_VERSION; | ||
| 125 | *GSL_MAJOR_VERSION = *Math::GSL::Combinationc::GSL_MAJOR_VERSION; | ||
| 126 | *GSL_MINOR_VERSION = *Math::GSL::Combinationc::GSL_MINOR_VERSION; | ||
| 127 | *GSL_POSZERO = *Math::GSL::Combinationc::GSL_POSZERO; | ||
| 128 | *GSL_NEGZERO = *Math::GSL::Combinationc::GSL_NEGZERO; | ||
| 129 | *GSL_SUCCESS = *Math::GSL::Combinationc::GSL_SUCCESS; | ||
| 130 | *GSL_FAILURE = *Math::GSL::Combinationc::GSL_FAILURE; | ||
| 131 | *GSL_CONTINUE = *Math::GSL::Combinationc::GSL_CONTINUE; | ||
| 132 | *GSL_EDOM = *Math::GSL::Combinationc::GSL_EDOM; | ||
| 133 | *GSL_ERANGE = *Math::GSL::Combinationc::GSL_ERANGE; | ||
| 134 | *GSL_EFAULT = *Math::GSL::Combinationc::GSL_EFAULT; | ||
| 135 | *GSL_EINVAL = *Math::GSL::Combinationc::GSL_EINVAL; | ||
| 136 | *GSL_EFAILED = *Math::GSL::Combinationc::GSL_EFAILED; | ||
| 137 | *GSL_EFACTOR = *Math::GSL::Combinationc::GSL_EFACTOR; | ||
| 138 | *GSL_ESANITY = *Math::GSL::Combinationc::GSL_ESANITY; | ||
| 139 | *GSL_ENOMEM = *Math::GSL::Combinationc::GSL_ENOMEM; | ||
| 140 | *GSL_EBADFUNC = *Math::GSL::Combinationc::GSL_EBADFUNC; | ||
| 141 | *GSL_ERUNAWAY = *Math::GSL::Combinationc::GSL_ERUNAWAY; | ||
| 142 | *GSL_EMAXITER = *Math::GSL::Combinationc::GSL_EMAXITER; | ||
| 143 | *GSL_EZERODIV = *Math::GSL::Combinationc::GSL_EZERODIV; | ||
| 144 | *GSL_EBADTOL = *Math::GSL::Combinationc::GSL_EBADTOL; | ||
| 145 | *GSL_ETOL = *Math::GSL::Combinationc::GSL_ETOL; | ||
| 146 | *GSL_EUNDRFLW = *Math::GSL::Combinationc::GSL_EUNDRFLW; | ||
| 147 | *GSL_EOVRFLW = *Math::GSL::Combinationc::GSL_EOVRFLW; | ||
| 148 | *GSL_ELOSS = *Math::GSL::Combinationc::GSL_ELOSS; | ||
| 149 | *GSL_EROUND = *Math::GSL::Combinationc::GSL_EROUND; | ||
| 150 | *GSL_EBADLEN = *Math::GSL::Combinationc::GSL_EBADLEN; | ||
| 151 | *GSL_ENOTSQR = *Math::GSL::Combinationc::GSL_ENOTSQR; | ||
| 152 | *GSL_ESING = *Math::GSL::Combinationc::GSL_ESING; | ||
| 153 | *GSL_EDIVERGE = *Math::GSL::Combinationc::GSL_EDIVERGE; | ||
| 154 | *GSL_EUNSUP = *Math::GSL::Combinationc::GSL_EUNSUP; | ||
| 155 | *GSL_EUNIMPL = *Math::GSL::Combinationc::GSL_EUNIMPL; | ||
| 156 | *GSL_ECACHE = *Math::GSL::Combinationc::GSL_ECACHE; | ||
| 157 | *GSL_ETABLE = *Math::GSL::Combinationc::GSL_ETABLE; | ||
| 158 | *GSL_ENOPROG = *Math::GSL::Combinationc::GSL_ENOPROG; | ||
| 159 | *GSL_ENOPROGJ = *Math::GSL::Combinationc::GSL_ENOPROGJ; | ||
| 160 | *GSL_ETOLF = *Math::GSL::Combinationc::GSL_ETOLF; | ||
| 161 | *GSL_ETOLX = *Math::GSL::Combinationc::GSL_ETOLX; | ||
| 162 | *GSL_ETOLG = *Math::GSL::Combinationc::GSL_ETOLG; | ||
| 163 | *GSL_EOF = *Math::GSL::Combinationc::GSL_EOF; | ||
| 164 | *gsl_check_range = *Math::GSL::Combinationc::gsl_check_range; | ||
| 165 | *GSL_RANGE_CHECK = *Math::GSL::Combinationc::GSL_RANGE_CHECK; | ||
| 166 | |||
| 167 | @EXPORT_OK = qw/ | ||
| 168 | gsl_combination_alloc | ||
| 169 | gsl_combination_calloc | ||
| 170 | gsl_combination_init_first | ||
| 171 | gsl_combination_init_last | ||
| 172 | gsl_combination_free | ||
| 173 | gsl_combination_memcpy | ||
| 174 | gsl_combination_fread | ||
| 175 | gsl_combination_fwrite | ||
| 176 | gsl_combination_fscanf | ||
| 177 | gsl_combination_fprintf | ||
| 178 | gsl_combination_n | ||
| 179 | gsl_combination_k | ||
| 180 | gsl_combination_data | ||
| 181 | gsl_combination_get | ||
| 182 | gsl_combination_valid | ||
| 183 | gsl_combination_next | ||
| 184 | gsl_combination_prev | ||
| 185 | /; | ||
| 186 | %EXPORT_TAGS = ( all => [ @EXPORT_OK ] ); | ||
| 187 | |||
| 188 | =encoding utf8 | ||
| 189 | |||
| 190 | =head1 NAME | ||
| 191 | |||
| 192 | Math::GSL::Combination - Combinations | ||
| 193 | |||
| 194 | =head1 SYNOPSIS | ||
| 195 | |||
| 196 | use Math::GSL qw/:all/; | ||
| 197 | use Math::GSL::Combination qw/:all/; | ||
| 198 | |||
| 199 | my $c = Math::GSL::Combination->new(6,3); | ||
| 200 | print join (" ", $c->as_list) . "\n"; | ||
| 201 | $c->next; | ||
| 202 | print join (" ", $c->as_list) . "\n"; | ||
| 203 | |||
| 204 | my $fd = gsl_fopen('combination.dat', 'w'); | ||
| 205 | gsl_combination_fwrite($fd, $c->raw); | ||
| 206 | gsl_fclose($fd); | ||
| 207 | |||
| 208 | =head1 DESCRIPTION | ||
| 209 | |||
| 210 | Here is a list of all the functions in this module : | ||
| 211 | |||
| 212 | =over | ||
| 213 | |||
| 214 | =item * C<gsl_combination_alloc($n, $k)> | ||
| 215 | |||
| 216 | This function allocates memory for a new combination with parameters $n, $k. | ||
| 217 | The combination is not initialized and its elements are undefined. Use the | ||
| 218 | function gsl_combination_calloc if you want to create a combination which is | ||
| 219 | initialized to the lexicographically first combination. | ||
| 220 | |||
| 221 | =item * C<gsl_combination_calloc($n, $k)> | ||
| 222 | |||
| 223 | This function allocates memory for a new combination with parameters $n, $k and | ||
| 224 | initializes it to the lexicographically first combination. | ||
| 225 | |||
| 226 | =item * C<gsl_combination_init_first($c)> | ||
| 227 | |||
| 228 | This function initializes the combination $c to the lexicographically first | ||
| 229 | combination, i.e. (0,1,2,...,k-1). | ||
| 230 | |||
| 231 | =item * C<gsl_combination_init_last($c)> | ||
| 232 | |||
| 233 | This function initializes the combination $c to the lexicographically last | ||
| 234 | combination, i.e. (n-k,n-k+1,...,n-1). | ||
| 235 | |||
| 236 | =item * C<gsl_combination_free($c)> | ||
| 237 | |||
| 238 | This function frees all the memory used by the combination $c. | ||
| 239 | |||
| 240 | =item * C<gsl_combination_memcpy($dest, $src)> | ||
| 241 | |||
| 242 | This function copies the elements of the combination $src into the combination | ||
| 243 | $dest. The two combinations must have the same size. | ||
| 244 | |||
| 245 | =item * C<gsl_combination_get($c, $i)> | ||
| 246 | |||
| 247 | This function returns the value of the i-th element of the combination $c. If | ||
| 248 | $i lies outside the allowed range of 0 to k-1 then the error handler is invoked | ||
| 249 | and 0 is returned. | ||
| 250 | |||
| 251 | =item * C<gsl_combination_fwrite($stream, $c)> | ||
| 252 | |||
| 253 | This function writes the elements of the combination $c to the stream $stream, | ||
| 254 | opened with the gsl_fopen function from the Math::GSL module, in binary format. | ||
| 255 | The function returns $GSL_EFAILED if there was a problem writing to the file. | ||
| 256 | Since the data is written in the native binary format it may not be portable | ||
| 257 | between different architectures. | ||
| 258 | |||
| 259 | =item * C<gsl_combination_fread($stream, $c)> | ||
| 260 | |||
| 261 | This function reads elements from the open stream $stream, opened with the | ||
| 262 | gsl_fopen function from the Math::GSL module, into the combination $c in binary | ||
| 263 | format. The combination $c must be preallocated with correct values of n and k | ||
| 264 | since the function uses the size of $c to determine how many bytes to read. The | ||
| 265 | function returns $GSL_EFAILED if there was a problem reading from the file. The | ||
| 266 | data is assumed to have been written in the native binary format on the same | ||
| 267 | architecture. | ||
| 268 | |||
| 269 | =item * C<gsl_combination_fprintf($stream, $c, $format)> | ||
| 270 | |||
| 271 | This function writes the elements of the combination $c line-by-line to the | ||
| 272 | stream $stream, opened with the gsl_fopen function from the Math::GSL module, | ||
| 273 | using the format specifier $format, which should be suitable for a type of | ||
| 274 | size_t. In ISO C99 the type modifier z represents size_t, so "%zu\n" is a | ||
| 275 | suitable format. The function returns $GSL_EFAILED if there was a problem | ||
| 276 | writing to the file. | ||
| 277 | |||
| 278 | =item * C<gsl_combination_fscanf($stream, $c)> | ||
| 279 | |||
| 280 | This function reads formatted data from the stream $stream into the combination | ||
| 281 | $c. The combination $c must be preallocated with correct values of n and k | ||
| 282 | since the function uses the size of $c to determine how many numbers to read. | ||
| 283 | The function returns $GSL_EFAILED if there was a problem reading from the file. | ||
| 284 | |||
| 285 | =item * C<gsl_combination_n($c)> | ||
| 286 | |||
| 287 | This function returns the range (n) of the combination $c. | ||
| 288 | |||
| 289 | =item * C<gsl_combination_k($c)> | ||
| 290 | |||
| 291 | This function returns the number of elements (k) in the combination $c. | ||
| 292 | |||
| 293 | =item * C<gsl_combination_data($c)> | ||
| 294 | |||
| 295 | This function returns a pointer to the array of elements in the combination $c. | ||
| 296 | |||
| 297 | =item * C<gsl_combination_valid($c)> | ||
| 298 | |||
| 299 | This function checks that the combination $c is valid. The k elements should | ||
| 300 | lie in the range 0 to n-1, with each value occurring once at most and in | ||
| 301 | increasing order. | ||
| 302 | |||
| 303 | =item * C<gsl_combination_next($c)> | ||
| 304 | |||
| 305 | This function advances the combination $c to the next combination in | ||
| 306 | lexicographic order and returns $GSL_SUCCESS. If no further combinations are | ||
| 307 | available it returns $GSL_FAILURE and leaves $c unmodified. Starting with the | ||
| 308 | first combination and repeatedly applying this function will iterate through | ||
| 309 | all possible combinations of a given order. | ||
| 310 | |||
| 311 | =item * C<gsl_combination_prev($c)> | ||
| 312 | |||
| 313 | This function steps backwards from the combination $c to the previous | ||
| 314 | combination in lexicographic order, returning $GSL_SUCCESS. If no previous | ||
| 315 | combination is available it returns $GSL_FAILURE and leaves $c unmodified. | ||
| 316 | |||
| 317 | =back | ||
| 318 | |||
| 319 | =cut | ||
| 320 | |||
| 321 | sub new { | ||
| 322 | my ($class, $n, $k) = @_; | ||
| 323 | my $this = {}; | ||
| 324 | $this->{_length} = $n; | ||
| 325 | $this->{_combination} = gsl_combination_calloc($n, $k); | ||
| 326 | bless $this, $class; | ||
| 327 | } | ||
| 328 | |||
| 329 | sub as_list { | ||
| 330 | my $self=shift; | ||
| 331 | $self->get( [ 0 .. $self->elements - 1 ] ); | ||
| 332 | } | ||
| 333 | |||
| 334 | sub get { | ||
| 335 | my ($self, $indices) = @_; | ||
| 336 | return map { gsl_combination_get($self->{_combination}, $_ ) } @$indices ; | ||
| 337 | } | ||
| 338 | |||
| 339 | sub raw { (shift)->{_combination} } | ||
| 340 | sub length { (shift)->{_length} } | ||
| 341 | |||
| 342 | sub elements { | ||
| 343 | my $self = shift; | ||
| 344 | return gsl_combination_k($self->{_combination}); | ||
| 345 | } | ||
| 346 | |||
| 347 | sub status { | ||
| 348 | my ($self,$status) = @_; | ||
| 349 | if (defined $status) { | ||
| 350 | $self->{status} = $status; | ||
| 351 | return $self; | ||
| 352 | } else { | ||
| 353 | return $self->{status}; | ||
| 354 | } | ||
| 355 | } | ||
| 356 | |||
| 357 | sub next { | ||
| 358 | my $self = shift; | ||
| 359 | my $status = gsl_combination_next($self->{_combination}); | ||
| 360 | $self->status($status); | ||
| 361 | return $self; | ||
| 362 | } | ||
| 363 | |||
| 364 | sub prev { | ||
| 365 | my $self = shift; | ||
| 366 | my $status = gsl_combination_prev($self->{_combination}); | ||
| 367 | $self->status($status); | ||
| 368 | return $status; | ||
| 369 | } | ||
| 370 | |||
| 371 | =head1 MORE INFO | ||
| 372 | |||
| 373 | For more informations on the functions, we refer you to the GSL official | ||
| 374 | documentation: L<http://www.gnu.org/software/gsl/manual/html_node/> | ||
| 375 | |||
| 376 | |||
| 377 | |||
| 378 | |||
| 379 | =head1 AUTHORS | ||
| 380 | |||
| 381 | Jonathan "Duke" Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com> | ||
| 382 | |||
| 383 | =head1 COPYRIGHT AND LICENSE | ||
| 384 | |||
| 385 | Copyright (C) 2008-2024 Jonathan "Duke" Leto and Thierry Moisan | ||
| 386 | |||
| 387 | This program is free software; you can redistribute it and/or modify it | ||
| 388 | under the same terms as Perl itself. | ||
| 389 | |||
| 390 | =cut | ||
| 391 | |||
| 392 | 1; |