| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- #ifndef ANKI_UTIL_CONST_CHAR_PTR_HASH_MAP_H
- #define ANKI_UTIL_CONST_CHAR_PTR_HASH_MAP_H
- #include <unordered_map>
- #include <cstring>
- namespace anki {
- /// The hash function
- struct CreateCharPtrHashMapKey
- {
- size_t operator()(const char* str) const
- {
- size_t h = 0;
- for (; *str != '\0'; ++str)
- {
- h += *str;
- }
- return h;
- }
- };
- /// The collision evaluation function
- struct CompareCharPtrHashMapKeys
- {
- bool operator()(const char* a, const char* b) const
- {
- return strcmp(a, b) == 0;
- }
- };
- /// The hash map that has as key an old school C string. When inserting the
- /// char MUST NOT point to a temporary or the evaluation function will fail.
- /// Its template struct because C++ does not offer template typedefs
- template<typename T>
- struct ConstCharPtrHashMap
- {
- typedef std::unordered_map<const char*, T,
- CreateCharPtrHashMapKey, CompareCharPtrHashMapKeys> Type;
- };
- } // end namespace
- #endif
|