Line data Source code
1 :
2 : #ifndef UG_BASE_LIB_ALGEBRA_ORDERING_STRATEGIES_ALGORITHMS_UTIL_H
3 : #define UG_BASE_LIB_ALGEBRA_ORDERING_STRATEGIES_ALGORITHMS_UTIL_H
4 :
5 : #include <boost/graph/adjacency_list.hpp>
6 : #include <boost/graph/graph_traits.hpp>
7 : #include "common/error.h" // UG_THROW
8 :
9 : namespace ug{
10 :
11 : #ifndef HAVE_BOOL
12 : #define HAVE_BOOL
13 :
14 : class BOOL{
15 : public:
16 : BOOL() : value_(bool()){}
17 0 : BOOL(bool const& t): value_(t) {}
18 0 : operator bool() const { return value_; }
19 : private:
20 : char value_;
21 : };
22 :
23 : #endif
24 :
25 :
26 : #ifndef HAVE_IS_PERMUTATION
27 : #define HAVE_IS_PERMUTATION
28 :
29 : template <typename O_t>
30 0 : bool is_permutation(O_t &o){
31 0 : std::vector<BOOL> container(o.size(), false);
32 0 : for(unsigned i = 0; i < o.size(); ++i){
33 0 : if(!container[o[i]]){
34 0 : container[o[i]] = true;
35 : }
36 : else{
37 0 : UG_THROW("is_permutation: multiple occurence of index, i=" << i << ", o[i]=" << o[i] << "\n");
38 : return false; //no doubles allowed
39 : }
40 : }
41 :
42 0 : for(unsigned i = 0; i < o.size(); ++i){
43 0 : if(!container[i]){
44 0 : UG_THROW("is_permutation: no occurence of index " << i);
45 : return false;
46 : }
47 : }
48 :
49 : return true;
50 0 : }
51 :
52 : #endif
53 :
54 : }
55 :
56 : #endif
|