CellModules
ordered_pair.hpp
Go to the documentation of this file.
1#ifndef ORDERED_PAIR
2#define ORDERED_PAIR
3#include <cassert>
4#include <unordered_map>
5#include <utility>
6namespace MecaCell {
7template <typename T> struct ordered_pair {
9 bool operator==(const ordered_pair &other) const {
10 return (first->id == other.first->id && second->id == other.second->id);
11 }
12 template <unsigned int i> T &get() { return i == 0 ? first : second; }
13 friend inline std::ostream &operator<<(std::ostream &out, const ordered_pair &v) {
14 out << "{" << v.first << ", " << v.second << "}";
15 return out;
16 }
17};
18template <typename T> inline ordered_pair<T *> make_ordered_cell_pair(T *a, T *b) {
19 if (a->id < b->id) return {a, b};
20 return {b, a};
21}
22template <typename T> inline ordered_pair<T> make_ordered_pair(const T &a, const T &b) {
23 if (a.id < b.id) return {a, b};
24 return {b, a};
25}
26} // namespace MecaCell
27namespace std {
28template <typename T> struct hash<MecaCell::ordered_pair<T>> {
29 size_t operator()(const MecaCell::ordered_pair<T> &x) const {
30 // assert(x.first->id < x.second->id);
31 // return hash<size_t>()(x.first->id) ^ hash<size_t>()(x.second->id);
32 return x.first->id * 10 ^ 9 + x.second->id;
33 }
34};
35} // namespace std
36#endif
this file contains various miscellanious utility functions & helpers *
ordered_pair< T * > make_ordered_cell_pair(T *a, T *b)
ordered_pair< T > make_ordered_pair(const T &a, const T &b)
Provides common mathematical functions and vector operations.
Definition: std.hpp:4
friend std::ostream & operator<<(std::ostream &out, const ordered_pair &v)
bool operator==(const ordered_pair &other) const
Definition: ordered_pair.hpp:9
size_t operator()(const MecaCell::ordered_pair< T > &x) const