Vita
locus.h
Go to the documentation of this file.
1
13#if !defined(VITA_LOCUS_H)
14#define VITA_LOCUS_H
15
16#include <iostream>
17#include <limits>
18
19#include "kernel/common.h"
20
21namespace vita
22{
25using index_t = std::size_t;
26
27static_assert(sizeof(index_t) <= sizeof(std::size_t),
28 "index_t size expected to be <= std::size_t");
29static_assert(sizeof(category_t) <= sizeof(std::size_t),
30 "category_t size expected to be <= std::size_t");
31
32struct locus
33{
34 index_t index;
35 category_t category;
36
37 static constexpr locus npos()
38 {
39 return {std::numeric_limits<index_t>::max(),
40 std::numeric_limits<category_t>::max()};
41 }
42};
43
49inline bool operator==(const locus &l1, const locus &l2)
50{
51 return l1.index == l2.index && l1.category == l2.category;
52}
53
59inline bool operator!=(const locus &l1, const locus &l2)
60{
61 return l1.index != l2.index || l1.category != l2.category;
62}
63
72inline bool operator<(const locus &l1, const locus &l2)
73{
74 return l1.index < l2.index ||
75 (l1.index == l2.index && l1.category < l2.category);
76}
77
84inline locus operator+(const locus &l, index_t i)
85{
86 return {l.index + i, l.category};
87}
88
94inline std::ostream &operator<<(std::ostream &s, const locus &l)
95{
96 return s << '[' << l.index << ',' << l.category << ']';
97}
98} // namespace vita
99
100#endif // include guard
The main namespace for the project.
std::size_t index_t
Index in the genome.
Definition: locus.h:25
std::size_t category_t
A category provide operations which supplement or supersede those of the domain but which are restric...
Definition: common.h:44
std::ostream & operator<<(std::ostream &o, hash_t h)
Mainly useful for debugging / testing.
Definition: cache_hash.cc:56