CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
Map.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 {
23 template<typename Key, typename T, typename Compare = std::less<>, typename RawAllocator = DefaultAllocator>
24 using Map = std::map<Key, T, Compare, ScopedAllocatorAdaptor<StdAllocator<Pair<const Key, T>, RawAllocator>>>;
25
27 template<typename Key, typename T, typename Compare = std::less<>> using TemporaryMap = Map<Key, T, Compare, TemporaryAllocator>;
28
32 template<typename Key, typename T, typename Hash = std::hash<Key>, typename KeyEqual = std::equal_to<>, typename RawAllocator = DefaultAllocator>
33 using HashMap = std::unordered_map<Key, T, Hash, KeyEqual, ScopedAllocatorAdaptor<StdAllocator<Pair<const Key, T>, RawAllocator>>>;
34
36 template<typename Key, typename T, typename Hash = std::hash<Key>, typename KeyEqual = std::equal_to<>>
38} // namespace CeresEngine
39
40template<typename Key, typename T, typename Compare, typename RawAllocator> struct std::hash<CeresEngine::Map<Key, T, Compare, RawAllocator>> {
42 inline size_t operator()(const Type& object) const noexcept {
43 size_t seed = 0;
44 for(const auto& value : object) {
45 CeresEngine::combine(seed, value);
46 }
47 return seed;
48 }
49};
50
51template<typename Key, typename T, typename Hash, typename KeyEqual, typename RawAllocator>
52struct std::hash<CeresEngine::HashMap<Key, T, Hash, KeyEqual, RawAllocator>> {
54 inline size_t operator()(const Type& object) const noexcept {
55 size_t seed = 0;
56 for(const auto& value : object) {
57 CeresEngine::combine(seed, value);
58 }
59 return seed;
60 }
61};
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
std::unordered_map< Key, T, Hash, KeyEqual, ScopedAllocatorAdaptor< StdAllocator< Pair< const Key, T >, RawAllocator > > > HashMap
HashMap is an associative container that contains key-value pairs with unique keys.
Definition Map.hpp:33
HashMap< Key, T, Hash, KeyEqual, TemporaryAllocator > TemporaryHashMap
A special HashMap that uses a fast temporary allocator.
Definition Map.hpp:37
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
std::map< Key, T, Compare, ScopedAllocatorAdaptor< StdAllocator< Pair< const Key, T >, RawAllocator > > > Map
Map is a sorted associative container that contains key-value pairs with unique keys.
Definition Map.hpp:24
Map< Key, T, Compare, TemporaryAllocator > TemporaryMap
A special Map that uses a fast temporary allocator.
Definition Map.hpp:27