Ultra 0.9.4
Loading...
Searching...
No Matches
locus.h
Go to the documentation of this file.
1
12
13#if !defined(ULTRA_LOCUS_H)
14#define ULTRA_LOCUS_H
15
16#include <iostream>
17#include <limits>
18
19namespace ultra
20{
21
25struct locus
26{
28 using index_t = std::size_t;
29
30 locus() = default;
31 constexpr locus(index_t i, size_t c) : index(i), category(c) {}
32
33 // DO NOT CHANGE THE ORDER: the matrix class uses structured binding to
34 // access this struct, associating `index` with `row` and `category` with
35 // `column`.
36 index_t index;
37 std::size_t category;
38
39 [[nodiscard]] static constexpr locus npos()
40 {
41 return {std::numeric_limits<index_t>::max(),
42 std::numeric_limits<std::size_t>::max()};
43 }
44
45 [[nodiscard]] friend bool operator==(const locus &,
46 const locus &) noexcept = default;
47};
48
55[[nodiscard]] inline bool operator<(const locus &l1, const locus &l2) noexcept
56{
57 return l1.index < l2.index ||
58 (l1.index == l2.index && l1.category < l2.category);
59}
60
67[[nodiscard]] inline bool operator>(const locus &l1, const locus &l2) noexcept
68{
69 return l1.index > l2.index ||
70 (l1.index == l2.index && l1.category > l2.category);
71}
72
79[[nodiscard]] inline locus operator+(const locus &l, locus::index_t i) noexcept
80{
81 return {l.index + i, l.category};
82}
83
89inline std::ostream &operator<<(std::ostream &s, const locus &l)
90{
91 return s << '[' << l.index << ',' << l.category << ']';
92}
93
94} // namespace ultra
95
96#endif // include guard
bool operator>(const locus &l1, const locus &l2) noexcept
Definition locus.h:67
bool operator<(const locus &l1, const locus &l2) noexcept
Definition locus.h:55
Definition locus.h:26
std::size_t index_t
Index in the genome.
Definition locus.h:28