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