mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-03-28 06:46:21 +01:00
Backported helper classes to pair.h from Godot4.
This commit is contained in:
parent
37eb131c50
commit
4090cb34d7
50
core/pair.h
50
core/pair.h
@ -30,6 +30,9 @@
|
|||||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
|
|
||||||
|
#include "core/hashfuncs.h"
|
||||||
|
#include "core/typedefs.h"
|
||||||
|
|
||||||
template <class F, class S>
|
template <class F, class S>
|
||||||
struct Pair {
|
struct Pair {
|
||||||
F first;
|
F first;
|
||||||
@ -59,7 +62,52 @@ bool operator!=(const Pair<F, S> &pair, const Pair<F, S> &other) {
|
|||||||
template <class F, class S>
|
template <class F, class S>
|
||||||
struct PairSort {
|
struct PairSort {
|
||||||
bool operator()(const Pair<F, S> &A, const Pair<F, S> &B) const {
|
bool operator()(const Pair<F, S> &A, const Pair<F, S> &B) const {
|
||||||
return A.first < B.first;
|
if (A.first != B.first) {
|
||||||
|
return A.first < B.first;
|
||||||
|
}
|
||||||
|
return A.second < B.second;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class F, class S>
|
||||||
|
struct PairHash {
|
||||||
|
static uint32_t hash(const Pair<F, S> &P) {
|
||||||
|
uint64_t h1 = HashMapHasherDefault::hash(P.first);
|
||||||
|
uint64_t h2 = HashMapHasherDefault::hash(P.second);
|
||||||
|
return hash_one_uint64((h1 << 32) | h2);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class K, class V>
|
||||||
|
struct KeyValue {
|
||||||
|
const K key;
|
||||||
|
V value;
|
||||||
|
|
||||||
|
void operator=(const KeyValue &p_kv) = delete;
|
||||||
|
_FORCE_INLINE_ KeyValue(const KeyValue &p_kv) :
|
||||||
|
key(p_kv.key),
|
||||||
|
value(p_kv.value) {
|
||||||
|
}
|
||||||
|
_FORCE_INLINE_ KeyValue(const K &p_key, const V &p_value) :
|
||||||
|
key(p_key),
|
||||||
|
value(p_value) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class K, class V>
|
||||||
|
bool operator==(const KeyValue<K, V> &pair, const KeyValue<K, V> &other) {
|
||||||
|
return (pair.key == other.key) && (pair.value == other.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class K, class V>
|
||||||
|
bool operator!=(const KeyValue<K, V> &pair, const KeyValue<K, V> &other) {
|
||||||
|
return (pair.key != other.key) || (pair.value != other.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class K, class V>
|
||||||
|
struct KeyValueSort {
|
||||||
|
bool operator()(const KeyValue<K, V> &A, const KeyValue<K, V> &B) const {
|
||||||
|
return A.key < B.key;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user