20#ifndef CCGSL_PERMUTATION_HPP
21#define CCGSL_PERMUTATION_HPP
26#include<gsl/gsl_permutation.h>
50 try {
count =
new size_t; }
catch( std::bad_alloc& e ){
103 gsl_permutation_memcpy( copy.
get(),
get() );
118#ifdef __GXX_EXPERIMENTAL_CXX0X__
124 std::swap(
count, v.count );
125 v.ccgsl_pointer =
nullptr;
134 std::swap(
count, v.count );
175#ifdef __GXX_EXPERIMENTAL_CXX0X__
202 int fread( FILE* stream ){
return gsl_permutation_fread( stream,
get() ); }
208 int fwrite( FILE* stream )
const {
return gsl_permutation_fwrite( stream,
get() ); }
214 int fscanf( FILE* stream ){
return gsl_permutation_fscanf( stream,
get() ); }
221 int fprintf( FILE* stream,
char const* format )
const {
222 return gsl_permutation_fprintf( stream,
get(), format ); }
227 size_t size()
const {
return gsl_permutation_size(
get() ); }
232 size_t*
data()
const {
return gsl_permutation_data(
get() ); }
239 int swap(
size_t const i,
size_t const j ){
return gsl_permutation_swap(
get(), i, j ); }
244 int valid()
const {
return gsl_permutation_valid(
get() ); }
259 int next(){
return gsl_permutation_next(
get() ); }
264 int prev(){
return gsl_permutation_prev(
get() ); }
272 return gsl_permutation_mul(
get(), pa.
get(), pb.
get() ); }
280 return gsl_permutation_linear_to_canonical(
get(), p.
get() ); }
287 return gsl_permutation_canonical_to_linear(
get(), q.
get() ); }
308 size_t get(
size_t const i )
const {
return gsl_permutation_get(
get(), i ); }
314 size_t operator[](
size_t const i )
const {
return gsl_permutation_get(
get(), i ); }
320 template<
typename container,
typename content,
bool reverse>
class iterator_base {
352 static content something = 0;
357 }
else if(
v->ccgsl_pointer == 0 ){
371 return *(
v->ccgsl_pointer->data +
position);
383 }
else if(
v->ccgsl_pointer == 0 ){
397 return *(
v->ccgsl_pointer->data +
position);
407 static content something = 0;
412 }
else if(
v->ccgsl_pointer == 0 ){
427 return *(
v->ccgsl_pointer->data + p );
437 if(
v == 0 or i.
v == 0 ){
440 }
else if(
v->ccgsl_pointer == 0 or i.
v->ccgsl_pointer == 0 ){
445 if(
v->ccgsl_pointer != i.
v->ccgsl_pointer ){
446 gsl_error(
"trying to take difference of iterators for different permutations", __FILE__, __LINE__,
479 if(
v == 0 or i.
v == 0 ){
484 if(
v->ccgsl_pointer != i.
v->ccgsl_pointer ){
485 gsl_error(
"trying to take difference of iterators for different permutations", __FILE__, __LINE__,
501 }
else if(
v->ccgsl_pointer == 0 ){
518 }
else if(
v->ccgsl_pointer == 0 ){
535 }
else if(
v->ccgsl_pointer == 0 ){
565 :
public iterator_base<permutation const,unsigned long,reverse>{
710 if( this->
v == 0 or i.
v == 0 ){
716 gsl_error(
"trying to take difference of iterators for different permutations", __FILE__, __LINE__,
@ GSL_EFAILED
generic failure
@ GSL_EFAULT
invalid pointer
A class template for the const iterators.
const_iterator_t< reverse > operator++(int)
The postfix ++ operator.
const_iterator_t< reverse > & operator=(const_iterator_t< reverse > const &i)
We can assign one output iterator from another.
bool operator==(const_iterator_t< reverse > const &i) const
Comparison with const_iterator.
bool operator<(const_iterator_t< reverse > const &i) const
Comparison with const_iterator.
const_iterator_t(permutation const *v, difference_type position)
This constructor allows permutation to create non-default iterators.
const_iterator_t< reverse > & operator++()
The prefix ++ operator.
bool operator!=(const_iterator_t< reverse > const &i) const
Comparison with const_iterator.
const_iterator_t< reverse > & operator-=(difference_type const n)
The -= operator.
const_iterator_t()
The default constructor.
const_iterator_t< reverse > & operator+=(difference_type const n)
The += operator.
const_iterator_t< reverse > operator--(int)
The postfix – operator.
const_iterator_t< reverse > & operator--()
The prefix – operator.
const_iterator_t< reverse > operator+(difference_type const n) const
The + operator.
const_iterator_t(const_iterator_t< reverse > const &i)
A copy constructor.
iterator_base< permutationconst, unsignedlong, reverse >::difference_type difference_type
Difference type.
difference_type operator-(const_iterator_t< reverse > const &i) const
The - operator: find distance between two iterators.
const_iterator_t< reverse > operator-(difference_type const n) const
The - operator: subtract distance from iterator.
The container must have iterator types.
bool operator==(iterator_base< container, content, reverse > const &i) const
The == operator.
container * v
Store a pointer to a permutation we can iterate over: 0 if no permutation.
std::random_access_iterator_tag iterator_category
An iterator must have an iterator category.
reference operator[](difference_type const n) const
Get element at i + n by reference ([] operator).
iterator_base()
The iterator is default constructible.
difference_type operator-(iterator_base< container, content, reverse > const &i) const
The - operator: find distance between two iterators.
ptrdiff_t difference_type
An iterator must have a difference_type.
size_t value_type
An iterator must have a value type.
value_type & reference
An iterator must have a reference type.
value_type * pointer
An iterator must have a pointer typea.
pointer operator->() const
Dereference the pointer.
void increment()
Increment the iterator.
void decrement()
Decrement the iterator.
bool operator!=(iterator_base< container, content, reverse > const &i) const
The != operator.
bool operator<(iterator_base< container, content, reverse > const &i) const
The < operator is used to compare iterators.
iterator_base(container *v, difference_type position)
This constructor allows permutation to create non-default iterators.
void shift(difference_type const n)
Shift iterator n places.
difference_type position
Mark position of iterator within permutation.
reference operator*() const
Dereference the pointer.
This class handles GSL permutation objects.
~permutation()
The destructor only deletes the pointers if count reaches zero.
int fread(FILE *stream)
C++ version of gsl_permutation_fread().
void reverse()
C++ version of gsl_permutation_reverse().
int valid() const
C++ version of gsl_permutation_valid().
int linear_to_canonical(permutation const &p)
C++ version of gsl_permutation_linear_to_canonical().
size_t canonical_cycles() const
C++ version of gsl_permutation_canonical_cycles().
size_t * count
The shared reference count.
size_t operator[](size_t const i) const
C++ version of gsl_permutation_get().
permutation & operator=(permutation const &v)
The assignment operator.
size_t get(size_t const i) const
C++ version of gsl_permutation_get().
permutation & operator=(permutation &&v)
Move operator.
const_iterator_t< true > const_reverse_iterator
The const_reverse_iterator type.
gsl_permutation const * get() const
Get the gsl_permutation.
size_t use_count() const
Find how many permutation objects share this pointer.
int fscanf(FILE *stream)
C++ version of gsl_permutation_fscanf().
size_t * data() const
C++ version of gsl_permutation_data().
size_t size_type
A container must have a size_type.
size_t inversions() const
C++ version of gsl_permutation_inversions().
int fwrite(FILE *stream) const
C++ version of gsl_permutation_fwrite().
int memcpy(permutation const &src)
C++ version of gsl_permutation_memcpy().
int inverse(permutation const &p)
C++ version of gsl_permutation_inverse().
size_t size() const
C++ version of gsl_permutation_size().
int mul(permutation const &pa, permutation const &pb)
C++ version of gsl_permutation_mul().
bool unique() const
Find if this is the only object sharing the gsl_permutation.
const_iterator end() const
Get iterator pointing beyond last permutation element.
gsl_permutation * get()
Get the gsl_permutation.
const_iterator_t< false > const_iterator
The const_iterator type.
static permutation calloc(size_t const n)
C++ version of gsl_permutation_calloc().
void init()
C++ version of gsl_permutation_init().
int prev()
C++ version of gsl_permutation_prev().
permutation(permutation const &v)
The copy constructor.
const_iterator::difference_type difference_type
A container must have a difference_type.
int fprintf(FILE *stream, char const *format) const
C++ version of gsl_permutation_fprintf().
int canonical_to_linear(permutation const &q)
C++ version of gsl_permutation_canonical_to_linear().
int next()
C++ version of gsl_permutation_next().
permutation(size_t const n, bool init=false)
This constructor creates a new permutation with n elements.
permutation(permutation &&v)
Move constructor.
permutation()
The default constructor is only really useful for assigning to.
gsl_permutation * ccgsl_pointer
The shared pointer.
size_t linear_cycles() const
C++ version of gsl_permutation_linear_cycles().
const_iterator begin() const
Get iterator pointing to first permutation element.
permutation clone() const
The clone function.
int swap(size_t const i, size_t const j)
C++ version of gsl_permutation_swap().
permutation(gsl_permutation *v)
Could construct from a gsl_permutation.
size_t n(workspace const &w)
C++ version of gsl_rstat_n().
gsl_sf_result result
Typedef for gsl_sf_result.
The gsl package creates an interface to the GNU Scientific Library for C++.