diff --git a/core/pair.h b/core/pair.h index dad6fdb8a..31a95c2f5 100644 --- a/core/pair.h +++ b/core/pair.h @@ -30,6 +30,9 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ +#include "core/hashfuncs.h" +#include "core/typedefs.h" + template struct Pair { F first; @@ -59,7 +62,52 @@ bool operator!=(const Pair &pair, const Pair &other) { template struct PairSort { bool operator()(const Pair &A, const Pair &B) const { - return A.first < B.first; + if (A.first != B.first) { + return A.first < B.first; + } + return A.second < B.second; + } +}; + +template +struct PairHash { + static uint32_t hash(const Pair &P) { + uint64_t h1 = HashMapHasherDefault::hash(P.first); + uint64_t h2 = HashMapHasherDefault::hash(P.second); + return hash_one_uint64((h1 << 32) | h2); + } +}; + +template +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 +bool operator==(const KeyValue &pair, const KeyValue &other) { + return (pair.key == other.key) && (pair.value == other.value); +} + +template +bool operator!=(const KeyValue &pair, const KeyValue &other) { + return (pair.key != other.key) || (pair.value != other.value); +} + +template +struct KeyValueSort { + bool operator()(const KeyValue &A, const KeyValue &B) const { + return A.key < B.key; } };