3030
3131#pragma once
3232
33- #include " core/templates/hashfuncs.h"
3433#include " core/typedefs.h"
34+
3535template <typename F, typename S>
3636struct Pair {
37- F first;
38- S second;
37+ F first{} ;
38+ S second{} ;
3939
40- Pair () :
41- first (),
42- second () {
43- }
40+ constexpr Pair () = default;
41+ constexpr Pair (const F &p_first, const S &p_second) :
42+ first(p_first), second(p_second) {}
4443
45- Pair (F p_first, const S &p_second) :
46- first (p_first),
47- second (p_second) {
48- }
44+ constexpr bool operator ==(const Pair &p_other) const { return first == p_other.first && second == p_other.second ; }
45+ constexpr bool operator !=(const Pair &p_other) const { return first != p_other.first || second != p_other.second ; }
46+ constexpr bool operator <(const Pair &p_other) const { return first == p_other.first ? (second < p_other.second ) : (first < p_other.first ); }
47+ constexpr bool operator <=(const Pair &p_other) const { return first == p_other.first ? (second <= p_other.second ) : (first < p_other.first ); }
48+ constexpr bool operator >(const Pair &p_other) const { return first == p_other.first ? (second > p_other.second ) : (first > p_other.first ); }
49+ constexpr bool operator >=(const Pair &p_other) const { return first == p_other.first ? (second >= p_other.second ) : (first > p_other.first ); }
4950};
5051
51- template <typename F, typename S>
52- bool operator ==(const Pair<F, S> &pair, const Pair<F, S> &other) {
53- return (pair.first == other.first ) && (pair.second == other.second );
54- }
55-
56- template <typename F, typename S>
57- bool operator !=(const Pair<F, S> &pair, const Pair<F, S> &other) {
58- return (pair.first != other.first ) || (pair.second != other.second );
59- }
60-
6152template <typename F, typename S>
6253struct PairSort {
63- bool operator ()(const Pair<F, S> &A, const Pair<F, S> &B) const {
64- if (A.first != B.first ) {
65- return A.first < B.first ;
66- }
67- return A.second < B.second ;
68- }
69- };
70-
71- template <typename F, typename S>
72- struct PairHash {
73- static uint32_t hash (const Pair<F, S> &P) {
74- uint64_t h1 = HashMapHasherDefault::hash (P.first );
75- uint64_t h2 = HashMapHasherDefault::hash (P.second );
76- return hash_one_uint64 ((h1 << 32 ) | h2);
54+ constexpr bool operator ()(const Pair<F, S> &p_lhs, const Pair<F, S> &p_rhs) const {
55+ return p_lhs < p_rhs;
7756 }
7857};
7958
@@ -83,34 +62,31 @@ struct is_zero_constructible<Pair<F, S>> : std::conjunction<is_zero_constructibl
8362
8463template <typename K, typename V>
8564struct KeyValue {
86- const K key;
87- V value;
65+ const K key{} ;
66+ V value{} ;
8867
89- void operator =(const KeyValue &p_kv) = delete ;
90- _FORCE_INLINE_ KeyValue (const KeyValue &p_kv) :
91- key(p_kv.key),
92- value(p_kv.value) {
93- }
94- _FORCE_INLINE_ KeyValue (const K &p_key, const V &p_value) :
95- key(p_key),
96- value(p_value) {
97- }
98- };
68+ KeyValue &operator =(const KeyValue &p_kv) = delete ;
69+ KeyValue &operator =(KeyValue &&p_kv) = delete ;
9970
100- template <typename K, typename V>
101- bool operator ==(const KeyValue<K, V> &pair, const KeyValue<K, V> &other) {
102- return (pair.key == other.key ) && (pair.value == other.value );
103- }
71+ constexpr KeyValue (const KeyValue &p_kv) = default;
72+ constexpr KeyValue (KeyValue &&p_kv) = default;
73+ constexpr KeyValue (const K &p_key, const V &p_value) :
74+ key(p_key), value(p_value) {}
75+ constexpr KeyValue (const Pair<K, V> &p_pair) :
76+ key(p_pair.first), value(p_pair.second) {}
10477
105- template <typename K, typename V>
106- bool operator !=(const KeyValue<K, V> &pair, const KeyValue<K, V> &other) {
107- return (pair.key != other.key ) || (pair.value != other.value );
108- }
78+ constexpr bool operator ==(const KeyValue &p_other) const { return key == p_other.key && value == p_other.value ; }
79+ constexpr bool operator !=(const KeyValue &p_other) const { return key != p_other.key || value != p_other.value ; }
80+ constexpr bool operator <(const KeyValue &p_other) const { return key == p_other.key ? (value < p_other.value ) : (key < p_other.key ); }
81+ constexpr bool operator <=(const KeyValue &p_other) const { return key == p_other.key ? (value <= p_other.value ) : (key < p_other.key ); }
82+ constexpr bool operator >(const KeyValue &p_other) const { return key == p_other.key ? (value > p_other.value ) : (key > p_other.key ); }
83+ constexpr bool operator >=(const KeyValue &p_other) const { return key == p_other.key ? (value >= p_other.value ) : (key > p_other.key ); }
84+ };
10985
11086template <typename K, typename V>
11187struct KeyValueSort {
112- bool operator ()(const KeyValue<K, V> &A , const KeyValue<K, V> &B ) const {
113- return A .key < B .key ;
88+ constexpr bool operator ()(const KeyValue<K, V> &p_lhs , const KeyValue<K, V> &p_rhs ) const {
89+ return p_lhs .key < p_rhs .key ;
11490 }
11591};
11692
0 commit comments