1 #if !defined HAVE_CHECK_PERMGEN_H__ 2 #define HAVE_CHECK_PERMGEN_H__ 3 // This file is part of the FXT library. 4 // Copyright (C) 2010, 2012, 2014, 2018, 2019 Joerg Arndt 5 // License: GNU General Public License version 3 or later, 6 // see the file COPYING.txt in the main directory. 7 8 #include "comb/num2perm.h" // perm2num_swp() 9 #include "ds/bitarray.h" 10 #include "aux0/factorial.h" 11 12 #include "fxttypes.h" 13 14 class check_permgen 15 // Checking validity of list of permutations. 16 { 17 public: 18 const ulong *x_; 19 ulong n_; 20 ulong *r_; // for reversed permutations 21 bitarray B; 22 23 private: // have pointer data 24 check_permgen(const check_permgen&) = delete; 25 check_permgen & operator = (const check_permgen&) = delete; 26 27 public: check_permgen(ulong n)28 explicit check_permgen(ulong n) 29 : 30 x_(nullptr), 31 n_(n), 32 r_(new ulong[n_]), 33 B( factorial(n) ) 34 { 35 } 36 ~check_permgen()37 ~check_permgen() 38 { 39 delete [] r_; 40 } 41 first(const ulong * x)42 void first(const ulong *x) 43 { 44 B.clear_all(); 45 x_ = x; 46 } 47 is_repeat()48 bool is_repeat() 49 // Mark permutation as seen. 50 // Return true if permutation is a repeat. 51 { 52 ulong w = perm2num_swp(x_, n_); 53 bool q = B.test_set(w); 54 return q; 55 } 56 is_repeat_rev()57 bool is_repeat_rev() 58 // Mark reversed permutation as seen. 59 // Return true if reversed permutation is a repeat. 60 { 61 for (ulong k=0, j=n_-1; k<n_; ++k, --j) r_[k] = x_[j]; 62 ulong w = perm2num_swp(r_, n_); 63 bool q = B.test_set(w); 64 return q; 65 } 66 }; 67 // ------------------------- 68 69 70 #endif // !defined HAVE_CHECK_PERMGEN_H__ 71