13 #include <boost/unordered_set.hpp>
14 #include <boost/unordered_map.hpp>
16 #define default_buckets boost::unordered::detail::default_bucket_count
20 #define byte unsigned char
21 #define SIZE_T_BITS (unsigned)(8*sizeof(size_t))
23 #define DEEP_EMPLACE(x,y) emplace(std::piecewise_construct, std::make_tuple(x), std::make_tuple(y))
25 #define DEFAULT_EMPLACE(x) emplace(std::piecewise_construct, std::make_tuple(x), std::make_tuple())
29 #define MAX_TW (unsigned char)LONG_WIDTH
31 #define MAX_TW (unsigned char)64
82 template <
typename ElementA,
typename ElementB>
83 bool pareto_le(
const std::pair<ElementA,ElementB>& p1,
const std::pair<ElementA,ElementB>& p2)
85 return (p1.first <= p2.first) && (p1.second <= p2.second);
103 diagonal_counter(
const size_t _max_x,
const size_t _max_y): max_x(_max_x), max_y(_max_y), x(0), y(0) {}
104 diagonal_counter(
const size_t _max_x,
const size_t _max_y,
const size_t _x,
const size_t _y): max_x(_max_x), max_y(_max_y), x(_x), y(_y) {}
108 if(
at_end())
return false;
110 if((x == max_x) || (y == 0)){
112 const size_t new_sum = x + y + 1;
113 x = (max_y <= new_sum) ? new_sum - max_y : 0;
127 if((y == max_y) || (x == 0)){
129 const size_t new_sum = x + y - 1;
130 y = (max_x <= new_sum) ? new_sum - max_x : 0;
142 return (x == 0) && (y == 0);
146 return (x == max_x) && (y ==
max_y);
152 template<
typename Element>
153 std::ostream& operator<<(std::ostream& os, const std::list<Element>& lst)
155 for(
auto i : lst) os << i <<
" ";
159 template<
typename Element1,
typename Element2>
160 std::ostream& operator<<(std::ostream& os, const boost::unordered_map<Element1, Element2>& map)
162 for(
auto i : map) os << i <<
" ";
170 template <
class Set,
typename Element>
171 inline bool contains(
const Set& s,
const Element& el)
173 return s.find(el) != s.cend();
181 for(
const auto& i : S)
189 void operator&=(boost::unordered_set<T>& S1,
const boost::unordered_set<T>& S2)
191 for(
typename boost::unordered_set<T>::iterator i = S1.begin(); i != S1.end();)
192 if(!
contains(S2, *i)) i = S1.erase(i);
else ++i;
198 void operator^=(boost::unordered_set<T>& S1,
const boost::unordered_set<T>& S2)
200 for(
typename boost::unordered_set<T>::iterator i = S1.begin(); i != S1.end();)
201 if(
contains(S2, *i)) i = S1.erase(i);
else ++i;
202 for(
typename boost::unordered_set<T>::iterator i = S2.begin(); i != S2.end(); ++i) S1.emplace(*i);
208 return std::ifstream(filename.c_str()).good();
212 template<
typename A,
typename B>
213 inline std::pair<B,A>
reverse(
const std::pair<A,B>& p)
215 return std::pair<B,A>(p.second, p.first);
bool pareto_le(const std::pair< ElementA, ElementB > &p1, const std::pair< ElementA, ElementB > &p2)
return whether a pair is pareto-smaller than another pair
Definition: utils.hpp:83
void operator^=(boost::unordered_set< T > &S1, const boost::unordered_set< T > &S2)
symmetric set difference for unordered sets
Definition: utils.hpp:198
size_t x
current x coordinate
Definition: utils.hpp:99
bool step_back()
advance backwrd (SW) through the matrix
Definition: utils.hpp:124
bool file_exists(const std::string &filename)
testing whether a file exists by trying to open it
Definition: utils.hpp:206
bool at_end()
check if we're at the end, that is (#columns, #rows)
Definition: utils.hpp:145
const size_t max_y
number of rows in the matrix
Definition: utils.hpp:98
const size_t max_x
number of columns in the matrix
Definition: utils.hpp:97
size_t hash_value(const boost::unordered_set< T > &S)
a hash computation for an unordered set, XORing its members
Definition: utils.hpp:178
bool step_forward()
advance forward (NE) through the matrix
Definition: utils.hpp:107
std::pair< B, A > reverse(const std::pair< A, B > &p)
reverse a pair of things, that is, turn (x,y) into (y,x)
Definition: utils.hpp:213
void operator&=(boost::unordered_set< T > &S1, const boost::unordered_set< T > &S2)
set intersection for unordered sets
Definition: utils.hpp:189
bool at_beginning()
check if we're at the beginning, that is (0,0)
Definition: utils.hpp:141
bool contains(const Set &s, const Element &el)
a more readable containment check
Definition: utils.hpp:171
size_t y
current y coordinate
Definition: utils.hpp:100