CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
MultiMap.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "Pair.hpp"
11
14
15#include <map>
16#include <unordered_map>
17
18namespace CeresEngine {
19
20 template<typename Key, typename T, typename Compare = std::less<>, typename RawAllocator = DefaultAllocator>
21 using MultiMap = std::multimap<Key, T, Compare, ScopedAllocatorAdaptor<StdAllocator<Pair<const Key, T>, RawAllocator>>>;
22
24 template<typename Key, typename T, typename Compare = std::less<>> using TemporaryMultiMap = MultiMap<Key, T, Compare, TemporaryAllocator>;
25
26 template<typename Key, typename T, typename Hash = std::hash<Key>, typename KeyEqual = std::equal_to<>, typename RawAllocator = DefaultAllocator>
27 using HashMultiMap = std::unordered_multimap<Key, T, Hash, KeyEqual, ScopedAllocatorAdaptor<StdAllocator<Pair<const Key, T>, RawAllocator>>>;
28
30 template<typename Key, typename T, typename Hash = std::hash<Key>, typename KeyEqual = std::equal_to<>>
32} // namespace CeresEngine
33
34template<typename Key, typename T, typename Compare, typename RawAllocator> struct std::hash<CeresEngine::MultiMap<Key, T, Compare, RawAllocator>> {
36 inline size_t operator()(const Type& object) const noexcept {
37 size_t seed = 0;
38 for(const auto& value : object) {
39 CeresEngine::combine(seed, value);
40 }
41 return seed;
42 }
43};
44
45template<typename Key, typename T, typename Hash, typename KeyEqual, typename RawAllocator>
46struct std::hash<CeresEngine::HashMultiMap<Key, T, Hash, KeyEqual, RawAllocator>> {
48 inline size_t operator()(const Type& object) const noexcept {
49 size_t seed = 0;
50 for(const auto& value : object) {
51 CeresEngine::combine(seed, value);
52 }
53 return seed;
54 }
55};
Definition Application.hpp:19
constexpr void combine(std::size_t &seed, const T &v)
Generates a new hash for the provided type using the default standard hasher and combines it with a p...
Definition Hash.hpp:32
MultiMap< Key, T, Compare, TemporaryAllocator > TemporaryMultiMap
A special MultiMap that uses a fast temporary allocator.
Definition MultiMap.hpp:24
std::unordered_multimap< Key, T, Hash, KeyEqual, ScopedAllocatorAdaptor< StdAllocator< Pair< const Key, T >, RawAllocator > > > HashMultiMap
Definition MultiMap.hpp:27
HashMultiMap< Key, T, Hash, KeyEqual, TemporaryAllocator > TemporaryHashMultiMap
A special HashMultiMap that uses a fast temporary allocator.
Definition MultiMap.hpp:31
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
std::multimap< Key, T, Compare, ScopedAllocatorAdaptor< StdAllocator< Pair< const Key, T >, RawAllocator > > > MultiMap
Definition MultiMap.hpp:21