Crow  1.1
A C++ microframework for the web
 
Loading...
Searching...
No Matches
ci_map.h
1#pragma once
2
3#include <string_view>
4#include <locale>
5#include <unordered_map>
6
7#include "crow/utility.h"
8
9namespace crow
10{
11 /// Hashing function for ci_map (unordered_multimap).
12 struct ci_hash
13 {
14 size_t operator()(const std::string_view key) const
15 {
16 std::size_t seed = 0;
17 std::locale locale;
18
19 for (auto c : key)
20 hash_combine(seed, std::toupper(c, locale));
21
22 return seed;
23 }
24
25 private:
26 static inline void hash_combine(std::size_t& seed, char v)
27 {
28 std::hash<char> hasher;
29 seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
30 }
31 };
32
33 /// Equals function for ci_map (unordered_multimap).
34 struct ci_key_eq
35 {
36 bool operator()(const std::string_view l, const std::string_view r) const
37 {
38 return utility::string_equals(l, r);
39 }
40 };
41
42 using ci_map = std::unordered_multimap<std::string, std::string, ci_hash, ci_key_eq>;
43} // namespace crow
The main namespace of the library. In this namespace is defined the most important classes and functi...
Hashing function for ci_map (unordered_multimap).
Definition ci_map.h:13
Equals function for ci_map (unordered_multimap).
Definition ci_map.h:35