Optional Two-phase heap tracing
[hiphop-php.git] / hphp / util / hash-map-typedefs.h
blob8e12844fd47db0c6f9c61081214e27e9a9ecfbda
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
16 #ifndef incl_HPHP_HASH_MAP_TYPEDEFS_H_
17 #define incl_HPHP_HASH_MAP_TYPEDEFS_H_
19 #include <unordered_map>
20 #include <unordered_set>
21 #include <functional>
22 #include <string>
24 #include "hphp/util/functional.h"
26 namespace HPHP {
28 //////////////////////////////////////////////////////////////////////
31 * Note: these deliberately change the default-constructor behavior of
32 * unordered_{map,set} to allocate slightly less memory.
34 * Generally be careful about using these hashtables. They're not
35 * cheap, although they may be convenient.
38 #if (defined(__GNUC__) && __GNUC__ >= 5) ||\
39 (defined(__clang) && (__clang_major__ > 3 ||\
40 __clang_major__ == 3 && __clang_minor__ >= 4))
41 // default constructors of unordered containers do not allocate
42 #define GOOD_UNORDERED_CTOR ()
43 #else
44 // minimize allocation when default constructed
45 #define GOOD_UNORDERED_CTOR (0)
46 #endif
48 template <class T, class U,
49 class V = std::hash<T>,
50 class W = std::equal_to<T> >
51 struct hphp_hash_map : std::unordered_map<T,U,V,W> {
52 hphp_hash_map() : std::unordered_map<T,U,V,W> GOOD_UNORDERED_CTOR {}
55 template <class T,
56 class V = std::hash<T>,
57 class W = std::equal_to<T> >
58 struct hphp_hash_set : std::unordered_set<T,V,W> {
59 hphp_hash_set() : std::unordered_set<T,V,W> GOOD_UNORDERED_CTOR {}
62 //////////////////////////////////////////////////////////////////////
64 template<class type, class T> struct hphp_string_hash_map :
65 public hphp_hash_map<std::string,type,string_hash> {
68 template<class T> using hphp_const_char_map =
69 hphp_hash_map<const char*,T,cstr_hash,eqstr>;
71 template<typename T>
72 using hphp_string_map = hphp_hash_map<std::string, T, string_hash>;
74 typedef hphp_hash_set<std::string, string_hash> hphp_string_set;
76 typedef hphp_hash_map<void*, void*, pointer_hash<void> > PointerMap;
77 typedef hphp_hash_map<void*, int, pointer_hash<void> > PointerCounterMap;
78 typedef hphp_hash_set<void*, pointer_hash<void> > PointerSet;
80 template<typename T>
81 using hphp_const_char_imap = hphp_hash_map<const char *, T, hashi, eqstri>;
83 using hphp_const_char_iset = hphp_hash_set<const char *, hashi, eqstri>;
85 template<typename T>
86 using hphp_string_imap =
87 hphp_hash_map<std::string, T, string_hashi, string_eqstri>;
89 using hphp_string_iset =
90 hphp_hash_set<std::string, string_hashi, string_eqstri>;
92 //////////////////////////////////////////////////////////////////////
96 #endif